Home Forums FIBER Integrating MATLAB with OptiSystem

  • This topic is empty.
Viewing 0 reply threads
  • Author
    Posts
    • #88671
      soso
      Participant

      I have a MATLAB component it does not accept the input electrical signal from OptiSystem
      function process_signal(InputPort1, InputPort2, InputPort3, InputPort4, OutputPort1, OutputPort2, OutputPort3, OutputPort4)
      % Input Signals
      X_I = InputPort1.data;
      X_Q = InputPort2.data;
      Y_I = InputPort3.data;
      Y_Q = InputPort4.data;

      % Ensure all inputs have the same length
      N = length(X_I);
      pi2 = pi^2;

      % FFT Conversion
      X_I_FFT = fftshift(fft(X_I));
      X_Q_FFT = fftshift(fft(X_Q));
      Y_I_FFT = fftshift(fft(Y_I));
      Y_Q_FFT = fftshift(fft(Y_Q));

      % Nonlinear Contributions Initialization
      NL_X_I_FFT = zeros(1, N);
      NL_X_Q_FFT = zeros(1, N);
      NL_Y_I_FFT = zeros(1, N);
      NL_Y_Q_FFT = zeros(1, N);

      % SPM and XPM Contributions
      SPM_X_I_FFT = zeros(1, N); XPM_X_I_FFT = zeros(1, N);
      SPM_X_Q_FFT = zeros(1, N); XPM_X_Q_FFT = zeros(1, N);
      SPM_Y_I_FFT = zeros(1, N); XPM_Y_I_FFT = zeros(1, N);
      SPM_Y_Q_FFT = zeros(1, N); XPM_Y_Q_FFT = zeros(1, N);

      % Nonlinear Equalization
      for omega1_idx = 1:N
      for omega2_idx = 1:N
      omega3_idx = mod(omega1_idx – omega2_idx + N, N) + 1;

      % SPM and XPM for X_I
      SPM_X_I_FFT(omega1_idx) = SPM_X_I_FFT(omega1_idx) + …
      X_I_FFT(omega1_idx) .* conj(X_I_FFT(omega3_idx));
      XPM_X_I_FFT(omega1_idx) = XPM_X_I_FFT(omega1_idx) + …
      conj(Y_Q_FFT(omega2_idx)) .* Y_Q_FFT(omega3_idx);

      % Repeat for X_Q
      SPM_X_Q_FFT(omega1_idx) = SPM_X_Q_FFT(omega1_idx) + …
      X_Q_FFT(omega1_idx) .* conj(X_Q_FFT(omega3_idx));
      XPM_X_Q_FFT(omega1_idx) = XPM_X_Q_FFT(omega1_idx) + …
      conj(Y_I_FFT(omega2_idx)) .* Y_I_FFT(omega3_idx);

      % Repeat for Y_I
      SPM_Y_I_FFT(omega1_idx) = SPM_Y_I_FFT(omega1_idx) + …
      Y_I_FFT(omega1_idx) .* conj(Y_I_FFT(omega3_idx));
      XPM_Y_I_FFT(omega1_idx) = XPM_Y_I_FFT(omega1_idx) + …
      conj(X_Q_FFT(omega2_idx)) .* X_Q_FFT(omega3_idx);

      % Repeat for Y_Q
      SPM_Y_Q_FFT(omega1_idx) = SPM_Y_Q_FFT(omega1_idx) + …
      Y_Q_FFT(omega1_idx) .* conj(Y_Q_FFT(omega3_idx));
      XPM_Y_Q_FFT(omega1_idx) = XPM_Y_Q_FFT(omega1_idx) + …
      conj(X_I_FFT(omega2_idx)) .* X_I_FFT(omega3_idx);
      end
      end

      % Total Nonlinear Contribution
      NL_X_I_FFT = (SPM_X_I_FFT + XPM_X_I_FFT) ./ (4 * pi2);
      NL_X_Q_FFT = (SPM_X_Q_FFT + XPM_X_Q_FFT) ./ (4 * pi2);
      NL_Y_I_FFT = (SPM_Y_I_FFT + XPM_Y_I_FFT) ./ (4 * pi2);
      NL_Y_Q_FFT = (SPM_Y_Q_FFT + XPM_Y_Q_FFT) ./ (4 * pi2);

      % Equalization
      K1 = 1; % Equalization coefficient placeholder

      % Equalize Each Signal
      OUT_X_I_FFT = K1 .* X_I_FFT .* NL_X_I_FFT;
      OUT_X_Q_FFT = K1 .* X_Q_FFT .* NL_X_Q_FFT;
      OUT_Y_I_FFT = K1 .* Y_I_FFT .* NL_Y_I_FFT;
      OUT_Y_Q_FFT = K1 .* Y_Q_FFT .* NL_Y_Q_FFT;

      % Back to Time Domain
      OUT_X_I = real(ifft(ifftshift(OUT_X_I_FFT)));
      OUT_X_Q = real(ifft(ifftshift(OUT_X_Q_FFT)));
      OUT_Y_I = real(ifft(ifftshift(OUT_Y_I_FFT)));
      OUT_Y_Q = real(ifft(ifftshift(OUT_Y_Q_FFT)));

      % Output Signals
      OutputPort1.data = OUT_X_I; % Equalized X Polarization (I)
      OutputPort2.data = OUT_X_Q; % Equalized X Polarization (Q)
      OutputPort3.data = OUT_Y_I; % Equalized Y Polarization (I)
      OutputPort4.data = OUT_Y_Q; % Equalized Y Polarization (Q)
      End

      • This topic was modified 2 weeks, 3 days ago by Ahmad Atieh.
Viewing 0 reply threads
  • You must be logged in to reply to this topic.