Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How do I convert the x-axis of an FFT from frequency to wavelength?

Asked by Joe

Joe (view profile)

on 28 Jun 2013
% speed of light m/s
c = 299792458;
% pulse duration (T=tau)
FWHM = 30e-15; 
T = FWHM/(2*(sqrt(log(2)))); 
% central wavelngth and central angular frequency
lambda0 = 800e-9;
w0 = (2*pi*c)/lambda0;
% chirp
eta = 2;
% time interval
t = -55e-15:.1e-15:55e-15; 
% spectral phase
phi_t = 0; 
% length of FFT # of sampling points
nfft = 200; 
% This is an evenly spaced frequency vector
f = [0:nfft - 1]/nfft; 
% wavelength interval and angular frequency conversion
lambda = (740e-9:20e-9:860e-9);
w = (2.*pi.*c)./lambda;
% electric field
E_t = exp((-t.^2/(2*T.^2)) + (-i*w0*t-(1/2)*i*eta*t.^2)); %*phi_t)); 
% Take fft, padding with zeros so that length(E_w) is equal to nfft 
E_w = abs(fftshift(fft(E_t,nfft))); 
I_w = ((abs(E_w)).^2); 
I_lambda = I_w.'*((2.*pi.*c)./lambda); (This is where I'm trying to convert to wavelength)
% Plot 
subplot(2, 1, 1);
plot(t, real(E_t));
title('Gaussian Pulse Signal'); 
xlabel('time (s)'); 
ylabel('E_t'); 
subplot(2, 1, 2);
plot(lambda, E_w);  
xlabel('\lambda'); 
ylabel('E_\omega'); 

0 Comments

Joe

Joe (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Wayne King

Wayne King (view profile)

on 29 Jun 2013
Edited by Wayne King

Wayne King (view profile)

on 29 Jun 2013
Accepted answer

This runs perfectly for me:

    c = 299792458;
  % pulse duration (T=tau)
  FWHM = 30e-15; 
  T = FWHM/(2*(sqrt(log(2)))); 
  % central wavelngth and central angular frequency
  lambda0 = 800e-9;
  w0 = (2*pi*c)/lambda0;
  % chirp
  eta = 2;
  % time interval
  t = -55e-15:.1e-15:55e-15; 
  % spectral phase
  phi_t = 0; 
  % wavelength interval and angular frequency conversion
  lambda = (740e-9:20e-9:860e-9);
  w = (2.*pi.*c)./lambda;
  % electric field
  E_t = exp((-t.^2/(2*T.^2)) + (i*w0*t-(1/2)*i*eta*t.^2)); %*phi_t)); 
   Edft = fftshift(fft(E_t));
   dt = t(2)-t(1);
   Fs = 1/dt;
   df = Fs/length(E_t);
   freq = -Fs/2+df:df:Fs/2;
   lambda = c./freq;
   plot(lambda,abs(Edft).^2);
   set(gca,'xlim',[0 10e-7])

And it shows the correct wavelength.

1 Comment

Joe

Joe (view profile)

on 29 Jun 2013

Awesome Thanks! Now I just got to get the y-axis right... haha.

Wayne King

Wayne King (view profile)

Answer by Wayne King

Wayne King (view profile)

on 28 Jun 2013
Edited by Wayne King

Wayne King (view profile)

on 29 Jun 2013
 E_t = exp((-t.^2/(2*T.^2)) + (i*w0*t-(1/2)*i*eta*t.^2)); 
 Edft = fftshift(fft(E_t));
 dt = t(2)-t(1);
 Fs = 1/dt;
 df = Fs/length(E_t);
 freq = -Fs/2+df:df:Fs/2;
 lambda = c./freq;
 plot(lambda,abs(Edft).^2);

Now the wavelength you expect is

c/(w0/(2*pi))

so zoom in on that

set(gca,'xlim',[0 10e-7])

You see the peak at 8x10^{-7} as you expect

3 Comments

Joe

Joe (view profile)

on 29 Jun 2013

What is "df" that you have for the "freq"?

Wayne King

Wayne King (view profile)

on 29 Jun 2013

That is the frequency separation between the DFT bins. Sorry I forgot that line of code:

    df = 1/(dt*length(E_t));

or equivalently

    df = Fs/length(E_t);

I've added it above.

Joe

Joe (view profile)

on 5 Jul 2013

Just to clarify... What is t(2) and t(1)? I know that dt is the time separation, but I'm not sure why you used t(2) and t(1). Also, is there another way of getting dt?

Wayne King

Wayne King (view profile)

Contact us