Home Forums EXCHANGE Call OptiSystem BER Calculation

Viewing 8 reply threads
  • Author
    Posts
    • #26455
      Damian Marek
      Participant

      Attached is an m-file that runs a OptiSystem simulation using its own random binary signal and calculates the final BER.

    • #26458
      Damian Marek
      Participant

      Matlab 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;

    • #26464
      Dr. Dhiman Kakati
      Participant

      Thanks Damian Its really a great step.

      Regards

    • #26469
      Dhananjay Patel
      Participant

      Thanks Bryan, i was also in the search of the same.

    • #26476
      gaganpreet Kaur
      Participant

      Thank 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.

    • #26479
      Alessandro Festa
      Participant

      Thank you Damian!

    • #38720
      Rafik Hisham
      Participant

      Hey 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’);

      • #39354
        Damian Marek
        Participant

        Depending 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).

    • #43706
      Be Asmaa
      Participant

      Good 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 error

      No appropriate method, property, or field GetLayoutMgr for class
      Interface.optisystem_application.GetActiveDocument.

      please help me to solve this issue.
      Regards

    • #43765
      Be Asmaa
      Participant

      hello everyone,

      please i need a help to solve this issus

      Regards

Viewing 8 reply threads
  • You must be logged in to reply to this topic.