필터 지우기
필터 지우기

Plot the spectrum of a pulse in wavelength

조회 수: 18 (최근 30일)
Ryan muddiman
Ryan muddiman 2021년 7월 9일
편집: Yukthi S 2024년 2월 28일
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