How to use fft to analyse the refelction specturm?
    4 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
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);

0 commentaires
Réponse acceptée
  Star Strider
      
      
 le 3 Juil 2024
        
      Modifié(e) : Star Strider
      
      
 le 3 Juil 2024
  
      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 commentaires
  Star Strider
      
      
 le 4 Juil 2024
				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.  
.
Plus de réponses (0)
Voir également
Catégories
				En savoir plus sur Multirate Signal Processing dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!







