Plot the spectrum of a pulse in wavelength

21 次查看(过去 30 天)
I have a measured pulse in time from a laser and I want plot the wavelength of the signal using an FFT. My measured signal looks like this.
Measured
I would like my FFT spectrum tolook like the below image (left).
Here is what I have tried:
Im = load('Autocorrellation1.mat');
% G is a 1-D time signal
G = wdenoise(sum(Im.Image),2);
G = G-min(G);
G = G/max(G);
% sampling frequency in samples per meter
dx = 1e6;
% Speed of light
c=3e8;
% time interval between samples
dt = 2/(dx*c);
% Length of signal
N = length(G);
% Sample frequency
Fs = 1/dt;
% change in frequency
df = 1/(N*dt);
% time vector
t = 0:dt:(dt*(N-1));
plot(t,G)
axis tight
xlabel('time (s)')
NFFT = 2^nextpow2(N);
bin_vals = [0 : NFFT-1];
N_2 = ceil(NFFT/2);
f = (bin_vals-N_2)*Fs/NFFT;
y = fft(G,NFFT);
wav = c./f;
S =abs(fftshift(y));
plot(f,S)

回答(1 个)

Yukthi S
Yukthi S 2024-2-28
编辑:Yukthi S 2024-2-28
Hi Ryan
It is apparent to me that you were trying to plot the FFT spectrum with wavelength on x-axis and normalized intensity on y-axis.
Your code looks fine to me except for few changes. You need to take care of zero frequency while calculating wavelength and also consider plotting the positive frequencies given that negative frequencies have no physical wavelength counterparts.
You can have a look at the following code snippets to get an idea:
  • Calculate the positive frequency vector.
f = (0:(NFFT-1))*(Fs/NFFT); % Frequency vector
% Only take the positive half of the frequency spectrum
positive_frequencies = f(1:floor(NFFT/2)+1);
positive_y = y(1:floor(NFFT/2)+1);
  • Now that you acquired positive frequencies, calculate the wavelength.
% Convert frequency to wavelength
wav = c ./ positive_frequencies;
  • To get normalized intensity,divide the intensity vector “S” by maximum value of “S”.
% Normalized intensity
S = abs(positive_y).^2;
S = S / max(S);
  • Plot the graph. In addition, due to the inverse proportionality between wavelength and frequency, the 'reverse' setting is applied to the “XDir” property on the axes to arrange the wavelengths in a left to right rising order.
% Plot the wavelength vs normalized intensity
figure;
plot(wav, S);
xlabel('Wavelength');
ylabel('Normalized Intensity');
title('Wavelength vs Normalized Intensity');
axis tight;
set(gca, 'XDir','reverse') % because wavelength decreases as frequency increases
Please refer to the following documentation to have more information on "XDir":

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by