필터 지우기
필터 지우기

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")

답변 (1개)

Star Strider
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')
T1 = 20480×3 table
Source CH1 CH2 ______ ___ _______ 1 0.1 -0.0052 2 0.1 -0.0076 3 0.3 -0.0072 4 0.1 -0.0072 5 0.1 -0.0068 6 0.1 -0.0052 7 0.1 -0.004 8 0.1 -0.0056 9 5.1 0.004 10 5.1 0.0028 11 5.1 0.0016 12 4.9 0.0012 13 5.1 0.0008 14 5.1 0.0012 15 5.1 0.0008 16 4.9 0.0016
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)
NFFT = 32768
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
Umair Dildar
Umair Dildar 2022년 3월 23일
Thanks for the quick response. I have a question
What does this function do "Ts = mean(diff(t));"
it shows error when I run on matlab, it says
Star Strider
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);
It may be necessary to use cell2mat the entire array.
.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by