Search code examples
matlabsignal-processingfftspectrum

fft Matlab vibration time domain to frequency measurement duration= 60 s


I'm trying to convert the vibration signal in the time domain to the frequency domain (use fft) to show the Magnitude Response. But the graph show like this. Can you please take a look and see where I go wrong with this?

About the data is the vibration from the reciprocating compressor in time domain start on 1/4/2015 0:00:00 - 15/4/2015 1:46:00 have 20267 rows, measurement duration= 60 s or 1 minute, RPM of compressor = 372.99152 RPM Link to dataset in data x45= vibration (m/s^2) and x52 = rpm of compressor

%% load vibration data in csv file
filename = 'data.csv';
T = readtable(filename);

T1 = T(:,1:2);
x45 = T1{:,2};

plot(T.time,T.x45);
xlabel('Time in seconds');
ylabel('Amplitude of signal');

dc3 = dsp.DCBlocker('Algorithm','Subtract mean'); % I use mean to remove dc-offset
y3 = dc3(T.x45); 

%% Use FFT convert time domain signal into frequency domain
% FFT output follows complex notation (a+ib)
X45 = fft(y3); % X45 is the frequency domain representation

%% Retrieve the magnitude information from X45
X45_mag = abs(X45); 

%% Retrieve the phase information from X45
X45_phase = angle(X45); 

%% Frequency bins
N = length(x45);
Ts = 60; % measurement duration= 60 s or 1 minute
Fs = 1 / Ts ;
Fbins = ((0: 1/N: 1-1/N)*Fs).'; 

%% Plot magnitude response
helperFFT(Fbins,X45_mag,'Magnitude Response')

%% Plot phase response
helperFFT(Fbins,X45_phase,'Phase Response')


function helperFFT(bin, yVal,titleStr)
%Copyright 2014 The MathWorks, Inc
close all;clc;
figure;
plot(bin, yVal,'Color',[0,0,1],'LineWidth',1.5); box on; grid on;
xlabel('Frequency (Hz).'); 
if strcmp(titleStr,'Phase Response');
ylabel('Radians');
title('FFT - Phase Response');
else
ylabel('Magnitude');
title('FFT - Magnitude Response');
end

Time domain signal: Time

Magnitude spectrum: Magnitude

Phase spectrum: Phase


Solution

  • Your magnitude spectrum looks OK, but you only need to plot half of the spectrum (real signals have complex conjugate symmetry).

    Also check out MATLAB functions like periodogram, which do a lot of the above work for you.