I've two signals X and Y. These are proximity sensors reading measuring vibrations of a rotating shaft. Now I want to plot orbit plots for these signals. I can plot unfiltered orbits with just X and Y. But since there is lot of noise in the signal I filtered it. Now there are dominant 1X frequency component and may be other sub frequency components. I want to plot the filtered orbit of 1X say 656 Hz. The sampling frequency I used is 1000000 Hz. I know band pass filter could give me only the 1X component. But I don't have DSP toolbox. Could someone help me how to design and implement narrow band pass filter without toolbox. Any suggestion or hints or idea would be helpful. Thanks in advance.
5 Answers
The steps that I would follow to handcraft a bandpass filter are these:
- Figure out how wide (in Hz) you want the filter to be.
- Create a low-pass filter with half the one-sided bandwidth as your desired filter bandwidth. You can calculate the sinc function with basic functions, since $sinc(x) = \frac{sin(\pi x)}{\pi x}$. You can adjust the bandwidth by adjusting the time scale in your sinc function. If n is the set of all integers between -N and N, inclusive, and you make your filter taps equal to $sinc(bn)$, then the filter's normalized bandwidth will be equal to $b$.
- Modulate the lowpass filter to the center frequency you want for your bandpass filter. You do that by multiplying it, element by element, with a sine wave of that frequency.
-
$\begingroup$ Thanks for your answer. If I had a DSP toolbox how would I implement it? I tried it with basic filters like band pass ( butterworth) but it seem to fail in that context too. Could you please look into this. stackoverflow.com/questions/29111768/… $\endgroup$– AgniCommented Mar 19, 2015 at 9:09
Assuming 2 MHz sampling rate, by just simple addition of every 20 samples you get a low pass filter that will keep the noise down and will still allow you to recover every problem related to the 38K RPM source signal which you could cope with successfully since 100K is maintaining the Nyquist requirements.
If you'd like to design IIR, use pole-zero placement method. That's what people used before dsp toolboxes emerged.
A crude approach do design an IIR filter for a single frequency $\omega, 0 \le \omega \le 1$ would be as follows:
Placing poles at $ \exp(\pm j \pi \omega)$ would give infinite gain for that frequency, so move them "a bit" inside to a radius $< 1$, say, $r$.
Place zeros at $\pm 1$ to "guarantee" a bandpass filter
Place zeros at other positions on the unit circle to increase the attenuation
Figure out the gain at $\omega$, where it would/should be the highest, and compensate for that
For your example:
omega = 656/(1000000)/2;
r = 0.99;
b = conv([1 -1], [1 1]);
a = conv([1 -r*exp(j*pi*omega)],[1 -r*exp(-j*pi*omega)]);
will form a start. Considering that the 1X frequency is rather low, you could add a number of zeros at some higher frequencies:
zerof = 0.1; % Corresponding to 50000 Hz
b = conv(b, conv([1 -exp(j*pi*zerof)],[1 -exp(-j*pi*zerof)]));
zerof = 0.5; % Corresponding to 250000 Hz
b = conv(b, conv([1 -exp(j*pi*zerof)],[1 -exp(-j*pi*zerof)]));
and multiple poles at the wanted frequency;
a = conv(a,a);
Once you are happy, you just need to figure out the gain and compensate for that.
This filter has about 80 dB attenuation for frequencies of 50000 Hz and higher (as someone pointed out, the sampling frequency is really high if correct).
-
$\begingroup$ This would be a quite rudimentary and manual pole-zero placement approach (there are automatic methods which are able to find better positions than those I more or less just made up). $\endgroup$– OscarCommented Mar 19, 2015 at 19:32
If you know how to design and apply Kaiser window, i would aim for a brickwall bandpass that might have (symmetrical and non-causal) impulse response
$$ h[n] = \cos(\omega_0 n) \cdot \frac{\sin(\omega_1 n/2)}{\omega_1 n/2} \quad \forall n \in \mathbb{Z} $$
assuming $0 < \omega_1 < \omega_0$, the bandedges should be at $\omega_0 \pm \omega_1$. the number of samples of $h[n]$ to keep and the "$\beta$ factor" for the Kaiser window would be things you have to fiddle with.
filter
to apply them. $\endgroup$