i copied it from the book i know the error is in the omega definition(line 12) but i dont know how to solve it please help
Show older comments
clear all;
distance=15;
beta2=1;
N=1;
mshape=input('m=0 for seech, m>0 for super-gaussian= ');
chirp0=0;
nt=1024;tmax=32;
stepnum=round(20*distance*N.^2);
deltaz=distance/stepnum;
dtau=(2*tmax)/nt;
tau=(-nt/2:nt/2-1)*dtau;
omega=(pi/tmax)*(0:nt/2-1) (-nt/2:-1);
if mshape==0
uu=sech(tau).*exp(-0.5i*chirp0*tau.^2);
else
uu=exp(-0.5*(1+1i*chirp0).*tau.^(2*mshape));
end
%%%%%
temp=fftshift(ifft(uu)).*(nt*dtau)/sqrt(2*pi);
figure;
subplot(2,1,1);
plot(tau,abs(uu).^2,'--k');hold on;
axis([-5 5 0 inf]);
xlabel('time');
ylabel('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('frequency');
ylabel('power');
%%%%%
dispersion=exp(0.5*1i*beta2*omega.^2*delta2);
hhz=1i*N^2*deltaz;
%%%%%
temp=uu.*exp(abs(uu).^2.*hhz/2);
for n=1:stepnum
ftemp=ifft(temp).*dispersion;
uu=fft(f_temp);
temp=uu.*exp(abs(uu).^2.*hhz);
end
uu=temp.*exp(-abs(uu).^2.*hhz);
temp=fftshift(ifft(uu)).*(nt*dtau)/sqrt(2*pi);
subplot(2,1,1)
plot(tau,abs(uu).^2,'-k')
subplot(2,1,2)
plot(fftshift(omega)/(2*pi),abs(temp).^2,'-k')
7 Comments
Walter Roberson
on 3 Dec 2013
Which book did you copy it from?
Perhaps you could post an image of the equations ?
abed
on 3 Dec 2013
Walter Roberson
on 3 Dec 2013
This code is from the book? Could you post an image of how the omega line shows up in the code in the book?
abed
on 7 Dec 2013
anu chauhan
on 12 Jun 2016
Edited: Walter Roberson
on 12 Jun 2016
plot((fftshift*omega/(2*pi)),abs(temp).^2,'k');hold on;
i am facing error with this comment in above code can anyone help, its error commenting that vectors must be of same length
Walter Roberson
on 12 Jun 2016
anu chauhan,
You have put at least one |(| in the wrong place. You have somehow made fftshift into a reference to a variable instead of making it a call to the MATLAB fftshift function. Perhaps
plot(fftshift(omega/(2*pi)), abs(temp).^2, 'k')
Afroja Akter
on 12 May 2017
Hi ,
I solve this problem in Matlab, but my problem is when i try to solve in Fortran95. Could anybody help me in fft loop portion solution in fortran.
Thanking Afroja
Answers (1)
Wayne King
on 7 Dec 2013
Edited: Wayne King
on 7 Dec 2013
I'm assuming that you are missing brackets around the vector in omega
distance=15;
beta2 = 1;
delta2=1;
N=1;
mshape=input('m=0 for seech, m>0 for super-gaussian= ');
chirp0=0;
nt=1024;tmax=32;
stepnum=round(20*distance*N.^2);
deltaz=distance/stepnum;
dtau=(2*tmax)/nt;
tau=(-nt/2:nt/2-1)*dtau;
omega=(pi/tmax)*[(0:nt/2-1) (-nt/2:-1)];
if mshape==0
uu=sech(tau).*exp(-0.5i*chirp0*tau.^2);
else
uu=exp(-0.5*(1+1i*chirp0).*tau.^(2*mshape));
end
%%%%%
temp=fftshift(ifft(uu)).*(nt*dtau)/sqrt(2*pi);
figure;
subplot(2,1,1);
plot(tau,abs(uu).^2,'--k');hold on;
axis([-5 5 0 inf]);
xlabel('time');
ylabel('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('frequency');
ylabel('power');
%%%%%
dispersion=exp(0.5*1i*beta2*omega.^2*delta2);
hhz=1i*N^2*deltaz;
%%%%%
temp=uu.*exp(abs(uu).^2.*hhz/2);
for n=1:stepnum
ftemp=ifft(temp).*dispersion;
uu=fft(ftemp);
temp=uu.*exp(abs(uu).^2.*hhz);
end
uu=temp.*exp(-abs(uu).^2.*hhz);
temp=fftshift(ifft(uu)).*(nt*dtau)/sqrt(2*pi);
subplot(2,1,1)
plot(tau,abs(uu).^2,'-k')
subplot(2,1,2)
plot(fftshift(omega)/(2*pi),abs(temp).^2,'-k')
However there are other problems, nowhere do you define/compute what delta2 is. I have just set it equal to 1, but I have no idea, you'll have to figure that part out.
Also, there is mistake where f_temp is confused with ftemp.
Categories
Find more on Accelerators & Beams in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!