Perform FFT from imported excel data. Help please
    10 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hi, I have the attached  time in first column and current in second column. i am trying to perform FFT and plot  magnitude vs Frequency.  My code is showing an empty plot.
could you please tell me where i am going wrong and kindly provide correction. I will be grateful. Thanks.
Sampling frequency is 20KHZ
[D,S,R] = xlsread('test data.csv');
RD = str2double(R);
Signal = RD(:,2);                                                 % Sampling Interval (milliseconds)
Ts = 0.00005;                                               % Sampling Interval (seconds)
Fs = 1/Ts;                                                  % Sampling Frequency (Hz)
Fn = Fs/2;                                                  % Nyquist Frequency (Hz)
N = length(Signal);
meanSignal = mean(Signal);                                  % ‘Signal’ Mean
FTSignal = fft(Signal-meanSignal)/N;                        % Normalised Fourier Transform Of Baseline-Corrected ‘Signal’
Fv = linspace(0, 1, fix(numel(FTSignal)/2)+1)*Fn;           % Frequency Vector
Iv = 1:numel(Fv);                                           % Index Vector
[pks,locs] = findpeaks(abs(FTSignal(Iv))*2, 'MinPeakHeight',0.044);
figure
plot(Fv, abs(FTSignal(Iv))*2)
grid
xlabel('Frequency (Hz)')
ylabel('Amplitude')
plotIdx = 1:Iv(max(locs));
figure
plot(Fv(plotIdx), abs(FTSignal(Iv(plotIdx)))*2)
hold on
plot(Fv(plotIdx(locs)), pks, '^r', 'MarkerFaceColor','r')
hold off
xlabel('Frequency (Hz)')
ylabel('Amplitude')
text(0.005, 0.08, 'Choose a peak and frequency')
2 comentarios
  Walter Roberson
      
      
 el 25 de Feb. de 2020
				"Sampling frequency is 20KHZ"
No it is not. If you examine the times in the first column, the difference is 0.0005 which is 2kHz. Your Ts is not correct for the data file.
Respuestas (1)
  Ridwan Alam
      
 el 26 de Feb. de 2020
        
      Editada: Ridwan Alam
      
 el 26 de Feb. de 2020
  
      Signal = D(:,2);
RD = str2double(R) is making a matrix of NaNs. So, you can use D instead of R. 
Ver también
Categorías
				Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


