Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to plot HPF and LPF 3rd and 4th order

Status
Not open for further replies.

Bluebirdglory

Newbie level 1
Joined
Aug 7, 2009
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,311
lpf hpf

Hi everybody,
Im a Software Engineering student and im supposed to make a Parametric Equlizer which can plot the graph of Peaking filter and LPF and HPF. by now i could have get plot the peaking filter by using the coefficients a0,a1,a2,b0,b1,b2 (biquad) and then finding the magnitude response directly, i have coded it in VB which l will attach it at the end, but now the problem is , when i want to do the same thing for LPF and HPF (using the corespondant values ) i just can have the curve for 1st and 2nd order, but i need to plot the 3rd and 4th order as well. any ne know how can i solve it ?

b0 = 1.0
b1 = 0.0
b2 = 0.0
a0 = 1.0
a1 = 0.0
a2 = 0.0

GainDb = inputG
F0 = inputF
myQ = inputQ
gain = 10 ^ (Abs(GainDb) * 0.05)
Fs = 48000

order = inputQ / 6
w0 = Tan(PI * F0 / Fs)
iden = 0.0
w2 = w0 * w0
myQ = myQ * (PI * F0 / Fs) / w0

If TrackGain.Enabled Then 'for peak EQ
If GainDb <= 0.0 Then
iden = 1.0 / (1.0 + (1.0 / myQ * w0) + w2)
b2 = iden * (1.0 - (gain / myQ * w0) + w2)
b1 = iden * 2.0 * (w2 - 1.0)
b0 = iden * (1.0 + gain / myQ * w0 + w2)
a2 = iden * (1.0 - (1.0 / myQ * w0) + w2)
a1 = iden * 2.0 * (w2 - 1.0)
Else
iden = 1.0 / (1.0 + (gain / myQ * w0) + w2)
b2 = iden * (1.0 - (1.0 / myQ * w0) + w2)
b1 = iden * 2.0 * (w2 - 1.0)
b0 = iden * (1.0 + (1.0 / myQ * w0) + w2)
a2 = iden * (1.0 - (gain / myQ * w0) + w2)
a1 = iden * 2.0 * (w2 - 1.0)
End If
a0 = 1.0

peakCalcPlot()

Else ' for LPF and HPF '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

If order <> 2 Then
iden = 1.0 / (w0 + 1.0)
If isHPF Then
y1(1) = iden
y1(0) = -iden
x1(1) = iden * (w0 - 1.0)
Else
y1(1) = iden * w0
y1(0) = y1(1)
x1(1) = iden * (w0 - 1.0)
End If
x1(0) = 1.0
End If
If order >= 2 Then
If (order = 2) Then
iden = 1.0 / (1.0 + 1.4142135623731 * w0 + w2)
x2(2) = iden * (1.0 - 1.41421354F * w0 + w2) ' /* Q=1/sqrt(2) */
Else
iden = 1.0 / (1.0 + 1.0 * w0 + w2) '/* Q=1 */
x2(2) = iden * (1 - 1 * w0 + w2)
End If
x2(1) = iden * 2.0 * (w2 - 1.0)
x2(0) = 1.0
If isHPF Then
y2(2) = iden
y2(1) = iden * (-2)
y2(0) = iden
Else
y2(2) = iden * w2
y2(1) = iden * 2.0 * w2
y2(0) = iden * w2
End If
End If

b0 = 1.0
b1 = 0.0
b2 = 0.0
'b3 = 0.0
a0 = 1.0
a1 = 0.0
a2 = 0.0


If order = 1 Then
b0 = y1(0)
b1 = y1(1)
b2 = 0
'b3 = 0
a0 = 1
a1 = x1(1)
a2 = 0

ElseIf order = 2 Then

b0 = y2(0)
b1 = y2(1)
b2 = y2(2)
'b(3) = 0
a0 = 1
a1 = x2(1)
a2 = x2(2)


ElseIf order = 3 Then
b0 = y1(0) * y2(0)
b1 = y1(0) * y2(1) + y1(1) * y2(0)
b2 = y1(0) * y2(2) + y1(1) * y2(1)


a0 = 1
a1 = x1(1) + x2(1)
a2 = x2(2) + x1(1) * x2(1)

Else
b0 = y1(0) * y2(0)
b1 = y1(0) * y2(1) + y1(1) * y2(0)
b2 = y1(0) * y2(2) + y1(1) * y2(1)


a0 = 1
a1 = x1(1) + x2(1)
a2 = x2(2) + x1(1) * x2(1)

End If

LPHPCalcPlot()
End If

End Sub



Private Sub peakCalcPlot()
'Calculate the curve values
For i As Integer = 0 To Graph(myKey).ptsArray.Length - 1
iExp = (10 * (10 ^ ((i + first20) / (gWidth / 3.0))))
yAxisValue = 0.0

omega = 2 * PI * iExp / Fs
cosW0 = Cos(omega)
cos2W0 = Cos(2.0 * omega)

num = (b0 ^ 2) + (b1 ^ 2) + (b2 ^ 2) + (2.0 * cosW0 * ((b0 * b1) + (b1 * b2))) + (2.0 * cos2W0 * b0 * b2)
den = 1.0 + (a1 ^ 2) + (a2 ^ 2) + (2.0 * cosW0 * (a1 + (a1 * a2))) + (2.0 * cos2W0 * a2)

yAxisValue = (Abs(num / den))

Graph(myKey).ptsArray(i).X = i
Graph(myKey).ptsArray(i).Y = 3 * (10 * Log10((yAxisValue))) + gHeightCenter
Next i
End Sub





actually i useed the following formulas to calculate a0.....b2 since the standard formulas didn work for me i used to got the formulas from :

LPF: H(s) = 1 / (s^2 + s/Q + 1)

b0 = (1 - cos(w0))/2
b1 = 1 - cos(w0)
b2 = (1 - cos(w0))/2
a0 = 1 + alpha
a1 = -2*cos(w0)
a2 = 1 - alpha



HPF: H(s) = s^2 / (s^2 + s/Q + 1)

b0 = (1 + cos(w0))/2
b1 = -(1 + cos(w0))
b2 = (1 + cos(w0))/2
a0 = 1 + alpha
a1 = -2*cos(w0)
a2 = 1 - alpha


but i dono why these formulas dosen work ,,, and also i think if i want to have 3rd and 4th order i need the value of a3,a4,b3,b4 as well, am i correct?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top