1
votes

When the FFT is performed on a function of time u in Matlab, a complex spectrum uf is returned. To plot the spectral amplitude abs(uf) against its frequency content, a frequency grid can be made to accommodate uf. I can associate a wavelength grid with the frequency grid, and plot uf against that also. The spacing between each element in the frequency array is constant, but since wavelength ~ 1/frequency, the spacing between each point in the wavelength array varies over the array index. I am curious if there is a way to take the FFT of a function of time to yield a spectrum in wavelength that has constant spacing. Here is my code in Matlab:

clc;
close all;
clear all;

lam = 800e-9; % Wavelength (m)
c = 3e8; % Light speed (m/s)

nt = 8192; % Temporal grid resolution
T = 400*1e-15; % Temporal grid size (s)
dt = T/nt; % Temporal pixel spacing

df = 1/(nt*dt); % Frequency pixel spacing
ff = [(0:nt/2-1) (-nt/2:-1)]*df; % Frequency grid 
ff = fftshift(ff); 

wav = c./ff; % Wavelength array (spacing is not constant between each element)

for k = 1:nt
    tt(k) = (-nt/2+k-1)*dt; % Time array
    u(k) = cos(2*pi*c/lam*tt(k)); % Function of time
end

%Now I can take FFT:

uf = fftshift(fft(u)); % The spectrum of my function. The FFT has yielded a spectrum associated with a frequency array of linearly spaced elements (ff).

Both plots of spectral amplitude vs. wavelength and vs. frequency yield good results.

figure(1)
plot(ff,abs(uf)) 
title('Spectral amplitude vs frequency')
xlabel('Frequency (Hz)')
ylabel('Spectral amplitude')

figure(2)
plot(wav,abs(uf))
title('Spectral amplitude vs wavelength')
xlabel('Wavelength (m)')
ylabel('Spectral amplitude');

enter image description here

But my wavelength array does not have constant spacing:

figure(3)
plot(ff)
title('Frequency array')
ylabel('Frequency (Hz)')
xlabel('Index')

figure(4)
plot(wav)
xlim([(nt/2 +1) (nt/2 + 100)])
title('Wavelength array')
ylabel('Wavelength (m)')
xlabel('Index')

enter image description here

1
can you more concisely state your problem?anon01
Why do you need a constant spacing for your wavelength intervals? An FFT is always calculated at fixed frequency intervals, which results in non constant wavelength intervals (wav = c./ff). You can interpolate if needed.m7913d
I need a constant wavelength spacing because my generated spectral amplitude will serve as an input to another program which demands constant wavelength spacing.Ross G

1 Answers

2
votes

You should make a linearly spaced wavelength array and interpolate your data to find the linearly spaced y values.