Presentation is loading. Please wait.

Presentation is loading. Please wait.

Implementing real-time convolution

Similar presentations


Presentation on theme: "Implementing real-time convolution"— Presentation transcript:

1 Implementing real-time convolution
Circular buffer Implementing real-time convolution

2 Problem Statement Implement the 4-th order FIR filter shown in Figure 3.2 on page 28. n = 4 x[] is the buffer for the input b[] is the coefficients vector the newest input will be multiplied by b[0] while the oldest will be multiplied by b[4] y is the output to the DAC sn denotes the value of the n-th input sample

3 Initially The system is relaxed, that is, the input buffer is filled with 0. x[0] = x[1] = … = x[4] = 0 We need an index idx to denote where is the latest input. Initially, idx = 0. that means x[0] will hold the current input at t = 0. Note that’s different from what we did in problem 2 where x[n] ALWAYS stores the latest input.

4 t = 0 idx = 0 x[] 1 2 3 4 s0 b[] b[0] b[1] b[2] b[3] b[4]
1 2 3 4 s0 b[] b[0] b[1] b[2] b[3] b[4] y = x[idx] * b[0] = x[0] * b[0]

5 t = 1 idx= 0+1=1 x[] 1 2 3 4 s0 s1 b[] b[0] b[1] b[2] b[3] b[4]
1 2 3 4 s0 s1 b[] b[0] b[1] b[2] b[3] b[4] y = x[idx] * b[0] + x[idx-1] * b[1] = x[1] * b[0] + x[0] * b[1]

6 t = 4 idx = 3+1 = 4 x[] 1 2 3 4 s0 s1 s2 s3 s4 b[] b[0] b[1] b[2] b[3]
1 2 3 4 s0 s1 s2 s3 s4 b[] b[0] b[1] b[2] b[3] b[4] y = x[i] * b[0] + x[i-1] * b[1] + x[i-2] * b[2] + x[i-3] * b[3] + x[i-4] * b[4] = x[4] * b[0] + x[3] * b[1] + x[2] * b[2] + x[1] * b[3] + x[0] * b[4]

7 t = 5 idx = 4 +1 = 5 = 0 x[] 1 2 3 4 s5 s1 s2 s3 s4 b[] b[0] b[1] b[2]
1 2 3 4 s5 s1 s2 s3 s4 b[] b[0] b[1] b[2] b[3] b[4] y = x[idx] * b[0] + x[idx-1] * b[1] + x[idx-2] * b[2] + x[idx-3] * b[3] + x[idx-4] * b[4] = x[0] * b[0] + x[-1] * b[1] + x[-2] * b[2] + x[-3] * b[3] + x[-4] * b[4] = x[0] * b[0] + x[4] * b[1] + x[3] * b[2] + x[2] * b[3] + x[1] * b[4]

8 Mod operator b[0] should be always multiplied by the latest data while b[4] times the oldest one. Also notice the negative indexes in the equation. Since it’s a “circular” buffer, x[-1] stands for x[4] But how to mathematically convert -1 to 4? Mod operation: (k + n) mod n = k mod n (3+5) mod 5 = 3 mod 5 =3 (-1+5) mod 5 = 4 mod 5 = 4 In C/C++, % is the mod operator

9 Solution #define N 4 int idx = 0; int i; float y;
Interrupt void McBSP_Rx_ISR() { idx = (idx+1) % (N+1); y = 0.0; for (i=0; i<=N;i++) y = y + x[(idx-i+N+1)%(N+1)] * b[i]; }


Download ppt "Implementing real-time convolution"

Similar presentations


Ads by Google