I have done the FFT analysis of a real time data. Please check weather am i right or not ?

clc;
clear;
close all;
%%Time Domain Plot
vib1=readtimetable("sing2.txt","SampleRate",1);
tiledlayout(5,1)
nexttile
plot(vib1.Time,vib1.Sing1)
N=length(vib1.Sing1);
xlabel("Time(s)")
ylabel("Ampl(mm/s^2)")
%% FFt
fs=1;%Sampling Frequency
delt=seconds(1/fs); %time step
t=0:1:length(vib1.Sing1)-1;
Totaltime=(length(vib1.Sing1)-1);
my_fft=2/N*(fft(vib1.Sing1));%FFT of Signal
abs_fft=abs(my_fft); %Absolute value of fft
delf=1/Totaltime; %Frequency Resolution
n2=1:1:N/2; %fft results are plotted for N/2 data points
fk=delf*n2;% frequency values
nexttile
plot(fk,abs_fft(1:N/2))
[v,p]=findpeaks(abs_fft(1:N/2),fk,'Threshold',0.03);
findpeaks(abs_fft(1:N/2),fk,'MinPeakHeight',0.03)
xlabel("Frequency (Hz)")
ylabel("Ampl(mm/s^2)")
%%Spectral density
nexttile
pspectrum(vib1.Sing1,vib1.Time,"spectrogram")

 Accepted Answer

Hi!
Looks correct to me your spectral analysis!
Screenshot from Signal Analyzer App. This app allows MATLAB script generation.
HTH!

10 Comments

please check fft part of the code is it correct or not.
The workflow is correct.
Here is an improved version of your code:
clear;
close all;
%% Read data from sing2.txt file
Fs = 1 ; % Sampling rate
vib1 = readtimetable("sing2.txt","SampleRate", Fs);
%% Plots - Time Domain
tiledlayout(5,1)
nexttile
plot(vib1, "Sing1")
xlabel("Time(s)")
ylabel("Ampl(mm/s^2)")
%% Compute FFT
L =length(vib1.Sing1); % Signal length
N = 2^nextpow2(L); % FFT length (to improve performance)
my_fft = fft(vib1.Sing1, N) ;% FFT of the Signal
abs_fft = abs(my_fft/N).^2 ; % FFT magnitude
f = Fs*(0:(N/2))/N ; % Frequency vector
%% Plot FFT magnitude
nexttile
plot(f, abs_fft(1: N/2+1))
xlabel("Frequency (Hz)")
ylabel("FFT Magnitude")
%% Find peaks in FFT magnitude
findpeaks(abs_fft(1: N/2+1) ,"MinPeakProminence",0.05*10^-3, "Annotate","extents")
%% Spectrogram
nexttile
pspectrum(vib1.Sing1,vib1.Time,"spectrogram")
please check the first plot command.
and please explain the line number 16.i am new to it.and find peak command. like meannin of "Annotate" and Extents
To compute the power spectrum. You can just keep like it was in your code if you re only interested in the fft magnitude .
ok thanks bro.means if i want to finad variation of frequency and amplitude then my code is correct.is it right?
You re welcome. The workflow is correct.
As you can see the plots you got are the same as the plots after you run the version code that I shared and the same as the plots obtained using Signal Analyzer App.
GL

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!