Adaptive Band pass filter for extracting respiratory waveform from accelerometer data I am recording data from an accelerometer attached to the chest (1000Hz). I need to extract the respiratory waveform. I tried an adaptive bandpass filter based on a dominant frequency in my signal based on https://cutt.ly/j24zdj.

Steps in brief: Take frequency spectra, find dominant freq f0, Make a bandpass filter as [max(0.1,f0-0,4), 0.4+rm]

The respiration rate could be between anything from 0.1 to 2 Hz. For deep and normal breathing, the filter works just fine. But for rapid and shallow breathings (low amplitude but high freq), it fails. It identifies the dominant freq incorrectly and thus the entire filter goes wrong.

For example in the image below: The dominant freq should have been around 0.6, but is identifies as 1.7 (Slight diff in amplitude). So filter works badly.

1) How do I design a filter for this? Any suggestions. I can't control the noise in this freq range. The person is as still as possible.

2) The red line is spectra after filtering. Why has the amplitude of certain frequencies increased? I am using the 'spec' function in R: uses the hanning window for computing. 

It's not the issue with plotting. The amplitudes have actually increased.
Under the extremely controlled conditions required to measure respiratory rate using this method, you can try to use the autocorrelation (which is more robust in the presence of noise) to determine the "dominant" frequency in your signal.


  2) The red line is spectra after filtering. Why has the amplitude of certain frequencies increased? I am using the 'spec' function in R: uses the hanning window for computing.


If that is not a mere rescaling of the waveform as it gets plotted over the same figure (?), then it would be safe to assume that the filter included some overall gain.

Hope this helps.