1 / 9

Circular buffer

Circular buffer. Implementing real-time convolution. 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

venus
Download Presentation

Circular buffer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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[] b[] y = x[idx] * b[0] = x[0] * b[0]

  5. t = 1 idx= 0+1=1 x[] b[] 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[] b[] 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[] b[] 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]; } }

More Related