Apply a digital filter (direct form II transposed): Difference between revisions
Content added Content deleted
(add ref) |
(→{{header|ALGOL 68}}: Tweak) |
||
Line 114: | Line 114: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{Trans|C++}} ... via Yabasic<br> |
{{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. |
The default lower bound in Algol 68 arrays is 1, so the loops/subscripts have been adjusted accordingly. |
||
<syntaxhighlight lang="algol68"> |
<syntaxhighlight lang="algol68"> |
||
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: |
PROC filter = ( []REAL a, b, signal, REF[]REAL result )VOID: |
||
BEGIN |
BEGIN |
||
Line 121: | Line 124: | ||
FOR i FROM LWB signal TO UPB signal DO |
FOR i FROM LWB signal TO UPB signal DO |
||
REAL tmp := 0; |
REAL tmp := 0; |
||
FOR j FROM LWB b TO UPB b DO |
FOR j FROM LWB b TO IF i > UPB b THEN UPB b ELSE i FI DO |
||
tmp +:= b[ j ] * signal[ LWB signal + ( i - j ) ] |
|||
OD; |
OD; |
||
FOR j FROM LWB a TO UPB a DO |
FOR j FROM LWB a + 1 TO IF i > UPB a THEN UPB a ELSE i FI DO |
||
tmp -:= a[ j ] * result[ LWB result + ( i - j ) ] |
|||
OD; |
OD; |
||
result[ i ] := tmp / a[ LWB a ] |
result[ i ] := tmp / a[ LWB a ] |
||
Line 145: | Line 148: | ||
IF i MOD 5 /= 0 THEN print( ( ", " ) ) ELSE print( ( newline ) ) FI |
IF i MOD 5 /= 0 THEN print( ( ", " ) ) ELSE print( ( newline ) ) FI |
||
OD |
OD |
||
END |
|||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 153: | Line 157: | ||
-0.211722, -0.174746, 0.069258, 0.385446, 0.651771 |
-0.211722, -0.174746, 0.069258, 0.385446, 0.651771 |
||
</pre> |
</pre> |
||
=={{header|AppleScript}}== |
=={{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. |
{{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. |