I have been given a digital bandpass filter - what is it?
Show older comments
I have been given a code snippet for a digital bandpass filter. I have no idea where the author got it from or how he derived it.
% Creates y being the BandPass filtering of input signal x. The BandPass will
% accept components of wavelength *period* plus or minus about *delta*%.
% Others should be rejected.
period = 30;
delta = 0.20;
beta = cos(2*pi()/20);
gamma = 1/cos(4*pi()*delta/period);
alpha = gamma - sqrt(gamma*gamma - 1);
y(1,1)=0;
y(2,1)=0;
for i = 3:3000 % We only filter first 3000 rows of x
y(i,1) = 0.5*(1-alpha)*(x(i,1)-x(i-2,1)) + beta*(1+alpha)*y(i-1,1) - alpha*y(i-2,1);
end
If used with Period=30 and Delta=0.20 it should capture about 20% of the cyclic behaviour around a wavelength of 30 data points.
Do any of you know the mathematical derivation or family that he has used? For example is this a Butterworth, Chebyshev Type I Filter etc?
Answers (3)
Wayne King
on 19 Dec 2011
0 votes
At first glance, it doesn't look familiar, but do you have the Signal Processing Toolbox? You can easily design bandpass filters using fdesign.bandpass
Daniel Shub
on 19 Dec 2011
It is not a notation I am familiar with. But it looks like beta, gamma, and alpha are scalars and Q is unused. If that is correct then letting y = BP and x = Price gives:
y = ax-ax[2]+by[1]-cy[2]
That almost looks like a filter, but I don't understand what ax means, are you sure it is not Price[1]-Price[2]? Also I would expect it to look like:
y[n] = 0*x[n]+ax[n-1]-ax[n-2]-by[n-1]-c[n-2]
8 Comments
Stewart Charles
on 19 Dec 2011
Daniel Shub
on 19 Dec 2011
Are you sure it is not y[n] = ...? Look at the documentation of the filter command. You should be able to easily get this into a format that MATLAB is happy with and then you can plot its magnitude and phase properties.
Stewart Charles
on 19 Dec 2011
Daniel Shub
on 19 Dec 2011
Then I would suggest you edit the question so that it has valid MATLAB code in standard MATLAB format. For example, cos instead of Cosine and filter coefficients given as b and a. Then clearly ask if anyone knows what type of IIR filter it is and where the coefficients came from. That is a much clear question than "does this look familiar to you".
Stewart Charles
on 19 Dec 2011
Stewart Charles
on 20 Dec 2011
Daniel Shub
on 20 Dec 2011
It looks much better and is now a much harder question. I will have a think about it.
Stewart Charles
on 13 Sep 2021
Wayne King
on 20 Dec 2011
Hi Stewart, this is a standard 2nd order linear constant coefficient difference equation. You can mimic this filter easier in MATLAB with
B = [0.5*(1-alpha) -0.5*(1-alpha)];
A = [1 -beta*(1+alpha) alpha];
% view the filter magnitude response
fvtool(B,A);
% filter data
output = filter(B,A,input);
The filter is a bandpass filter with a narrow passband at pi/10 radians/sample. What period that actually corresponds to depends on the sampling frequency of the data.
To answer your question, the design equations look like a Chebyshev type II approximation to me.
You can design a Chebyshev type II filter using fdesign.bandpass and specifying the design method as 'cheby2'
3 Comments
Daniel Shub
on 20 Dec 2011
From Stewart's comments to me and his revised question, it seems he wants to know if this is a Butterworth filer or a Chebshev or some other common IIR filter.
Wayne King
on 20 Dec 2011
@Daniel Thank you for pointing out that omission, I have added that information.
Stewart Charles
on 13 Sep 2021
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!