Jump to content

Apply a digital filter (direct form II transposed): Difference between revisions

m
no edit summary
m (Move to task status, multiple implementations and little controversy.)
mNo edit summary
Line 204:
<pre>-0.152974,-0.435258,-0.136043,0.697503,0.656445,-0.435483,-1.08924,-0.537677,0.51705,1.05225,0.961854,0.69569,0.424356,0.196262,-0.0278351,-0.211722,-0.174746,0.0692584,0.385446,0.651771,</pre>
 
=={{header|Julia}}==
{{trans|zkl}}
<lang julia>
const acoef = [1.00000000, -2.77555756e-16, 3.33333333e-01, -1.85037171e-17]
const bcoef = [0.16666667, 0.5, 0.5, 0.16666667]
const signal = [-0.917843918645, 0.141984778794, 1.20536903482, 0.190286794412,
-0.662370894973, -1.00700480494, -0.404707073677 ,0.800482325044,
0.743500089861, 1.01090520172, 0.741527555207, 0.277841675195,
0.400833448236, -0.2085993586, -0.172842103641, -0.134316096293,
0.0259303398477, 0.490105989562, 0.549391221511, 0.9047198589]
 
function DF2TFilter(a,b,s)
ret = zeros(s)
for i in 1:length(s)
temp = 0.0
for j in 1:length(b)
if i - j >= 0.0
temp += b[j] * s[i-j+1]
end
end
for j in 1:length(a)
if i - j >= 0.0
temp -= a[j] * ret[i-j+1]
end
end
ret[i] = temp / a[1]
end
ret
end
 
println(DF2TFilter(acoef, bcoef, signal))</lang>
{{output}}<pre>
[-0.152974, -0.435258, -0.136043, 0.697503, 0.656445, -0.435482, -1.08924, -0.537677, 0.51705, 1.05225,
0.961854, 0.69569, 0.424356, 0.196262, -0.0278351, -0.211722, -0.174746, 0.0692584, 0.385446, 0.651771]
</pre>
=={{header|Kotlin}}==
{{trans|C++}}
4,108

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.