How to plot a spectral analysis of a displacement signal

2 views (last 30 days)
Hi,
ive been trying to plot a Spectral analysis of a displacement signal but with no luck. I have data in excel sheet(included in attachments). I know i need to use FFT though all of my tries have given me something that does not really correlate with what i can find in my manuals for the excercise (university project).
Data - D is my signal input that needs to be analysed.
i have tried following code(one of many i tried):
>>fs = 10000; % Hz
D_fft = fft(D);
N = length(D);
f = (0:N-1) * (fs/N);
plot(f, abs(Y_fft))
The plot on the right is how it kinda should look like.
Any help much appreciated

Accepted Answer

dpb
dpb on 3 Jun 2023
Edited: dpb on 3 Jun 2023
data=readmatrix('MTACT.xlsx');
t=data(:,1);y=data(:,2);
subplot(2,1,1)
plot(t,y)
dt=mean(diff(t));
Fs=1/dt;
L=numel(t);
y=detrend(y,0);
Y=fft(y);
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;
subplot(2,1,2)
plot(f,P1)
ylim([0 0.05])
follows the amplitude spectrum example given at fft.
NOTA BENE: The time signal is riding on a DC value the same magnitude as the peak excursion; if you don't detrend to remove the mean, it may overwhelm the spectral content and the plot autoscale will not show anything at higher frequencies if the overall magnitude on the plot is 3 or so...

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!