How to plot the fft if we are having the data ?
4 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Sulaymon Eshkabilov
on 10 Jul 2021
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)|')
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!