How to resolve the algorithm Apply a digital filter (direct form II transposed) step by step in the Yabasic programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Apply a digital filter (direct form II transposed) step by step in the Yabasic programming language

Table of Contents

Problem Statement

Digital filters are used to apply a mathematical operation to a sampled signal. One of the common formulations is the "direct form II transposed" which can represent both infinite impulse response (IIR) and finite impulse response (FIR) filters, as well as being more numerically stable than other forms. [1] Filter a signal using an order 3 low-pass Butterworth filter. The coefficients for the filter are a=[1.00000000, -2.77555756e-16, 3.33333333e-01, -1.85037171e-17] and b = [0.16666667, 0.5, 0.5, 0.16666667] 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] [Wikipedia on Butterworth filters]

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Apply a digital filter (direct form II transposed) step by step in the Yabasic programming language

Source code in the yabasic programming language

sub filter(a(), b(), signal(), result())
    local i, j, tmp
 
    for i = 0 to arraysize(signal(), 1)
        tmp = 0
        for j = 0 to arraysize(b(), 1)
            if (i-j<0) continue
            tmp = tmp + b(j) * signal(i-j)
        next
        for j = 0 to arraysize(a(), 1)
            if (i-j<0) continue
            tmp = tmp - a(j) * result(i-j)
        next
        tmp = tmp / a(0)
        result(i) = tmp
    next
end sub
 
dim a(4), b(4), signal(20), result(20)

// a()
data 1, -2.77555756e-16, 3.33333333e-01, -1.85037171e-17
// b()
data 0.16666667, 0.5, 0.5, 0.16666667
// signal()
data -0.917843918645, 0.141984778794, 1.20536903482, 0.190286794412
data -0.662370894973, -1.00700480494, -0.404707073677, 0.800482325044
data 0.743500089861, 1.01090520172, 0.741527555207, 0.277841675195
data 0.400833448236, -0.2085993586, -0.172842103641, -0.134316096293
data 0.0259303398477, 0.490105989562, 0.549391221511, 0.9047198589

for i = 0 to 3 : read a(i) : next
for i = 0 to 3 : read b(i) : next
for i = 0 to 19 : read signal(i) : next
 
filter(a(),b(),signal(),result())

for i = 0 to 19
    print result(i) using "%11.8f";
    if mod(i+1, 5) <> 0 then
        print ", ";
    else
        print
    end if
next

  

You may also check:How to resolve the algorithm JortSort step by step in the D programming language
You may also check:How to resolve the algorithm Negative base numbers step by step in the C programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the Prolog programming language
You may also check:How to resolve the algorithm File size step by step in the Phix programming language
You may also check:How to resolve the algorithm Concurrent computing step by step in the Julia programming language