02-08-2024 10:39 AM - edited 02-08-2024 10:41 AM
I am using an MCU to interrupt and read accelerometer data at a rate of 100Hz, and I want to calculate displacement. However, when I move the accelerometer, there inevitably appears to be an offset (zero calibration was performed at initialization) Many articles mention that high-pass filtering the velocity can make the calculation of displacement more accurate. However, as you can see from the diagram, once I apply a high-pass filter to the velocity signal, the signal becomes strange with bumps appearing. Is there any way to solve this? PS. I have attached the data (without high-pass filtering, and the actual displacement is around 19.7cm). X represents acceleration, Y represents velocity after the first integration, and Z represents displacement after the second integration.
02-08-2024 12:28 PM
Well, your cutoff frequency is 100 hz and the Nyquist frequency is 50hz. That is going to provide poor results. Try a cutoff around 20Hz
02-08-2024 01:34 PM - edited 02-08-2024 01:34 PM
100Hz is the sampling frequency, and 0.075 is the cutoff frequency.
02-08-2024 03:45 PM
I haven't done much with high-pass filtering so am not equipped to explain the tail end of the curve that looks similar to exponential decay. I'm more familiar with low-pass filtering (though I'm not exactly an expert there either).
In any event, I would think you should be doing your high-pass filter *before* the integration step. The purpose of the high-pass filter is to reject DC offset and near-DC drift so you don't integrate them into a velocity ramp or drift. So you need to filter first, integrate second.
-Kevin P
02-08-2024 04:21 PM - edited 02-08-2024 04:26 PM
I think the problem is the integration function. You have no starting values defined. If I were you I would just generate a running sum of your data to do the integration shown below. That way, you don't have to worry about the initial conditions. With the high-pass filter you just might set the cutoff to 0.005 Hz or lower just to isolate the DC value. Kevin_P is correct in that the high-pass filter should be first.
02-09-2024 12:45 AM
Even if I put the filter at the very beginning (acceleration), there is still no difference. 0.005Hz is too low, causing the offset to not be corrected.😞