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 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Star Strider
2022년 3월 20일
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
Star Strider
2022년 3월 23일
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);
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!