distance = input('Enter fiber length in L_D '); beta2 = input('dispersion: 1 for normal, -1 for anomalous '); N = input('Nonlinear parameter N = '); % Soliton order mshape = input('m = 0 for sech, m > 0 for super-Gaussian '); chirp0 = 0; % set simulation parameters nt = 1024; Tmax = 32; % FFT points and window size step_num = round(20 * distance * N^2); % No. of z steps deltaz = distance/step_num; % step size in z dtau = (2*Tmax) / nt; % step size in tau %% tau and omega arrays tau = (-nt/2 : nt/2-1) * dtau; % temporal grid omega = (pi/Tmax) * [(0:nt/2-1) (-nt/2:-1)]; % freq grid if mshape == 0 uu = sech(tau) .* exp(-0.5j * chirp0 * tau.^2); else uu = exp(-0.5 * (1 + 1j * chirp0) .* tau.^(2 * mshape)); end %% plot input pulse shape and spectrum temp = fftshift(ifft(uu)) .* (nt * dtau) / sqrt(2 * pi); % spectrum figure(1); clf; subplot(2,1,1); plot(tau, abs(uu).^2, '--k'); hold on; axis([-5 5 0 inf]); xlabel('Normalized Time'); ylabel('Normalized Power'); title('Input and Output pulse shape and spectrum'); subplot(2, 1, 2); plot(fftshift(omega)/(2*pi), abs(temp) .^ 2, '--k'); hold on; axis([-.5 .5 0 inf]); xlabel('Normaized freq'); ylabel('spectral power'); %% store dispersive phase shifts to speed up code dispersion = exp(0.5j * beta2 * omega.^2 * deltaz); % [hase factor hhz = 1j * N^2 * deltaz; %% begin main loop %% N/2 -> D -> N/2 first half step nonlinear temp = uu .* exp(abs(uu) .^ 2 .* hhz / 2); for n = 1 : step_num f_temp = ifft(temp) .* dispersion; uu = fft(f_temp); temp = uu .* exp(abs(uu) .^ 2 .* hhz); end uu = temp .* exp(-abs(uu) .^ 2 .* hhz); % final field temp = fftshift(ifft(uu)) .* (nt*dtau) / sqrt(2 * pi); % final spectrum %% end of main loop %% plot output pulse shape and spectrum subplot(2,1,1); plot(tau, abs(uu).^2, '-k'); subplot(2,1,2); plot(fftshift(omega) / (2*pi), abs(temp).^2, '-k');