ECE 3551 MICROCOMPUTER SYSTEMS 1 Lab 6—Learn to process audio data OBJECTIVE: Learn how to process audio data in ADSP-BF533 EZ-Kit Lite. Learn how to implement digital iir filer in DSP. Learn how to control the audio input/output. Create the Project 1. Before power on the board, make sure that switch SW9 pin1,pin2, pin3, pin4, pin5 and pin6 are turned on., which means all pins in SW9 must be on. 2. Copy the project in Lab #6 to “u:\ece3551\labs\lab6” Modify the Project In this lab, you need to learn how to filter audio data and compare the original audio and the filtered audio. In this Lab exercise only input 1 and output 1 will be used. 1. Duplicating the input & Controlling the output: Read the data from the input 1 and save it’s copy: one is the original data and another will be the filtered data. PF8 is used to control which data is sent to output 1: In the beginning, LED4 is off, and the original data is send to output1. So what is heard is the original audio. When PF8 is pressed: The LED4 should turn on, and The filtered data is send to output. What is heard, therefore is filtered audio. By pushing PF8 again, the LED4 should turn off, and the original data is send to output1; what is heard is the original audio again. Designing IIR Filters: Matlab exports IIR filters in a direct-form II sections each being of second order. The general relationship of output and input given in Z transform is of the form: K K b0k b1k z 1 b2k z 2 Y z H z G H k z G k 1 X z a 2k z 2 k 1 k 1 1 a1 z Note that z-1 denotes unit delay (D), Y(z) is z-transform of the output, X(z) is z-transform of the input. The block diagram realization of a filter with K=2 sections is given below: d1(n) d2(n) x(n) y(n) D ↔ z-1 a11 d1(n-1) D ↔ z-1 b11 a12 D ↔ z-1 a21 d2(n-1) b12 D ↔ z-1 b21 d1(n-2) a22 b22 d2(n-2) Example of a fourth-order IIR filter realized by cascading of two biquads. ADI VisualDSP++ Blackfin library provides several functions that help implementation of the iir filters. The following is taken from “VisualDSP++ 4.5 C/C++ Compiler and Library Manual for Blackfin Processors”, page 4-126. iir - infinite impulse response filter2 Synopsis #include <filter.h> void iir_fr16(const fract16 input[], fract16 output[], int length, iir_state_fr16 *filter_state); The function uses the following structure to maintain the state of the filter. typedef struct { fract16 *c; /* coefficients */ fract16 *d; /* start of delay line */ int k; /* number of biquad stages */ } iir_state_fr16; Description The iir_fr16 function implements a biquad, transposed direct form II, infinite impulse response (IIR) filter. It generates the filtered response of the input data input and stores the result in the output vector output. The number of input samples and the length of the output vector are specified by the argument length. The function maintains the filter state in the structured variable filter_state, which must be declared and initialized before calling the function. The macro iir_init, defined in the filter.h header file, is available to initialize the structure and is defined as: #define iir_init(state, coeffs, delay, stages) \ (state).c = (coeffs); (state).d = (delay); \ \ (state).k = (stages) The characteristics of the filter are dependent upon filter coefficients and the number of stages. Each stage has five coefficients which must be stored in the order A2, A1, B2, B1, and B0. The value of A0 is implied to be 1.0 and A1 and A2 should be scaled accordingly. This requires that the value of the A0 coefficient be greater than both A1 and A2 for all the stages. A pointer to the coefficients should be stored in filter_state->c, and filter_state->k should be set to the number of stages. Each filter should have its own delay line which is a vector of type fract16 and whose length is equal to twice the number of stages. The vector should be initially cleared to zero and should not otherwise be modified by the user program. The structure member filter_state->d should be set to the start of the delay line. Algorithm B0 B1 z 1 B2 z 2 H z 1 A1 z 1 A2 z 2 Where d m xm A2 d m 2 A1d m 1 ym B2 d m 2 B1d m 1 B0 d m And m={0,1,2,…,length-1} H(z) above is one bi-quad stage of the filter. Note that A coefficients are i inverted in sign compared to ai coefficients provided by MATLAB. Also the coefficients are in fractional format frac16. Use MATLAB to design 2 types of filters: 1. Low-Pass IIR Filter with following properties: Response Type = Lowpass Design Method = IIR Chebyshev Type II Filter Order (i.e., Number of Filter Coefficients) = 10 Sampling Frequencey Fs = 48000 Hz Cutoff Frequency Fc = 5000 Hz Sidelobe attenuation = 80 This Figure is the default configuration output of the MATLAB fdatool. Exporting the result into a C file should give you this result. Low-Pass Filter /* * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool * * Generated by MATLAB(R) 6.5.1 and the Signal Processing Toolbox 6.1. * * Generated on: 23-Oct-2006 11:01:25 * */ /* * Discrete-Time IIR Filter (real) * ------------------------------* Filter Structure : Direct-Form II, Second-Order Sections * Filter Order : 10 * Stable : Yes * Linear Phase : No */ /* General type conversion for MATLAB generated C-code */ #include "tmwtypes.h" /* * Expected path to tmwtypes.h * C:\MATLAB6p5p1\extern\include\tmwtypes.h */ /* * Warning - Filter coefficients were truncated to fit specified data type. * The resulting response may not match generated theoretical response. * Use the Filter Design & Analysis Tool to design accurate fixed-point * filter coefficients. */ #define MWSPT_NSEC 6 const int NL[MWSPT_NSEC] = { 1,3,3,3,3,3 }; const int16_T NUM[MWSPT_NSEC][3] = { { 10, 0, 0 }, { 32767, 32767, 32767 }, { 32767, -18534, 32767 }, { 32767, -32768, 32767 }, { 32767, -32768, 32767 }, { 32767, -32768, 32767 } }; const int DL[MWSPT_NSEC] = { 1,3,3,3,3,3 }; const int16_T DEN[MWSPT_NSEC][3] = { { 32767, 0, 0 }, { 32767, -32768, 10247 }, { 32767, -32768, 13356 }, { 32767, -32768, 18274 }, { 32767, -32768, 23799 }, { 32767, -32768, 29614 } }; 2. High-Pass FIR Filter with following properties: Response Type = Highpass Design Method = IIR - Chebyshev Type II Filter Order (i.e., Number of Filter Coefficients) = 10 Sampling Frequencey Fs = 48000 Hz Cutoff Frequency Fc = 1500 Hz Sidelobe attenuation = 80 Export Filter coefficients: The MATLAB should generate the following Filter Coefficients: /* * Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool * * Generated by MATLAB(R) 6.5.1 and the Signal Processing Toolbox 6.1. * * Generated on: 23-Oct-2006 11:02:29 * */ /* * Discrete-Time IIR Filter (real) * ------------------------------* Filter Structure : Direct-Form II, Second-Order Sections * Filter Order : 10 * Stable : Yes * Linear Phase : No */ /* General type conversion for MATLAB generated C-code */ #include "tmwtypes.h" /* * Expected path to tmwtypes.h * C:\MATLAB6p5p1\extern\include\tmwtypes.h */ /* * Warning - Filter coefficients were truncated to fit specified data type. * The resulting response may not match generated theoretical response. * Use the Filter Design & Analysis Tool to design accurate fixed-point * filter coefficients. */ #define MWSPT_NSEC 6 const int NL[MWSPT_NSEC] = { 1,3,3,3,3,3 }; const int16_T NUM[MWSPT_NSEC][3] = { { 15837, 0, 0 }, { 32767, -32768, 32767 }, { 32767, -32768, 32767 }, { 32767, -32768, 32767 }, { 32767, -32768, 32767 }, { 32767, -32768, 32767 } }; const int DL[MWSPT_NSEC] = { 1,3,3,3,3,3 }; const int16_T DEN[MWSPT_NSEC][3] = { }; { 32767, 0, 0 }, { 32767, -32768, 20827 }, { 32767, -32768, 21816 }, { 32767, -32768, 23788 }, { 32767, -32768, 26720 }, { 32767, -32768, 30554 } Useful hints Pay attention to converting int_16 (integer 16 bit signed format) into frac16 bit format. This can be accomplished by dividing the int_16 value by 32767 (MAX_INT) and assigining it to frac16 data type. Note also the sign of the MATLAB coeffs vs iir_fr16. Lab report is needed for this lab.