Clear Filters
Clear Filters

How to implement either a High/Low Pass filter on accelerometer data.

70 views (last 30 days)
Hello all,
I have collected data from an accelerometer and have been reading and attempting to understand past posts for hours now however I don't believe I know enough about signal processing to properly implment the filter I need. For my accelerometer, I set the output data rate to 50hz so the bandwidth would be 25hz and sampled at 10hz (10 times /sec) to account for Nyquist.
My data is highly noisy and I am trying to extract frequencies which based on similar research in my field should be between 0.1-1hz range. Also from research papers I've read it seems previous research either uses a high pass butterworth filter or a lowpass filter.
I have implemented an FFT first however I'm not quite sure how to discern it and accuratley apply a filter passing the signal in the desired range through to obtain a filtered dataset. I'll provide an image and code below (not sure if correct).
I would really appreciate if someone would step me through how to implement a filter on my dataset so I can clearly discern the peak frequencies in my data and have a filtered dataset going foward. I'm pretty amateur to both signal processing and Matlab! Thank you, I'd really like to understand it.
X = readmatrix('30min.CSV');
Y = fft(X);
L = 133361; %Length of matrix
Fs = 10; %Sampling Frequency (hz)
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;
title("Single-Sided Amplitude Spectrum of X(t)")
xlabel("f (Hz)")

Answers (1)

Star Strider
Star Strider on 28 Sep 2022
For my accelerometer, I set the output data rate to 50hz so the bandwidth would be 25hz and sampled at 10hz (10 times /sec) to account for Nyquist.
It is difficult for me to interpret this. If the sampling frequency is 50 Hz, the Nyquist frequency is 25 Hz, so it should be relatively straightforward to filter a signal in the range of 0.1 Hz to 1 Hz.
The signal appears to have broadband noise. The easiest way to eliminate that is with the Savitzky-Golay filter (sgolayfilt function) since a frequency-selective filter will passd the noise as well as the signal in its passband. Use the bandpass , highpass or lowpass functions for the other filtering, and specify 'ImpulseResponse','iir' for best results. Those functions will design a very efficient elliptic filter for each.
CAN105 on 29 Sep 2022
Thank you for the clarification!
I have tried out the Savitzky-Golar filter and got some things to work but am not entirley sure it is correct and I didn't want to go down too many rabbit holes so I'll post my progress here so far. I commented some general questions but I certainly don't expect you to answer all of them! I'm mainly trying to see if I am on the right path. I'm not sure how to implement filtering out data above 2hz and below 0.01 still...
Ultimatley I need to take 10 minute chunks to analyze dominant frequecy across larger csv files.
% Star Strider recommends Savitzky-Golay filter first to reduce broadband
% noise then followed by a bandpass, highpass, or lowpass function for
% other filtering...%
X = readmatrix('20220825_1Hr_Rollonly.csv'); % Create matrix of accelerometer data
%% Apply Savitzky-Golay filter to smooth data
order= 3; %How do we determine order?
framelen = 6001; %Why does framelen need to be odd?
%Trying 10minute chunk of data
yg = sgolayfilt(X,order,framelen);
hold on
%% Apply highpass filter to smoothed data
fs =10; %Sample Rate (10hz)
yh = highpass(yg,0.01,fs, ImpulseResponse="iir");
Star Strider
Star Strider on 29 Sep 2022
The Savitzky-Golay filter seems to have reduced much of the noise, as well as the signal energy.
If you want to filter the signal between 0.01 Hz and 2 Hz, use the bandpass function instead. The syntax is almost the same.
I do not have the data, so one way to determine if the sampling intervals are regular is with:
Tsmean = mean(diff(t))
Tsstd - std(diff(t))
The ‘Tsmean’ value will be the mean sampling interval (the inverse of the sampling frequency, so ideally about 0.1 here), and ‘Tsstd’ the standard deviation of the sampling intervals. It should be on the order of indicating that the sampling intervals are regular. If it is on the order of for example, the data need to be resampled (using the link I posted earlier) to a constant sampling interval in order for the digital filters to work correctly.
The documentation does not specify the reason that ‘framelen’ needs to be odd. I suspect it is so that it is symmetrical about a specific value, that value corresponding to the output. I have not explored the theory behind it, or read the references.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!