EE 345S Real-Time Digital Signal Processing Lab Spring 2009 Lab #3.2 & 3.3 Digital Filters Akshaya Srivatsa
Outline More About Circular Buffers C Code v/s Assembly How Function Makes Call Using Assembly in C Linear Assembly Code How To Read Assembly Files IIR Filters DF-I and Implementation IIR Filter DF-II and Implementation Task List for Lab #3.2 Task List for Lab #3.3
More About Circular Buffers 8 registers: A4-A7 and B4-B7 can be used as circular buffers. Number of words in the buffer = Block Size 2 bits BK0 and BK1 (each 5 bit fields) of AMR (Address Mode register) BUF_LEN = 2NBlock+1 where BUF_LEN is total no. of bytes.
More About Circular Buffers Buffer must be aligned to byte boundaries i.e. multiples of block size Implementation: #define Nblock 6 #define BUF_LEN_WORD 1<<(Nbloack-1) # define BUF_LEN 1<<(Nblock+1) #pragma DATA_ALIGN(x, BUF_LEN) x[] should be global. This prevents carries and borrows in address calculation between blocks to access data.
C Code v/s Assembly We use C coding over Assembly for the following reasons Rapid Software development Applications can be easily ported to DSP’s Assembly Code is tough to write because Multiple levels of pipelining. Multiple Execution Units Different instructions take different execution times
How Function Makes Call In function call, first argument is the left most one. Registers A0-A9 and B0-B9 are saved on the stack. The first 10 arguments are saved in registers A and B. Other ones are saved on stack. The caller branches to the function. Returned values are stored in B3. Upon returning, the stack is popped and loaded back into the register.
Using Assembly in C Every variable in C is prefixed with an underscore in assembly. (x in C is _x in assembly) B3 (Return value) and A3 (Structure Register) must not be used freely. Objects or functions declared in assembly that is called by C needs to be declared with .def or .global. Must start with .cproc and end with .endproc to mark the start and end points for optimization.
Linear Assembly Code Has the extension .sa No information about parallel instructions, latencies or register usage. An assembly optimizer- Find instructions that can operate in parallel Assign register usage Handle pipeline latencies Optimize execution time
How To Read Assembly Files _<tag> is entry point .cproc are the arguments for the function .reg are the registers declared that are used. .return is the return value stored in B3. .endproc is end of procedure
IIR Filters IIR Filters can be represented as Its time domain equivalent is This is called “Direct Form” since co-efficients directly appear in the difference equation. Filter requires N+M+1 storage elements for all the x[n] and y[n] values.
IIR Filters DF-I Implementation
IIR Filters DF-I Implementation Compute v[n] Compute y[n] Update state variables
IIR Filters DF-I Implementation The FDA tool on Matlab breaks the IIR filter into biquads or IIR filters with order 2. Same co-efficients are used for DF-I and DF-II The co-efficients are in this order [b1 b2 b3 … bN (a1=1) a2 a3 … aN] For M biquads, you get M+1 scaling factors. Typically scaleM+1 = 1 Implementation is scale1 – biquad1 – scale2 – biquad2 - .. scaleM – biquadM – scaleM+1
IIR Filters DF-II Implementation Let us rewrite the IIR filter difference equation:
IIR Filters DF-II Implementation Step 1: Step 2:
Common Mistakes Each biquad is an IIR filter. If you working with biquads, treat each one independently. Each biquad has its own state variabled. DO NOT MIX THE STATE VARIABLES OF BIQUADS. Always first evaluate output for a biquad before you do any operations on the next biquad.
Task List Tasks for Lab 3.1 are FIR Filter Profiling IIR Filter Design IIR DF-I Implementation and profiling Important Points DO NOT OVERWRITE older C files. The task list can be found at the following link http://users.ece.utexas.edu/~bevans/courses/realtime/lectures/laboratory/c6713/lab3/Lab_3_Task_List.doc
Task List Tasks for Lab 3.1 are IIF Filter DF-II Implementation and Profiling LabVIEW VI for Magnitude & Phase Response Answer all Questions Important Points DO NOT OVERWRITE DF-I code Create a new labmain.c The task list can be found at the following link http://users.ece.utexas.edu/~bevans/courses/realtime/lectures/laboratory/c6713/lab3/Lab_3_Task_List.doc