2 views (last 30 days)
Show older comments
Joe on 6 Jul 2013
Accepted Answer: Matt J
Open in MATLAB Online
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))
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Matt J on 7 Jul 2013
Edited: Matt J on 7 Jul 2013
Open in MATLAB Online
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 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
Joe on 7 Jul 2013
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/81275-how-to-scale-the-plot-of-an-inverse-fast-fourier-transform#comment_158704
Open in MATLAB Online
Yes this seems to work. Just a few things...
Why does it not seem to effect the graphs at all when eta is adjusted?
Also, why in this line
E_w = (1/(sqrt((1/T.^2)+1i*eta)))*exp((-(w).^2)/((2/T.^2)+2*1i*eta));
is there 1i? is that just a mistake or...? and why did -(w-w0).^2 switch to just -(w).^2?
Sorry if it seems I'm badgering you with questions. I appreciate the help a lot.
Matt J on 7 Jul 2013
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/81275-how-to-scale-the-plot-of-an-inverse-fast-fourier-transform#comment_158711
Edited: Matt J on 7 Jul 2013
Open in MATLAB Online
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 on 7 Jul 2013
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/81275-how-to-scale-the-plot-of-an-inverse-fast-fourier-transform#comment_158713
Thanks for your help. Much appreciated.
Sign in to comment.
More Answers (1)
Matt J on 6 Jul 2013
Edited: Matt J on 6 Jul 2013
Open in MATLAB Online
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 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
Joe on 7 Jul 2013
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/81275-how-to-scale-the-plot-of-an-inverse-fast-fourier-transform#comment_158654
Open in MATLAB Online
Ok so I think I have the right sampling interval dt. So I just don't understand how to get my sampling time from the sampling interval that I want to plot against.
Fs = w/(2*pi); % sampling frequency
dt = T/nfft;
t = (0:dt:(dt*length(E_w)));
ifftE_t = ifftshift(ifft(E_w))/dt; % ifft
Matt J on 7 Jul 2013
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/81275-how-to-scale-the-plot-of-an-inverse-fast-fourier-transform#comment_158673
Edited: Matt J on 7 Jul 2013
Open in MATLAB Online
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 on 7 Jul 2013
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/81275-how-to-scale-the-plot-of-an-inverse-fast-fourier-transform#comment_158684
Open in MATLAB Online
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.
Sign in to comment.
Sign in to answer this question.
See Also
Categories
Signal ProcessingSignal Processing ToolboxTransforms, Correlation, and ModelingTransformsHilbert and Walsh-Hadamard Transforms
Find more on Hilbert and Walsh-Hadamard Transforms in Help Center and File Exchange
Tags
- ifft
- scaling
- plotting
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office