- This topic has 9 replies, 7 voices, and was last updated 7 years, 3 months ago by
Be Asmaa.
-
AuthorPosts
-
-
October 13, 2015 at 4:12 pm #26455
Damian Marek
ParticipantAttached is an m-file that runs a OptiSystem simulation using its own random binary signal and calculates the final BER.
-
October 13, 2015 at 4:16 pm #26458
Damian Marek
ParticipantMatlab code follows:
clear all;
NrOfInt = 255; % Number of integers per frame
M = 8; % Number of bits per symbol
NrFrames = 10; % Number of frames to be transmitted% Generate the matrix with integers to be transmitted
IntSignalin = randi(2^M-1,NrOfInt,NrFrames);% Converte integers to binary numbers
for swint = 1:NrFrames
BinarySig(swint,:) = reshape( dec2bin(IntSignalin(:,swint)) , NrOfInt * M, 1 );
end% Setup bit rate and time window for tranmission of each frame
BitRate = 2.48832e9; % bits/s
NrOfBits = NrOfInt*M + 2;
TimeWindow = NrOfBits / BitRate;% Calculate global parameters of OptiSystem to receive the bit sequence
% from Matlab
GlobalNrOfBits = 1024;
GlobalBitRate = GlobalNrOfBits / TimeWindow;% OptiSystem cosimulation ————————————————-
% create a COM server running OptiSystem
optsys = actxserver(‘optisystem.application’);% Section looks for OptiSystem process and waits for it to start
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Execute the system command
taskToLookFor = ‘OptiSystemx64.exe’;
% Now make up the command line with the proper argument
% that will find only the process we are looking for.
commandLine = sprintf(‘tasklist /FI “IMAGENAME eq %s”‘, taskToLookFor);
% Now execute that command line and accept the result into “result”.
[status, result] = system(commandLine);
% Look for our program’s name in the result variable.
itIsRunning = strfind(lower(result), lower(taskToLookFor));
while isempty(itIsRunning)
% pause(0.1)
[status, result] = system(commandLine);
itIsRunning = strfind(lower(result), lower(taskToLookFor));
end
%%%%%%%%%%%%%%%%%%%%%%%%%% Open the OptiSystem file defined by the path
directory = strcat(pwd,’\OpticalLinkProject.osd’);
optsys.Open(directory);% Specify and define the parameters that will be varied
ParameterName1 = ‘Filename’;
InputSignal = ‘OptiSysSequence.dat’;Document = optsys.GetActiveDocument;
LayoutMngr = Document.GetLayoutMgr;
CurrentLyt = LayoutMngr.GetCurrentLayout;
CurrentSweep = CurrentLyt.GetIteration;
Canvas = CurrentLyt.GetCurrentCanvas;% Set the global parameters correctly
CurrentLyt.SetParameterValue(‘Bit rate’, GlobalBitRate);
CurrentLyt.SetParameterValue(‘Simulation window’, ‘Set time window’);
CurrentLyt.SetParameterValue(‘Time window’, TimeWindow);% Specify the components that will have the parameters updated
Component1 = Canvas.GetComponentByName(‘User Defined Bit Sequence Generator’);
Component1.SetParameterValue( ‘Bit rate’, BitRate/1e9 )Component2 = Canvas.GetComponentByName(‘Low Pass Bessel Filter’);
Component2.SetParameterValue(‘Cutoff frequency’, 0.75 * BitRate/1e9);Component3 = Canvas.GetComponentByName(‘Data Recovery’);
Component3.SetParameterValue(‘Reference bit rate’, BitRate/1e9);Visualizer1 = Canvas.GetComponentByName(‘Binary Sequence Visualizer’);
for swint = 1 : NrFrames
OptiSysSequence(:,1) = str2num(BinarySig(swint,:)’);save OptiSysSequence.dat OptiSysSequence -ascii;
% vary the parameters, run OptiSystem project and get the results
% Set component parameters
Component1.SetParameterValue( ParameterName1, InputSignal );% Calculate
Document.CalculateProject( false , true);% get the bit sequence recovered from OptiSystem
GraphBinary = Visualizer1.GetGraph(‘Amplitude’);
nSize = GraphBinary.GetNrOfPoints;arrSig = GraphBinary.GetYData( CurrentSweep );
SignalOut = cell2mat( arrSig );
BinaryOut(:,swint) = SignalOut(3:2:2*(NrOfBits-1),1);
BinaryIn(:,swint) = OptiSysSequence(:,1);
BinaryMat = reshape(BinaryOut(:,swint), M, NrOfInt )’;
% convertes the binary data to integer
Intmsg = bin2dec(num2str(BinaryMat));
end% Calculates the bit error rate and the number of errors detected
[number,ratio] = symerr(BinaryOut,BinaryIn);disp(‘The BER calculated is:’)
disp(num2str(ratio))
% close OptiSystem
optsys.Quit; -
October 14, 2015 at 12:12 am #26464
Dr. Dhiman Kakati
ParticipantThanks Damian Its really a great step.
Regards
-
October 14, 2015 at 12:35 am #26469
Dhananjay Patel
ParticipantThanks Bryan, i was also in the search of the same.
-
October 14, 2015 at 2:29 am #26476
gaganpreet Kaur
ParticipantThank you so much Damian it is going to be great help. i have been looking for matlab co-simulation for quite some time just because MATLAB simulink gives some flexibility over opti-system though we have optisystem defining new components. i had rather left my design of digital back-propagation via virtual fiber bcoz i was unable to co-simulate matlab simulink and optisystem. but i can resume my work.thanks again.
-
October 14, 2015 at 2:48 am #26479
Alessandro Festa
ParticipantThank you Damian!
-
May 3, 2016 at 6:53 am #38720
Rafik Hisham
ParticipantHey Thanks Alot for this code
I Got This Error i don’t know what’s this :
Error using feval
Server Creation Failed: The requested operation requires elevation.Error in actxserver (line 87)
h=feval([‘COM.’ convertedProgID], ‘server’, machinename, interface);Error in MATLAB_optisystem_cosimulation (line 35)
optsys = actxserver(‘optisystem.application’);-
May 24, 2016 at 9:07 am #39354
Damian Marek
ParticipantDepending on your version of OptiSystem the running process may be named differently. This error is coming from the matlab file trying to find the process named: ‘OptiSystemx64.exe’. Before running this m-file open up OptiSystem and find the name of the process in the task manager and replace the name in the given file above.
Alternatively, you can remove that whole section of code and put a wait statement in (its only purpose is to open OptiSystem and wait for it to be running before starting the next part of the code).
-
-
May 29, 2017 at 11:45 am #43706
Be Asmaa
ParticipantGood afternoon, Thanks you Damian Marek for this code
i am having problem between Optisystem and Matlab.
when i execute a matlabcalloptisystem.m i got this errorNo appropriate method, property, or field GetLayoutMgr for class
Interface.optisystem_application.GetActiveDocument.please help me to solve this issue.
Regards -
May 30, 2017 at 7:00 pm #43765
Be Asmaa
Participanthello everyone,
please i need a help to solve this issus
Regards
-
-
AuthorPosts
- You must be logged in to reply to this topic.