How to use fft to analyse the refelction specturm?

68 次查看(过去 30 天)
I wanna get spatial frequency from FFT, just like the picture. I have already got the reflection spectrum.The wavelength and corresponding intensity are saved in Excel.
aa = xlsread('C:\Users\jc\Desktop\6.27\xx.xlsx');
x = linspace(1510,1590,16001);%wavelength
y = aa(1:16001,2); %intensity
wavelength = x*1e-9;%nm
wavenumber = 1./wavelength;
wavenumberfit = linspace(wavenumber(1),wavenumber(16001),16001);

采纳的回答

Star Strider
Star Strider 2024-7-3,14:41
编辑:Star Strider 2024-7-3,14:42
It would help to have xx.xlsx, however lacking it, I will synthesize something like it —
Fs = 0.1;
L = 1000;
t = linspace(0, Fs*L, Fs*L+1).'/Fs;
signal = sum(sin(2*pi*t*[0.125 0.215]/10).*[600 470],2);
figure
plot(t, signal)
xlabel('Wavelength (nm)')
ylabel('Optical Power (dB)')
[FTs1,Fv] = FFT1(signal,t);
figure
plot(Fv, abs(FTs1)*2)
xlabel('Spatial Frequency (#/nm)')
ylabel('FFT Magnitude (a.u.)')
function [FTs1,Fv] = FFT1(s,t)
t = t(:);
L = numel(t);
if size(s,2) == L
s = s.';
end
Fs = 1/mean(diff(t));
Fn = Fs/2;
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)) .* hann(L).*ones(1,size(s,2)), NFFT)/sum(hann(L));
Fv = Fs*(0:(NFFT/2))/NFFT;
% Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
FTs1 = FTs(Iv,:);
end
My simulation is not exact, however it is close enough to demonstrate the approach. I wrote the ‘FFT1’ function for my own use, so that I wouldn’t have to type out that code whenever I wanted to calculate the FFT of a signal.
.
  6 个评论
Chueng
Chueng 2024-7-4,13:52
Thank you very much for your reply. The reason of the irregular wavelength was because its value was extracting from the device. Therefore, the linspace function can be used to obtain the wavelength, I’ll try this to verify.
Star Strider
Star Strider 2024-7-4,14:34
My pleasure!
Non-uniform sampling times (or wavelength values) are a simple fact-of-life in many applications. The problem is that the irregular sampling intervals make the signals unsuitable for any sort of signal processing (the only exceptin being the nufft function). I definitely recommend using the resample function instead of linspace (that likely will not provide the actual wavelengths corresponding to the recorded intensity values) or interp1 (that will only interpolate to the new wavelength values without correcting for spurious signals). The reason is that while resample interpolates to the ‘corrected’ wavelength values, it also uses an anti-aliasing filter to prevent spurious signals from appearing in the resampled signal. I recommend using my code (or some version of it) in your analysis for that reason.
If my Answer helped you solve your problem, please Accept it!
My apologies for the delay in responding. Windows 11 crashed again and I had to restart this computer.
.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by