Borrar filtros
Borrar filtros

How to scale the plot of an Inverse Fast Fourier Transform?

1 visualización (últimos 30 días)
Hi, I'm not sure how to get my scaling right in my ifft from frequency to time when I plot it. I've tried below, but I know something is off from the graph. Thanks.
% Constants
c = 299792458; % speed of light in a vacuum
FWHM = 30e-15; % pulse duration
T = FWHM/(2*(sqrt(log(2)))); % (T=tau)
lambda0 = 800e-9; % central wavelength
w0 = (2*pi*c)/lambda0; % central angular frequency
eta = 0; % chirp (2nd derivitive of phase)
% electric field and intensity in wavelength domain
nfft = 2^12;
lambda = (740e-9:((120e-9)/(nfft-1)):860e-9);
w = (2.*pi.*c)./lambda;
E_w = (1/(sqrt((1/T.^2)+i*eta)))*exp((-(w-w0).^2)/((2/T.^2)+2*i*eta));
I_lambda= (abs(E_w)).^2;
% IFFT
Fs = w/(2*pi); % sampling frequency
df = Fs/nfft;
dw = 2*pi*df;
dt = 1./Fs; % increments of time
T1 = (nfft*dt);
t = (-T1/2+dt:dt:T1/2);
ifftE_t = ifft(E_w); % ifft
% PLOT
subplot(2, 1, 1);
plot(w, I_lambda);
title('Gaussian Pulse Signal');
xlabel('Wavelength');
ylabel('I_\lambda');
subplot(2, 1, 2)
plot(t, abs(ifftE_t))

Respuesta aceptada

Matt J
Matt J el 7 de Jul. de 2013
Editada: Matt J el 7 de Jul. de 2013
The following modification seems to work for me. I get Gaussian-looking pulses in both the time and frequency domain, exactly as expected for eta=0.
% Constants
c = 299792458; % speed of light in a vacuum
FWHM = 30e-15; % pulse duration
T = FWHM/(2*(sqrt(log(2)))); % (T=tau)
lambda0 = 800e-9; % central wavelength
w0 = (2*pi*c)/lambda0; % central angular frequency
eta = 0; % chirp (2nd derivitive of phase)
% electric field and intensity in wavelength domain
f0=w0/(2*pi);
L=(1/FWHM); %order of magnitude of pulse duration in frequency space
df=L/10000;
Df=5*L; %frequency duration
N=ceil(Df/df);
dt=1/N/df;
NormalizedAxis= (0:N-1) -ceil((N-1)/2);
t=dt*NormalizedAxis;
f=df*NormalizedAxis;
w=2*pi*f;
dw=2*pi*df;
% Spectra
E_w = (1/(sqrt((1/T.^2)+1i*eta)))*exp((-(w).^2)/((2/T.^2)+2*1i*eta));
I_lambda= (abs(E_w)).^2;
% IFFT
ifftE_t = fftshift(ifft(E_w))/dt; % ifft
% PLOT
subplot(2, 1, 1);
plot(w+w0, I_lambda);
title('Gaussian Pulse Signal');
xlabel('Wavelength');
ylabel('I_\lambda');
subplot(2, 1, 2)
plot(t, abs(ifftE_t)); xlim(FWHM*[-5,5])
  3 comentarios
Matt J
Matt J el 7 de Jul. de 2013
Editada: Matt J el 7 de Jul. de 2013
Why does it not seem to effect the graphs at all when eta is adjusted?
I definitely see a change in I_lambda as eta is varied over 0, 1/T^2, 5/T^2.
abs(ifftE_t) seems to be invariant to eta for some reason, but real(ifftE_t) is not.
is there 1i? is that just a mistake or...?
It's the recommended way to express sqrt(-1). Supposedly, MATLAB processes it faster. It also allows you to use i as a variable without creating conflict, e.g.,
>> i=3; c=i+2i
c =
3.0000 + 2.0000i
why did -(w-w0).^2 switch to just -(w).^2?
Personal preference. A shift in frequency doesn't affect abs(ifftE_t), so it didn't matter.
Joe
Joe el 7 de Jul. de 2013
Thanks for your help. Much appreciated.

Iniciar sesión para comentar.

Más respuestas (1)

Matt J
Matt J el 6 de Jul. de 2013
Editada: Matt J el 6 de Jul. de 2013
There is no standardized way of scaling Fourier transforms. Different professions scale it differently. If you are using the engineering profession's definition of the continuous inverse Fourier transform, you can approximate it as
ifft(X)/dt
where dt is the sampling interval in the time domain.
However, you have bigger problems in your code. Your sampling interval, dt, is a vector for some reason, instead of a scalar
>> size(dt)
ans =
1 4096
which among other things means that the following line doesn't make sense
t = (-T1/2+dt:dt:T1/2);
Colon operations a:b:c are meant to be done with scalar a,b,c.
  3 comentarios
Matt J
Matt J el 7 de Jul. de 2013
Editada: Matt J el 7 de Jul. de 2013
You should probably also be doing the ifft as follows
ifftE_t = fftshift(ifft(ifftshift(E_w))/dt);
I still don't know why you have
Fs = w/(2*pi); % sampling frequency
Since w is a vector, your sampling frequency Fs will be a vector as well, which wouldn't make sense. I still also don't understand how you can generate w according to
w = (2.*pi.*c)./lambda;
since this will give you non-equispaced samples in w. You need to decide on a scalar dw first and then generate equi-spaced w, something like
N=nfft;
dw=mean(diff(2*pi*c./lambda)); %just an example dw
w=dw*(0:N-1) -ceil((N-1)/2);
Then for the time axis. you would do
dt=1/N/dw;
timeAxis=dt*( (0:N-1) -ceil((N-1)/2) );
Joe
Joe el 7 de Jul. de 2013
That didn't really give me what I wanted I wanted a graph more like this:
df = w(1)/(2*pi) - w(2)/(2*pi);
ifftE_t = ifftshift(ifft(E_w))*df; % ifft
Ts = 1/df;
dt = Ts/length(E_w);
time = -Ts/2:dt:Ts/2-dt;
Except I'm not getting enough oscillations. That w that you had made my first graph a straight line
w=dw*(0:N-1) -ceil((N-1)/2);
Although you are right that my w that gives me non-equispaced samples so I'm not really sure how to fix that because when I adjust my w it doesn't give me the right graph.
I'm comparing this ifft to an equation I got when I did the math analytically here.
% (test to see if inverse fourier matches)
Pt = -100e-15:1e-15:100e-15;
PE_t =exp((-Pt.^2/(2*T.^2)) + (i*w0*Pt-(1/2)*i*eta*Pt.^2)); %*phi_t));
plot(Pt, PE_t);
Sorry if I don't make to much sense, this is my first time using MATLAB and working with Fourier Transformations.

Iniciar sesión para comentar.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by