11-11-2025 04:09 AM
Hello,
I'm trying to replicate CFC filters by using the mathematical calculation, but it's not quite working. I have something like this for CFC60:
dim cfc, T, wd, wa, a0, a1, a2, b1, b2, pi
cfc = 60
T = 0.00005 'Sampling rate in seconds.
pi = 3.141592653589793
'wd = 2 * pi * cfc * 2.0775 'SAE J211
wd = 2 * pi * cfc * 1.25 * 5/3 'ISO 6487
wa = sin(wd * T / 2)/cos(wd * T / 2)
a0 = wa*wa / (1 + sqrt(2) * wa + wa*wa)
a1 = 2 * a0
a2 = a0
b1 = -2 * (wa*wa - 1) / (1 + sqrt(2) * wa + wa*wa)
b2 = (1 - sqrt(2) * wa - wa*wa) / (1 + sqrt(2) * wa + wa*wa)
LogFileWrite "wd = " & wd & vbLf & "wa = " & wa & vbLf & "a0 = " & a0 & vbLf & "a1 = " & a1 & vbLf & "a2 = " & a2 & vbLf & "b1 = " & b1 & vbLf & "b2 = " & b2
dim oCh, oChOrigin
set oCh = Data.Root.ChannelGroups(1).Channels("cfc60result")
set oChOrigin = Data.Root.ChannelGroups(1).Channels("D0HEAD0000PAACXP")
oCh.Values(1) = oChOrigin.Values(1)
oCh.Values(2) = oChOrigin.Values(2)
dim ii
for ii = 3 to oCh.Size
oCh.Values(ii) = a0 * oChOrigin.Values(ii) + a1 * oChOrigin.Values(ii - 1) + a2 * oChOrigin.Values(ii - 2) + b1 * oChOrigin.Values(ii - 1) + b2 * oChOrigin.Values(ii - 2)
next
' Backward
for ii = oCh.Size - 2 to 1 step -1
oCh.Values(ii) = a0 * oCh.Values(ii) + a1 * oCh.Values(ii + 1) + a2 * oCh.Values(ii + 2) + b1 * oCh.Values(ii + 1) + b2 * oCh.Values(ii + 2)
next
Should this work or am I understanding it wrong? The second pass generates an overflow because b1 and b2 are too high. The resulting channel gets crazy values like -1.14643186630641E+308.
Thanks!
Kindest regards,
Néstor
11-12-2025 02:44 AM
I found the error, b2 should be:
b2 = (-1 + sqrt(2) * wa - wa*wa) / (1 + sqrt(2) * wa + wa*wa)
However, the result doesn't match the Crash Analysis CFC60 filter results with the same input data.
Does Crash Analysis apply a different calculation?