bandpass filter code

Posted By: hola123

bandpass filter code - 03/08/20 22:03

Hi,

I am reading about cycles and am very interested in the topic. The function bandpass seems very powerful but bit of a black box. Is there any code anywhere or if not any code any information on the type of algorithm it is using?

Cheers
Posted By: dr_panther

Re: bandpass filter code - 07/26/20 09:37

There is a very good explanation of spectral analysis in the blackbook of JCL, I also think this concepts might be explained in Ehlers book.
Posted By: rki

Re: bandpass filter code - 04/10/23 11:46

I can confirm that the blackbook does not have the code for BandPass filter
Posted By: rki

Re: bandpass filter code - 04/10/23 18:43

Ehler's work has a Roofing Filter that is a BandPass filter. Below is code for that
def RoofingBandPassFilter (vals):
filt = np.ones (len(vals))*vals
hps = np.ones(len(vals))*vals

for i in range (2, len(vals)):
# Highpass filter cyclic components whose periods are shorter tahn 48 bars
# converted cos and sin arguments from degrees to radians as mentioned in the paper
alpha1 = (np.cos(0.0925) + np.sin(0.0925) - 1) / np.cos(0.0925)
hps[i] = ((1.0-alpha1/2.0)**2)*(vals[i]-2*vals[i-1]+vals[i-2]) + 2*(1-alpha1)*hps[i-1] - ((1-alpha1)** 2)*hps[i-2]

# smooth with a super smoother
a1 = np.exp(-1.414 * 3.14159 / 10)
b1 = 2 * a1 * np.cos(0.436)

c3 = -a1 * a1
c1 = 1 - b1 - c3
filt[i] = c1*(hps[i]+hps[i-1])/2 + b1*filt[i-1] + c3*filt[i-2]
return filt

But it does not have the center and width parameters of zorro
Posted By: madpower2000

Re: bandpass filter code - 04/17/23 19:58

Book: Cycle analytics for traders : advanced technical trading concepts / John F. Ehlers. 2013
EasyLanguage, Code Listing 5-1.
Code
{
    BandPass Filter
    © 2013 John F. Ehlers
}
Inputs:
    Period(20),
    Bandwidth(.3);
    Vars:
    alpha2(0),
    HP(0),
    gamma1(0),
    alpha1(0),
    beta1(0),
    BP(0),

alpha2 = (Cosine(.25*Bandwidth*360 / Period) + Sine (.25*Bandwidth*360 / Period) - 1) / Cosine(.25*Bandwidth*360 / Period);
HP = (1 + alpha2 / 2)*(Close - Close[1]) + (1- alpha2)*HP[1];
beta1 = Cosine(360 / Period);
gamma1 = 1 / Cosine(360*Bandwidth / Period);
alpha1 = gamma1 - SquareRoot(gamma1*gamma1 - 1);
BP = .5*(1 - alpha1)*(HP - HP[2]) + beta1*(1 + alpha1)*BP[1] - alpha1*BP[2];
© 2024 lite-C Forums