How to plot the fft if we are having the data ?

4 次查看(过去 30 天)
load('Lp_400_Bw5.mat')
xlsread('Messdaten');
time=ans(:,1); % Time vector
data = ans(:,2);
Messdaten1=ans(:,2);
fs=1/1.000000000000000e-03;
N=size(Messdaten1);
% X=fft({Messdaten}*2/N;
%f=fs/(N)*(1:N)
hfp = fplot(Messdaten1);
xv = hfp.XData;
yv = hfp.YData;
X=fft(yv);
Error is Error using fft
Invalid data type. First argument must be double, single, int8, uint8, int16, uint16, int32, uint32, or
logical.

回答(1 个)

Sulaymon Eshkabilov
Hi,
Here is a correct and complete code for fft calc and plot with your data given in .xls data file:
clearvars; clf;
D=readtable('Messdaten.xls');
time=D.Var1; % Time
X = D.Var2; % Data
Fs=1e3; % Sampling frequency, [Hz]
L = length(X);
N = 2^nextpow2(L);
Y = fft(X, N);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
plot(f,P1)
title('Single-Sided Amplitude Spectrum of S(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by