Hello everyone, I have an acceleration signal from an accelerometer. I wrote a simple script in order to analyse this signal: I plotted the signal in time domain, I performed a frequency domain analysis, I filtered and realigned the signal and at the end I tried to reconstruct velocity and displacement with the cumtrapz function. The code is in the following:
clc;clear all;close all;file_acc='CT4H1X21-2.xlsx';x_acc=xlsread(file_acc);%%Time domain analysis of acceleration signal
Fsa=19200;Ta=1/Fsa;xa=x_acc(:,3);Na=length(xa);ta=linspace(0,Na*Ta,Na);figureplot(ta,xa)grid ontitle('Acc. on the sparger')xlabel('t (s)')ylabel('xa(t), Acceleration (g)')%%Frequency domain analysis of accelerometric signal
NFFT2_acc = 2^nextpow2(Na); % Next power of 2 from length of y
Xa=fft(xa-mean(xa),NFFT2_acc)/Na;fa=Fsa/2*linspace(0,1,NFFT2_acc/2+1);figure;plot(fa,2*abs(Xa(1:NFFT2_acc/2+1))) grid ontitle('Single-Sided Amplitude Spectrum of xa(t)')xlabel('f (Hz)')ylabel('Xa(f)')%%Plot the Power Spectral Density of the accelerometric signal
figure;[pxxa,fxa] = pwelch((xa-mean(xa)),[],[],[],Fsa);plot(fxa,pxxa);grid ontitle('Power Spectral Density of xa(t)')xlabel('Frequency (Hz)')ylabel('Power/Frequency (dB/Hz)')%%Butterworth filter for accelerometric signal
Fca=150;Fsa=19200;[ba,aa]=butter(10,Fca/(Fsa/2));figure;freqz(ba,aa)dataIna=xa;% Apply the filter to Smooth out the Signal
xafilter=filter(ba,aa,dataIna);% Overlay the filtered pressure signals on the original signals
% Filtered signal is delayed
figure;plot(ta,xa,'b',ta,xafilter,'r');grid on;title('xa (accelerometric signal)')xlabel('t (s)')ylabel('acc. (g)')legend({'Original xa Signal','Filtered xa Signal'});%set(gcf,'NumberTitle','Off', 'Name','Filtered Signal vs. Actual Signal');
%%Compare the original accelerometric signal and delay compensated filtered accelerometric signal
figure;%xfiltfilt = filtfilt(d.sosMatrix,d.ScaleValues,x2);
xfiltfilta=filtfilt(ba,aa,xa);plot(ta,xa,ta,xfiltfilta);grid ontitle('xa accelerometric signal')xlabel('t (s)')ylabel('acc (g)')legend({'Original xa Signal','Actual xa Signal (filtered and realigned signal)'});%%Frequency domain analysis of the filtered and realigned accelerometric signal
Xaf=fft(xfiltfilta-mean(xfiltfilta),NFFT2_acc)/Na;figure;plot(fa,2*abs(Xaf(1:NFFT2_acc/2+1))) grid onxlim([0 150])title('Single-Sided Amplitude Spectrum of xa(t) filtered and realigned Signal')xlabel('f (Hz)')ylabel('Xa(f)')%%Velocity
acceleration=xfiltfilta*9.80665;velocity=cumtrapz(ta,acceleration);figure;plot(ta,velocity);grid ontitle('Velocity of the sparger from the acceleration signal')xlabel('t (s)')ylabel('Velocity (m/s)')%%Displacement
displacement=cumtrapz(ta,velocity);figure;plot(ta,displacement);grid ontitle('Displacement of the sparger from the velocity signal')xlabel('t (s)')ylabel('Displacement (m)')
I'm not sure of what I did; in particular I found displacement of the order of meters and this is clearly an error. May someone take a look at my code? Thank you very much.
Best Answer