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

add RPL
(Added XPL0 example.)
(add RPL)
Line 1,467:
20 0.651770838819
</pre>
 
=={{header|RPL}}==
We use here useful list handling functions that are available from HP48G or newer models.
{| class="wikitable"
! RPL code
! Comment
|-
|
ROT REVLIST ROT REVLIST → signal a b
≪ { } 1 signal SIZE '''FOR''' j
signal j b SIZE - 1 + j SUB
'''WHILE''' DUP SIZE b SIZE < '''REPEAT''' 0 SWAP + '''END'''
b * ∑LIST
OVER j a SIZE - 1 + j 1 - SUB 0 +
'''WHILE''' DUP SIZE a SIZE < '''REPEAT''' 0 SWAP + '''END'''
a * ∑LIST -
a DUP SIZE GET / +
'''NEXT'''
≫ ≫ '<span style="color:blue">'''FILTR'''</span>' STO
|
<span style="color:blue">'''FILTR'''</span> ''( {a} {b} {signal} → {filtered} ) ''
Reverse a and b
For j = 1 to last signal item
extract what to multiply to b
prepend 0's if necessary
multiply by b and sum
extract what to multiply by a except a[0]
prepend 0's if necessary
multiply by a, sum and substract
divide by a[0] which is the last item once a reversed
|}
Figures have been rounded to 3 digits after the decimal point to ease the 100% manual data transfer.
{ 1 -2.778E-16 0.3333 -1.851E-17 }
{ 0.1667 0.5 0.5 0.1667}
{ -0.9178 0.1420 1.2054 0.1903 -0.6624
-1.007 -0.4047 0.8005 0.7435 1.0109
0.7415 0.2778 0.4008 -0.2086 -0.17281 -
-0.1343 0.02593 0.4901 0.5494 0.90472 }
<span style="color:blue">'''FILTR'''</span> 3 RND
'''Output:'''
<span style="color:grey"> 1:</span> { -.153 -.435 -.136 .697 .656
-.436 -1.089 -.538 .517 1.052
.962 .696 .425 .196 .028
-.212 -.175 .069 .386 .652 }
 
=={{header|Ruby}}==
1,150

edits