I have an Excel file having sample data and magnitude, I want to convert the time domain to frequency domain using FFT, The file is attached
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an Excel file having sample data and magnitude, I want to convert the time domain to frequency domain using FFT, The file is attached
The code I used is below, but this one is not giving the desire results
#CODE:
clear all
clc
anum1= xlsread('DSO0001.csv','A4:A20483');
anum2=xlsread('DSO0001.csv','C4:C20483');
anum3=smooth(anum2);
subplot(2, 1, 1);
plot(anum1,anum3)
title("Smooth Data")
xft=fft(anum2,1024);
xabs=abs(xft);
subplot(2, 1, 2)
plot(xabs)
title("FFT")
0 commentaires
Réponses (1)
Star Strider
le 20 Mar 2022
It is probably not giving the desired result because the fft is truncated to 1024. Ths signal is much longer than that, and the ‘correct’ length of the fft is 32768, by my calculations
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/934554/DSO0001.CSV','VariableNamingRule','preserve')
L = size(T1,1);
t = T1{:,1};
s = T1{:,[2,3]};
Ts = mean(diff(t));
% Tsd = std(diff(t))
Fs = 1/Ts;
Fn = Fs/2;
figure
yyaxis left
plot(t, s(:,1))
yyaxis right
plot(t, s(:,2))
NFFT = 2^nextpow2(L)
FTs = fft(s,NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
figure
subplot(2,1,1)
plot(Fv, abs(FTs(Iv,1))*2)
grid
xlim([0 0.5])
xlabel('Frequency')
ylabel('Amplitude')
subplot(2,1,2)
plot(Fv, abs(FTs(Iv,2))*2)
grid
xlim([0 0.5])
xlabel('Frequency')
ylabel('Amplitude')
figure
subplot(2,1,1)
plot(Fv, abs(FTs(Iv,1))*2)
grid
xlim([0 0.005])
xlabel('Frequency')
ylabel('Amplitude')
subplot(2,1,2)
plot(Fv, abs(FTs(Iv,2))*2)
grid
xlim([0 0.005])
xlabel('Frequency')
ylabel('Amplitude')
The result appears o be appropriate otherwise, since ‘CH1’ is essentially a square wave, and the fft approximates a sinc function, as expected. The ‘CH2’ signal just appears to be noise.
.
2 commentaires
Star Strider
le 23 Mar 2022
My pleasure!
That line calculates the sampling interval ‘Ts’ of the time vector.
You are apparently reading it into a cell array. My code does not do that (and does not use xlsread), so I cannot reproduce the error. It would be best to use my code as I wrote it to avoid such problems.
One possibility:
t = cell2mat(t);
Ts = mean(diff(t);
.
Voir également
Catégories
En savoir plus sur Time-Frequency Analysis 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!