%Simulace sireni impulsu optickym vlaknem
close all; clear all; clc;
i=sqrt(-1);c=3e8;       %konstanty
%vstupni parametry--------------------------------------------------------
P0=0.001;       %vstupni spickovy vykon gauss pulsu, W
alfadB=0;       %utlum vlakna, dB/km
D=17;           %disperze, ps/nm*km
lambda=1550;    %vlnova delka, nm
n2=3.2e-16;     %nelinearni koef indexu lomu vlakna, cm^2/W
Aef=50;         %efektivni plocha jadra vlakna, um^2
z=50;           %delka vlakna, km
dz=0.25;        %element vzdalenosti v rozmezi 0.1 - 1 km
T0=50;          %sirka pulsu v ps, kde A=A0*1/e
C=0;            %koef rozmitaneho gauss pulsu
m=1;            %rad gauss pulsu
N=1024;         %pocet bodu casoveho vektoru
okno=400;       %sirka casoveho okna, ps
%-------------------------------------------------------------------------
beta2=-D*1e-24*((lambda)^2)/(2*pi*c);%disperzni koef 2.r, s^2/m
gamma=(2*pi*n2*1e17)/(lambda*Aef);   %nelinearni koef vlakna, 1/W*m
T0=(T0/2)*1e-12;
h=z/dz;                                             %pocet kroku vypoctu
dz=dz*1000;                                         %km -> m
alfa=(2*alfadB/4.343)/1000;                         %utlum vlakna 1/m
t=-(okno/2)*1e-12:(okno*1e-12)/(N-1):(okno/2)*1e-12;%casovy vektor
dt=(okno*1e-12)/(N-1);                              %casovy element
A=sqrt(P0)*exp(-(1+i*C)*(t/T0).^(2*m));             %gauss puls
figure(1);
plot(t*1e12,abs(A)/sqrt(P0),'b');
xlabel('time [ps]');
ylabel('normalized power');
grid on;hold on;
l=length(A);
dw=2*pi*1/(dt*l);
w=(-1*l/2:1:l/2-1)*dw;
w=fftshift(w);
spA=fft(A);
for k=1:h,
    spA=spA.*exp(-(alfa/2)*(dz/2)+i*w.^2*(beta2/2)*(dz/2));
    A=ifft(spA);
    A=A.*exp(i*gamma*(abs(A)).^2*dz);
    spA=fft(A);
    spA=spA.*exp(-(alfa/2)*(dz/2)+i*w.^2*(beta2/2)*(dz/2));
end;
A=ifft(spA);
plot(t*1e12,abs(A)/sqrt(P0),'r');
legend('input','output');
