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

(add ref)
Line 114:
=={{header|ALGOL 68}}==
{{Trans|C++}} ... via Yabasic<br>
... with the "j" loops transformed to not needlessly iterate beyond i.<br>
The default lower bound in Algol 68 arrays is 1, so the loops/subscripts have been adjusted accordingly.
<syntaxhighlight lang="algol68">BEGIN # apply a digital filter #
BEGIN # apply a digital filter #
# the lower bounds of a, b, signal and result must all be equal #
PROC filter = ( []REAL a, b, signal, REF[]REAL result )VOID:
BEGIN
Line 121 ⟶ 124:
FOR i FROM LWB signal TO UPB signal DO
REAL tmp := 0;
FOR j FROM LWB b TO IF i > UPB b THEN UPB b ELSE i FI DO
IF i >= j THEN tmp +:= b[ j ] * signal[ LWB signal + ( i - j ) ] FI
OD;
FOR j FROM LWB a + 1 TO IF i > UPB a THEN UPB a ELSE i FI DO
IF i >= j THEN tmp -:= a[ j ] * result[ LWB result + ( i - j ) ] FI
OD;
result[ i ] := tmp / a[ LWB a ]
Line 145 ⟶ 148:
IF i MOD 5 /= 0 THEN print( ( ", " ) ) ELSE print( ( newline ) ) FI
OD
END
END</syntaxhighlight>
{{out}}
<pre>
Line 153 ⟶ 157:
-0.211722, -0.174746, 0.069258, 0.385446, 0.651771
</pre>
 
=={{header|AppleScript}}==
{{trans|Julia}} — except that j starts from 2 in the second inner repeat, there being no point in fetching and performing math with the zero about to be overwritten. This change in turn allows the result list to be populated on the fly instead of being pre-populated with zeros.
3,032

edits