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

Added 11l
(Added 11l)
Line 8:
 
The signal that needs filtering is the following vector: [-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]
 
=={{header|11l}}==
{{trans|Nim}}
 
<lang 11l>F apply_filter(a, b, signal)
V result = [0.0] * signal.len
L(i) 0 .< signal.len
V tmp = 0.0
L(j) 0 .< min(i + 1, b.len)
tmp += b[j] * signal[i - j]
L(j) 1 .< min(i + 1, a.len)
tmp -= a[j] * result[i - j]
tmp /= a[0]
result[i] = tmp
R result
 
V a = [1.00000000, -2.77555756e-16, 3.33333333e-01, -1.85037171e-17]
V b = [0.16666667, 0.5, 0.5, 0.16666667]
 
V 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]
 
V result = apply_filter(a, b, signal)
L(r) result
print(‘#2.8’.format(r), end' ‘’)
print(I (L.index + 1) % 5 != 0 {‘, ’} E "\n", end' ‘’)</lang>
 
{{out}}
<pre>
-0.15297399, -0.43525783, -0.13604340, 0.69750333, 0.65644469
-0.43548245, -1.08923946, -0.53767655, 0.51704999, 1.05224975
0.96185430, 0.69569009, 0.42435630, 0.19626223, -0.02783512
-0.21172192, -0.17474556, 0.06925841, 0.38544587, 0.65177084
</pre>
 
=={{header|Ada}}==
1,480

edits