I took this code from the agrawal book: nonlinear fiber optics and I wanted to see the results :(adsbygoogle = window.adsbygoogle || []).push({});

%---specify input parameters

clear all;

distance= input('enter fiber length (in units of L_D)= ');

beta2=input(' dispersion: 1 for normal, -1 for anomalous');

N=input('Nonlinear parameter N=');

mshape=input('m=0 for sech , m>0 for super-Gaussian =');

chirp0=0; % input pulse chirp

%--- set stimulation parameters

nt=1024; Tmax=32; % FFT points and window size

step_num=round(20*distance*N^2); % number of z steps

deltaz=distance/step_num; % 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)];% frequency grid

%--- input field profile

if mshape==0

uu= sech(tau)*exxp(-0.5i*chirp0*tau.^2); %soliton

else %super Gaussian

uu=exp((-0.5*(1+1i*chirp0)*tau.^(2*mshape)));

end

%-- plot input pulse shape and spectrum

temp=fftshift(ifft(uu)).*(nt*dtau)/sqrt(2*pi);%spectrum

figure; subplot(2,1,1);

plot(tau,abs(uu).^2,'--k');hold on;

axis([-5 5 0 inf]);

xlabel('normalized time');

yalebl('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('normalized frequency');

ylabel('spectral power');

%---store dispersive phase shifts to speedup code

dispersion=exp(1i*0.5*beta2*omega.^2 *deltaz);%phase factor

hhz=1i*N^2*deltaz; % nonlinear phase factor

%******[beginning of main loop]****

%scheme:1/2N -> D-> 1/2N; first half step nonlinear

temp=uu.*exp(abs(uu).^2.*hhz/2); %note hhz/2

for n=1:step_num

f_temp=ifft(temp).*dispersion;

u=fft(f_temp);

temp=uu.*exp(abs(uu).^2.*hhz);

end

uu=temp.*exp(-abs(uu).^2.*hhz/2); % 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')

The error was the following:

Error in ==> Untitlednls at 3

distance= input('enter fiber length(in units of L_D)=');

in line 3 i wrote

distance= input('enter fiber length(in units of L_D)=');

Any advice or help please thank you

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab code problem

Loading...

Similar Threads - Matlab code problem | Date |
---|---|

Matlab MATLab: Not enough inputs for nlinfit | Nov 16, 2017 |

Matlab coding problem (Black-Scholes Option Pricing content) | Feb 13, 2011 |

A problem in Matlab ,code doesn't work | Dec 17, 2009 |

Matlab code for transient 2 D thermal problem | Mar 13, 2007 |

**Physics Forums - The Fusion of Science and Community**