1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| function [n]=gaussfftshift()
N=2^10;
dx=40/N
X=N*dx % length of x
x=dx*(0:N-1)-20;
dk=1/X
k=2*pi*dk*(0:N-1)-1/(2*dx);
Ks=N*dk %Ks=1/dx sampling 'frequency'
%x=linspace(-20,20,N);
%p=2*pi./x;
sigma=2;
u=10;
y=1/(sqrt(2*pi*sigma*sigma)).*exp(-(x).^2/(2*sigma*sigma));
n=size(y);
figure(1);plot(x,y);grid;
title('Gaussian center on 0')
z=abs(fftshift(y));
figure(2);
subplot(2,1,1);
plot(x,z);grid;
title('|FFTSHIFT| Gaussian center on 0')
xlabel('x')
subplot(2,1,2);
plot(k,z);grid;
xlabel('k')
z=abs(fft(y));
figure(3);
subplot(2,1,1);
plot(k,fftshift(z));
title('|FFT| then use fftshift in plot Gaussian center on 0')
axis([65 70 0 30])
subplot(2,1,2);
plot(k,z);
title('|FFT| without used fftshift in plot Gaussian center on 0')
z=ifft(z);
figure(4);plot(x,z);grid;
title('ifft of |FFTSHIFT|, Gaussian center on 0')
z=(fft(y));
figure(5);plot(k,fftshift(z));grid;
title('FFT then use fftshift in plot Gaussian center on 0')
axis([65 70 -30 30])
z=(ifft(z));
figure(6);plot(x,z);grid;
title('ifft of FFTSHIFT Gaussian center on 0')
%axis([-1 1 0 40]);
%t=abs(fftshift(y));
%figure(3);plot(k,t);grid;
%title('FFTSHIFT Gaussian center on 0')
%axis([-0.5 0.5 0 0.25]);
y2=1/(sqrt(2*pi*sigma*sigma)).*exp(-((x-u).^2)/(2*sigma*sigma));
figure(7);plot(x,y2);grid;
title('Gaussian center on 10')
z2=abs(fftshift(y2));
figure(8);
subplot(2,1,1);
plot(x,z2);grid;
title('|FFTSHIFT| Gaussian center on 10')
xlabel('x')
subplot(2,1,2);
plot(k,z2);grid;
xlabel('k');
z2=abs(fft(y2));
figure(9); plot(k,fftshift(z2));
title('|FFT| then use fftshift in plot Gaussian center on 10')
axis([65 70 0 30])
z2=ifft(z2);
figure (10); plot(x,z2);grid;
title('ifft of |FFTSHIFT| Gaussian center on 10')
z2=fft(y2);
figure(11);
subplot(2,1,1);
plot(k,fftshift(z2));grid;
title('FFT then use fftshift in plot Gaussian center on 10')
axis([65 70 -30 30])
subplot(2,1,2);
plot(k,z2);grid;
title('FFT with used fftshift in plot Gaussian center on 10')
z2=(ifft(z2));
figure(12);plot(x,z2);grid;
title('ifft of FFTSHIFT Gaussian center on 10')
%axis([-0.4 0.4 0 50]);
%k2=abs(fftshift(y2));
%figure(6);plot(k,k2);grid;
%title('FFTSHIFT Gaussian center on 10')
%axis([-1 0 0 0.25]); |
Partager