1
$\begingroup$

I have a signal sampled at 100 Hz with the frequency spectrum seen below.

Frequency spectrum

What I would like to do is to filter out the region around 0.7 Hz (say 0.7 ± 0.3 Hz) (leftmost red circle) and get rid of both the other peak around 1.5 to 3 Hz (rightmost red circle) and ideally also frequencies <0.4 Hz.

I've played around with Butterworth filters as they seem to be peoples first choice, elliptical filters as they are supposed to have the steepest roll-off and FIR filters since the first two seem to become unstable when I set very narrow passbands.

None of them seem to have a steep enough roll-off though to allow filtering at the level I'm attempting. See below for 10 to 20 Hz bandpass versions of the filters I have tested.

Tested filters

I've tried increasing orders and taps but without success.

I'm not sure if I'm trying to do something impossible here but vague memories from my signal processing course tells me that it should be possible by upsampling/downsampling combined with some clever filtering. I.e. that I can use the fact that the signal is sampled at 100 Hz and that there is no content in most of the frequencies below the Nyquist frequency.

I don't care about the phase of the signal and I can't make any assumptions about it being periodic although I don't know if it matters.

I also looked at this and must admit that the "create a lowpass filter, convert it to bandpass" currently goes over my head. The final target of my code is a Cortex M4F CPU meaning that my computational resources are not endless all-though the exact limits are not clear yet.

Is it possible to create a bandpass filter at 0.7 ± 0.3 Hz and if so could someone show me how or point me in the right direction?

Thank you in advance!

$\endgroup$
5
  • $\begingroup$ Enlarging your apparent transition width, by reducing the sample rate, will relax and enable the filter specifications for a practical design. So you may consider reducing your data rate as much as possible, and then design the bandpass filter according to new criteria, and filter your data. After filtering, you can increase your sampling rate back to the original. $\endgroup$
    – Fat32
    Commented Nov 2, 2021 at 14:27
  • $\begingroup$ I found that if i increase taps to ≈5000 i seem to be getting results along what I want but I'm unsure on if the target hardware can handle that. Yes, my memory tells me that it was possible to play around with the sample rate so I'll see if I can play around with that. $\endgroup$ Commented Nov 2, 2021 at 14:35
  • $\begingroup$ Do you have linear phase requirements? What about passband ripple and stopband attenuation? If you're not worried about linear phase, you'll probably be better off with an IIR filter like Butterworth, Chebyshev or Elliptic. With a 5000 tap FIR filter at 100 Hz you'll have to run 500000 MACs per second with using direct convolution. It may be possible but you'll be pushing the limit for sure. If you do end up using a FIR filter I would at least use fast convolution $\endgroup$
    – Ryan
    Commented Nov 2, 2021 at 15:06
  • $\begingroup$ I'm only interested in the amplitude of the signal so based on that I'm assuming I don't have any linear phase requirements and the exact requirements on ripple and attenuation are not set yet as this is just early prototyping but thank you. I'll look into if I can get something working with the IIR filters if i change attenuation and ripple. $\endgroup$ Commented Nov 2, 2021 at 15:29
  • $\begingroup$ What is the required sampling frequency of the output? If it is way below that of the input, that'll help. $\endgroup$ Commented Nov 3, 2021 at 6:52

2 Answers 2

5
$\begingroup$

The steeper something is in the frequency domain the more spread out it will be in the time domain. roughly speaking if you want a transition band of 0.1Hz width with a sample rate of 100Hz you'll need 1000s of samples. For a transition band of 0.01Hz you will need 10000s of samples.

The key here is to get the requirements right: what exactly are your pass band frequencies, what passband ripple can you tolerate, what stopband attenuation do you need and what transition bands can you afford. Once that's clear, the design process is simple enough: just crank up the order until it meets your requirement.

Typically IIR filter are better for this type of thing. However with these very low frequencies and steep transitions, you may run into numerical problems, especially if you are planning to use fixed point.

A few tricks can help

  • You seem to have a significant bias in the data. Either take this out or use a DC blocking filter to tame the very low frequencies
  • You can downsample to a lower sample rate to reduce filter complexity and increase stability.
  • Use enough points in the time domain to evaluate the filter. A filter like this takes a LONG time to reach steady state.
  • Do NOT use the transfer function form (b,a) for IIR filters. Use second order sections (SOS) or zero, pole, gain (zpk), instead. Transfer function form is numerically unstable if the poles are that close to zero.

This being said, I thought an 8th order elliptic band pass looked pretty good:

enter image description here

$\endgroup$
5
  • $\begingroup$ Thanks! I'll look into my stop band attenuation and passband ripple as i get an unstable elliptical filter if I place the cutoffs so low and close to each other. $\endgroup$ Commented Nov 2, 2021 at 15:25
  • $\begingroup$ Would you mind sharing the parameters of your filter Hilmar? I have a hard time getting anything elliptical stable if i set the cut offs that low and close. For example: b, a = signal.ellip(8, 0.1, 40, [0.4, 1], "bandpass", fs=fs) w, h = signal.freqz(b, a, fs=100) Gives me something quite uggly if I try to plot it whereas it looks decent at higher cut offs. $\endgroup$ Commented Nov 2, 2021 at 15:40
  • $\begingroup$ I designed this in Matlab. [z,p,k] = ellip(8,.1,40,[.4 1.0]*2/100); You can't design a filter like this is transfer function form. Use zpk or sos instead. $\endgroup$
    – Hilmar
    Commented Nov 3, 2021 at 6:19
  • $\begingroup$ Thank you Hilmar! That explained why I haven't been able to get stable filters. You have been immensely helpful! $\endgroup$ Commented Nov 3, 2021 at 7:29
  • $\begingroup$ Accepting this answer as it helped me implement the filter i needed by using an elliptical filter in SOS form. No need for downsampling. $\endgroup$ Commented Nov 3, 2021 at 9:37
0
$\begingroup$

Sharp cutoffs at low frequencies can indeed require a large number of taps, which means a large latency. If you can tolerate the latency, this is very well solvable with downsampling more than once. You can first run it through a low-pass filter to get a signal sampled at, say, 10 Hz, then you will need 10x less taps in the final filter. Online tool at t-filter.engineerjs.com can help you design a filter to meet the requirements. An example such filter is given below. Relaxing the requirements will make it fit the filter with less taps and vice versa. You can add more attenuation around DC and/or at higher frequencies as you see fit, as long as it's away from the transition bands.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.