Perform FFT from imported excel data. Help please

2 vues (au cours des 30 derniers jours)
Jmv
Jmv le 25 Fév 2020
Commenté : Jmv le 26 Fév 2020
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 commentaires
Walter Roberson
Walter Roberson le 25 Fév 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.
Jmv
Jmv le 26 Fév 2020
Hi Walter. I appreiciate your comment, thanks
yes you are right, the sampling frequency i was meant to use is actally 20KHZ and Ts 0.00005. the times in data files are not correct.
I have now re-uploaded file attached with correct time data.
I am still getting an empty graph. where do you think i am going wrong?
Thanks

Connectez-vous pour commenter.

Réponses (1)

Ridwan Alam
Ridwan Alam le 26 Fév 2020
Modifié(e) : Ridwan Alam le 26 Fév 2020
Signal = D(:,2);
RD = str2double(R) is making a matrix of NaNs. So, you can use D instead of R.
  1 commentaire
Jmv
Jmv le 26 Fév 2020
Thanks very much for the reply.
i can now plot after the changes you suggested.
however to be able determine frequencies at 60 HZ as my fundamental frequency and determine its multiples ( i.e 2x60hz, 3x60hz, ect up to multiple of 50). Could you kindly guide me on how to do that. if you could share a code, i would really apreciate it. Thanks very much

Connectez-vous pour commenter.

Catégories

En savoir plus sur Measurements and Feature Extraction 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!

Translated by