real-time audio filter examples with the ezdsp c5505_v2

28
Real-time audio filter examples with the eZdsp c5505 Tom Derks 17-02-2012, Eindhoven 1 | Page

Upload: tom-derks

Post on 23-Jan-2017

145 views

Category:

Documents


14 download

TRANSCRIPT

Page 1: Real-time audio filter examples with the ezDSP c5505_v2

Real-time audio filter examples with the eZdsp c5505

Tom Derks17-02-2012, Eindhoven

1 | P a g e

Page 2: Real-time audio filter examples with the ezDSP c5505_v2

1 Contents2 Abstract.........................................................................................................................................3

3 Introduction...................................................................................................................................3

4 Software........................................................................................................................................4

4.1 DAC/ADC (aic3204.c).............................................................................................................5

4.2 DMA (dma.c)..........................................................................................................................5

4.3 Filters (filters.c)......................................................................................................................5

4.4 GPIO (gpio.c)..........................................................................................................................5

4.5 Timer (rtc.c)...........................................................................................................................5

5 Filters.............................................................................................................................................6

5.1 FIR..........................................................................................................................................6

5.1.1 Low/High/Band-pass......................................................................................................6

5.1.2 Echo...............................................................................................................................7

5.2 IIR...........................................................................................................................................7

5.2.1 All-pass...........................................................................................................................7

5.2.2 Echo...............................................................................................................................7

5.3 Downsampling.......................................................................................................................8

6 Filter Design...................................................................................................................................9

6.1 FIR..........................................................................................................................................9

6.2 IIR...........................................................................................................................................9

7 Hardware input............................................................................................................................10

8 Real time FFT analysis..................................................................................................................11

9 Results.........................................................................................................................................12

9.1 Problems..............................................................................................................................13

9.2 Additions..............................................................................................................................13

10 Conclusion...................................................................................................................................15

11 Appendix A: Scripts......................................................................................................................16

12 Appendix B: Library setup............................................................................................................17

13 Appendix C: Documentation........................................................................................................18

2 | P a g e

Page 3: Real-time audio filter examples with the ezDSP c5505_v2

2 AbstractThis project implements real-time audio-filter examples on the eZdsp c5505 to help students understand the basics of signal processing. The aim of these examples is to help students get a better understanding of filtering, resampling and other basic operations in time- and frequency-domain by using preselected or their own signals as filter input. Three basic amplitude filters (low-,high-,band-pass) are implemented in the program. However any filter can be easily added by exporting a filter created in matlab. Furthermore special echo filters are implemented to show the basic concept of a filter. The echo filter has a very large delay for the filter coefficients to make the weighted sum of time shifted signal audible. A downsampling filter without prefiltering is used to show the effects of frequencies above the nyquist frequency in a downsampled signal. The filtered audio output can be heard through speakers/headphones and the real-time fft spectrum of the signal can be shown by connecting the output to a laptop running the Spectrum analyses software . The ability to hear the real-time processed signals together with the shown fft spectrum should give a good idea what happens to a signal’s frequency components in common signal processing operations implemented in the example filters.

3 IntroductionThe goal of the project is to implement real-time filters on the eZdsp to help students understand the basics of signal processing. Audio can be filtered in real-time with a range of different filter operations and the resulting signal can be heard with speakers or displayed on the laptop screen with a FFT analysis. By applying the filters in real-time a better understanding of the filter concepts can be achieved.

The ezdsp c5505 module of Texas Instruments has been used for the filter operations(Figure 1). It is a standalone signal processing module with analog stereo in and out. The heart of the module is de c5505 signal processing chip, which is a 16-bit processor with 200MMips performance. It has special instructions to speed up common signal processing operations and a hardware accelerator for Radix FFT computation. Digital io is available on the expansion connector including some common protocols like spi, uart and i2c.

3 | P a g e

Figure 1: eZdsp c5505

Page 4: Real-time audio filter examples with the ezDSP c5505_v2

The module is integrated for protection in a custom box also used for the Rock Your Baby OO1.1 project (Figure 2). The usb connector, audio in and outputs and the expansion pins are available as in/output on the custom box. The box has two serial connectors to reach the expansion connector pins. One of the serial connectors can only be used for output due to protective circuitry. The special connector is connected directly to the expansion pins with only a resistor for load protection. There are two input switches available to switch between single plug stereo in/output or double mono in/output.

4 | P a g e

Figure 2: eZdsp integrated in a protective casing

Page 5: Real-time audio filter examples with the ezDSP c5505_v2

4 SoftwareCode Composer studio 4 is used to program the ezdsp module. It is a development platform based on the open-source eclipse IDE. Software can be coded in C and compiled to be run on the ezdsp. It also has a fully functional debugging environment. In debug mode it is possible to step through live code running on the eZdsp and all variables and memory spaces can be inspected.

To have access to a package of highly optimized signal processing functions the dsp library can be included into the project. Furthermore the csl libraries are used to make the software more high-level and easier to understand. Function calls can be used to initialize hardware opposed to writing values to registers. To make use of both libraries the include paths and library paths need to be setup in the Code composer project. In the appendix are screenshots (Figure 10,Figure 11) displaying the configuration settings needed to make use of the dsplib and csl lib functions.

When the program is loaded with code composer the code is stored in RAM memory which loses its contents on power loss. It is also possible to put a program into the flash memory of the eZdsp. After the chip gets power from the usb connector the program stored in the flash memory is loaded and started. This eliminates the need of any software after the program is loaded on the eZdsp.

The program has been build in separate sections to divide functionality in different files to increase readability (Figure 3). The sound chip module configures the ADC en DAC to read and write data from the analog audio channels. The DMA module transfers the digital samples to memory ready for filter processing. The GPIO module reads external input pins and the timer module toggles a Boolean on a regular interval. The main program selects and enables a filter based on the GPIO inputs and the timer state. The subsections of this chapter will go into more detail of all the software components of the program.

The eZdsp has the option to put programs into flash memory to keep programs stored permanently. The program automatically starts when power is applied to the stick. A program can be programmed into flash memory with the eZdsp Programming Tool. First the hex55 executable converts file created by code composer to a binary file. A special program from Texas Instruments (programmer_USBKey.out) is loaded into the eZdsp. This program loads selects the binary to be stored into the flash memory.

5 | P a g e

Page 6: Real-time audio filter examples with the ezDSP c5505_v2

Figure 3: Software block diagram

4.1 DAC/ADC (aic3204.c)The aic3204 module configures the DAC and ADC of the audio codec chip on the ezdsp. The ezdsp has one stereo analog input and one analog stereo output. The ADC is configured to sample the signal on 44 kHz with 16-bit samples. The DAC has the same converter frequency with 16-bit digital samples.

4.2 DMA (dma.c)Direct memory access (DMA) is a feature that allows hardware subsystems to access memory independently of the CPU. The DMA module is used to read input data from the ADC en write processed data back to the DAC. A DMA transfer copies a buffer to another memory space without the use of the cpu. Therefor no cpu cycles are wasted to read and write data from the soundcard. Because stereo sound is processed 4 DMA channels are needed. Two input and two output channels. A ping-pong buffer is used to process audio in real-time. One channel copies data from the ADC to the ping input buffer. Simultaneously another channel copies previously filtered data in the ping output buffer to the DAC. While the transfers are running the main program has time to process the input data in the pong buffer to the pong output buffer. All these simultaneous processes can be seen by the green dashed lines in Figure 3. When the transfers complete the same process is repeated with the ping and pong buffers swapped, as showed by the orange dashed lines

4.3 Filters (filters.c)In the filters module several filter functions are defined to process audio data from the input to output buffer. All filter functions copy the data from the input buffer to the output buffer while applying a filter algorithm. All of the filters functions can use the highly optimized dsplib functions but can be easily modified to use filter functions written in C.

4.4 GPIO (gpio.c)The gpio module configures the I/O ports to read out the digital input switches. Based on the value of the inputs, filters are selected and activated. This allows different filters to be dynamically selected when the program runs on the eZdsp. In total 7 input ports and 1 output port are used. Since there is no voltage pin the output port is set high for a +3.3V reference. The input ports are used for filter selection (4bits), left channel filter activation, right channel filter activation and toggling of the timer feature.

6 | P a g e

Page 7: Real-time audio filter examples with the ezDSP c5505_v2

4.5 Timer (rtc.c)The timer module toggles the filter activation automatically on 5 second time intervals. A real time clock (rtc) is configured to give an interrupt call every second. Every interrupt call a counter is increased. When the count reaches 5 the filter activation is toggled and the counter is reset to zero. Filtering of a channel is only toggled if filtering of that channel is also activated.

7 | P a g e

Page 8: Real-time audio filter examples with the ezDSP c5505_v2

5 FiltersThis chapter covers the demo filters which can be run real-time on the Ezdsp. It is split into three filter categories, FIR,IIR and downsampling. Each category contains subsections for the filter demos implemented in the dsp.

The functions supplied by the dsplib libary are used for standard FIR/IIR filter operations. The filter functions in the dsplib library are highly optimized assembly functions supplied by Texas Instruments. The filters use a hardware circular buffer to efficiently store history samples needed to do the filter calculations. For non-standard filter operations custom filter functions have been programmed in C. Efficient circular buffers only possible when programming the whole function in assembly. Programming a FIR filter function in assembly to use circular buffers is complex and the function is not easy to understand and modify. Therefor another system is used to store history samples in a different way.

Memory space before the current samples is reserved for history samples (Error: Reference source not found). The samples of the previous buffer are copied to the history samples memory space. This allows negative indexes to be used on the buffer with a maximum range of the buffer size. It has the downside of always copying the whole previous buffer into history. However if all these history samples are actually needed it is as efficient as using a circular buffer. Another downside is the maximum history of one buffer, but with a buffer size of 1024 this isn’t an impractical limitation since it allows filters with a maximum order of this buffer size. With the small overhead of always copying the buffer once very efficient filters routines can be programmed in C.

5.1 FIRThe FIR filter function (direct-form) in the dsplib library can be used to implement a standard filter. To demonstrate what is actually happening in the filter and for easy adjustment of the filter algorithm, a custom FIR filter function (direct-form) is programmed in C. To make an efficient FIR filter algorithm the special instructions available in the eZdsp have to be used. The MACM instruction is one of these special instructions. The function is a saturating multiply with addition executed in only one cycle. This operation is automatically detected by the compiler when written in a specific form. The resulting function can be seen in A. All of the used FIR filters can be changed to use the standard dsplib function or the custom filter.

5.1.1 Low/High/Band-passTo show the effect of low/high/band pass filters on audio three example filters have been designed. In the pass band the attenuation is 0dB, while it is 80db in the stop band for all three filters. The filter specifications are shown in Table 2. The pass and stop frequencies in the low/high pass filters are chosen to have significant signal power in both their pass bands, so the difference in high and low frequencies can be heard. The pass/stop frequencies of the band-pass filter are chosen to have significant signal power in the middle of the spectrum for the same reason.

8 | P a g e

Table 1: Memory layout of pingpong buffer

Ping_history Ping Pong_history Pong

Page 9: Real-time audio filter examples with the ezDSP c5505_v2

Filter Fstop1 Fpass1 Fpass2 Fstop2 Filter orderLow-pass 5 kHz 4 kHz - - 112High-pass 4 kHz 5 kHz - - 122Band-pass 3 kHz 4 kHz 8 kHz 9 kHz 122Table 2: Filter specification

5.1.2 EchoAnother practical example for a FIR filter is to generate an audio echo effect. To get an audible echo effect, coefficients at around 10ms delay time are needed. The standard dsplib FIR filter function is not suitable for this use since the number of coefficients of the filter would get too high. The number of delays per filter coefficient is fixed to one so a filter of 440 coefficient would be needed to get a 10ms delay. Therefor a custom fir filter function is written in C to increase the delay time between filter coefficients to 512 samples. A good echo effect is accomplished by using the filter displayed in Figure 4. The filter has two delay branches to create the echo effect. Since the samples in the delays are uncorrelated for high frequencies, the delay coefficients have been chosen to total 1. This prevents buffer overflow on the 16-bit fixed integer computation in the dsp.

Figure 4: FIR echo filter

5.2 IIRIIR filters are more difficult to implement in a dsp because stability is not guaranteed and overflow can occur due to the feedback. Complex IIR filters are usually made out of biquads sections. These are building blocks with 2 zeros and 2 poles which can be cascaded to get every possible filter. The dsplib library has an IIR filter function which uses an array with biquad values as the filter coefficients. A direct-form I IIR filter function is made to demonstrate a simple filter. The function can’t be used for large order filters due to overflow of the 16-bit fixed integer variables but can be used for demonstrating the calculations done for a simple filter.

5.2.1 All-passAll pass filters can be used to change the phase on different frequencies. However the human ear is very limited to hearing phase shifts on a signal. Even with very rigorous non-linear phase delays shift the filtering had no audible effect.

5.2.2 EchoThe echo effect can also be accomplished with an IIR filter. When more echo coefficients are wanted and those coefficients may decay by a fixed ratio, the same filter can be accomplished with a lower order filter. An example echo filter is shown in Figure 5. The number of delays per sample is adjusted to 512 delays just like in the FIR echo filter. To prevent buffer overflows in the output

9 | P a g e

Page 10: Real-time audio filter examples with the ezDSP c5505_v2

calculation the filter coefficients have been chosen to never amplify the output signal. The amplitude of the transfer function is shown in formula 1, the maximum at theta is 0.5pi is exactly one.

|H (e iθ )|= 12+cos2θ−sin2θ

(formula 1)

Figure 5: IIR echo filter

5.3 DownsamplingAnother good signal processing example is showing the nyquist sample theorem by downsampling a signal without pre-filtering the high frequencies above the nyquist frequency. Frequencies above the nyquist frequency will move into the lower frequency band. It is not possible to change the sampling frequency on the eZdsp while audio is playing. Therefor the sample frequency is not modified, but digital filter operations are used to mimic the effect of a lower sampling frequency (Figure 6).

Pre-filtering frequencies above the nyquist frequency can be turned on or off to show the results in both situations. The sample rate of the signal is reduced by throwing away samples. To get back to the original sample rate the firinterp function is used which is available in the dsplib library. The function inserts zeros in between samples and uses a FIR filter to interpolate the inserted samples. A 128th order low pass filter has been used as an anti-alias/interpolation filter. It has it’s cut off frequency at 90% of the nyquist frequency. When the anti-alias filter is on, it can be easily seen that the whole downsample filter can be simplified to just this filter. This is not simplified to have a division in the real downsample step (firdec block), and the operations needed to get back to the original sample frequency.

Since the program processes audio blocks of 1024 samples only downsample factors with a power of 2 can be easily accomplished. The downsample filter function has interpolating filters to downsampling by a factor of 2, 4, 8 and 16.

Figure 6: The filter methods applied to mimic downsample effect

10 | P a g e

Page 11: Real-time audio filter examples with the ezDSP c5505_v2

11 | P a g e

Page 12: Real-time audio filter examples with the ezDSP c5505_v2

6 Filter DesignMatlab can be used to design the filter coefficients for the FIR and IIR filters functions. With the Filter Design and Analysis tool (FDAtool) coefficients can be calculated by entering the design specifications for the desired filter. FDAtool defaults to calculating the coefficients as double-precision floating point numbers. The eZdsp stick only has 16-bit fixed point direct hardware support for multiply and additions. Therefor filter coefficients have to be converted to 16-bit fixed point to efficiently do the filter calculations. FDAtool has support to output the coefficients as fixed integers. It does not just round the filter coefficients but tries to get a close approximation to the wanted transfer function with limited coefficient accuracy.

6.1 FIRWhen the coefficients are exported to a matlab array, they still need to be converted to a format usable in the eZdsp. The matlab script fir_export converts the matlab array of quantized doubles to 16-bit integer values in the Q1.15 format and prints them as a string to the file fir_filter.txt (Appendix A).The content of the fir_filter.txt file can be used directly as a filter definition in the filter source code.

6.2 IIRThe coefficient order for the biquad array used in the dsplib function is different than the order in matlab. Therefor a matlab script has been written to put the biquad array in the right format. The matlab script “iir_export” converts the biquad array of quantized doubles to 16-bit integer values, puts the integers in the correct order and print them as a string to the file “iir_filter.txt” (Appendix A).Since coefficients of the filter can be larger than one, the number of bits to be used for the integer part is flexible. The amount of extra bits the result needs to be shift to the left is displayed in the matlab console.

12 | P a g e

Page 13: Real-time audio filter examples with the ezDSP c5505_v2

7 Hardware inputTo select multiple filters without reprogramming the eZdsp some kind of input mechanism has to be used. The box has two DB25 serial ports to interface with the eZdsp stick. The “default” connector can only be used as output since all pins are driven by a Schmitt-trigger which outputs voltages at 5V TTL level. The “Special” connector has the pins directly connected to the eZdsp with a resistor as load protection and a parallel zener-diode for over-voltage protection. This allows pin usage for digital input/ouput and standard communication protocols like uart and SPI.

The input to the eZdsp is done with 7 hardware switches. There are in total 8 General IO pins available on the “special” connector but since there is no power pin one pin is needed as a supply voltage (Table 3). An individual switch is used to toggle filtering for the left and right audio channel. One switch is used to enable time based toggling of the filter. The filter is only enabled by the timer if the channel filter is also activated. The four remaining input bits are used for filter selection, the left switch being the most significant bit. This allows a maximum of 16 different filters to be selected. In Figure 7 the resulting hardware is shown which is directly attached to the special connector.

PIN #

13

12

11

10

9 8 7 6 5 4 3 2 1

DSP IO GPIO_16

GPIO_15

GPIO_14

GPIO_13

GPIO_12

GPIO_11

GPIO_10

PIN # 25

24

23

22

21

20

19

18

17

16

15

14

DSP IO

GND

I2C_

SCL

I2C_

SDA

UART

_TX

UART

_RX

UART

_CT

UART

_RT

SPI_RX

SPI_DX

SPI_CLK

SPI_CS1

GPIO_17

Table 3: Pin diagram of the hardware input switches

13 | P a g e

INPUTFilter[3] GPIO10Filter[2] GPIO11Filter[1] GPIO12Filter[0] GPIO13Filter_left GPIO16Filter_right GPIO14Filter_timer GPIO15OUTPUTHigh(3.3V) GPIO17

Page 14: Real-time audio filter examples with the ezDSP c5505_v2

Figure 7: Hardware input switches (schematic view on the right)

14 | P a g e

Filter[3] Filter[2] Filter[1] Filter[0]Left Timer Right

Page 15: Real-time audio filter examples with the ezDSP c5505_v2

8 Real time FFT analysisA real time fft analysis is a big addition compared to only hearing the audio signal. It can visually show the frequency components which gives a better idea of the composition of a signal. Furthermore it allows a direct real-time comparison for the student between the heard audio signal and the frequency components present in the audio signal. This can give good insight in audio signals and what exactly happens to them with specific filter operations.

The program “Spectrum analyses v2.9beta” of W.A. Steer can display a real-time fft analysis for the analog input of a laptop. It samples an audio stream in 16-bit 44.1kHz mono (Left Channel) and uses a 4096-points fast fourier transform to yield the spectral analysis in real time (Figure 8). A Hanning window is used to reduce leakage. The program displays the spectral energy of each frequency with a resolution of approximately 11Hz. More specifications and features can be found on the creator’s site (http://www.techmind.org/audio/specanaly.html)

Speakers and the analog laptop input can be connected at the same time by using a splitter at the output of the EZDSP. The spectrum analyze program is a standalone executable with requires no installation. When the program is started only the analog audio input has to be selected. The vertical and horizontal axis of the fft plot can be scaled to give a clear fft view; the optimal settings depend on the size of the program window.

Figure 8: Screenshot of the spectrum analysis interface

15 | P a g e

Page 16: Real-time audio filter examples with the ezDSP c5505_v2

16 | P a g e

Page 17: Real-time audio filter examples with the ezDSP c5505_v2

9 ResultsA standalone program is uploaded into the eZdsp which automatically starts up after power is applied by the usb connector. Eleven filters can be chosen by selecting a filter code using the input switches (Table 4). The downsample filters are shifted down one filter id to allow easy switching between the variants with and without prefiltering with the least significant filter switch. A good test signal for all the different filters is an audio sweep over the whole 20-22kHz frequency range. By turning the filter on for only one audio channel it is easily heard which tones are passed or stopped by the filters. When using the downsample filters the nyquist theorem can be proven, since it’s easily heard the tones above the nyquist frequency are shifted into the lower frequency section. It is recommended to use the additional visual fft interface for complex audio signals like music. It gives an extra visible aid to get a better understanding of the frequency components of the filtered results (Figure 9).

Filter Filter Description0 Low-pass FIR filter1 High-pass FIR filter2 Band-pass FIR filter3 Echo FIR filter4 Echo IIR filter5 NO FILTER6 Downsample factor 2 (prefiltering)7 Downsample factor 2 (no prefiltering)8 Downsample factor 4 (prefiltering)9 Downsample factor 4 (no prefiltering)10 Downsample factor 8 (prefiltering)11 Downsample factor 8 (no prefiltering)Table 4: Implemented filters with their filter id

17 | P a g e

Figure 9: Real time fft of music signal (left original, right bandpass-filtered)

Page 18: Real-time audio filter examples with the ezDSP c5505_v2

9.1 ProblemsDuring the project there were two software problems which consumed a lot of time. This was primarily caused by the lack of efficient debugging possibilities available for those problems. The first problem was caused by synchronization issues with the different DMA channels which copy the audio buffer data. Even though the different DMA transfers copied the same buffer sizes they did not always finish in the same order as they were started. Therefor the interrupt triggered when a DMA transfer was finished had to be handled individually opposed to only handling the interrupt of the transfer who was started last. This problem was hard to debug since it is a problem which only occurred occasionally when running the code in real-time.

The second problem was getting standalone mode working. When programming the eZdsp with the Code Composer Suite it resets the eZdsp hardware before running the program. When the module is started in standalone mode these initializations are not performed. Since there are no debug capabilities in standalone mode it was not possible to track down the initialization problem by stepping through the code. The only solution was to integrate the whole project into a reference project which did work in standalone mode. The project uses an assembly file (vector.asm) which contains a function run before the program which resets different components of the ezdsp.

Another easy to resolve problem had to do with the dsplib filter functions. All elements of the history buffer to be used in the dsplib functions should be initialized to zero. Especially initialization of the first element is important since it contains the index of the oldest entry in the history buffer. When this value is not initialized to zero, filter results may be unexpected since history samples will not be stored correctly depending on the random value of the memory location.

In the current program there is one unresolved problem with reading the state of the input switches. Most of the times the GPIO12 and GPIO13 input pins are always read as low, reducing the bits for the filter selection to two. The problem is not in the hardware switches, since the digital input is also low with a 3.3V voltage directly applied to the input pin. In some rare occasions the switches do all work, which makes it very likely to be an initialization problem. The switch to toggle the timer function is broken due to a hardware problem. Since the broken link is glued between two components it is not possible to fix this without making a completely new hardware module. Since the eZdsp has some digital communication protocols available, it might be an alternative idea to use a display to reduce the inputs needed for filter selection. This idea is mentioned in the addition section.

9.2 AdditionsThe overhead to copy the input buffer data to the history can be eliminated by using a DMA transfer for the copy process. This optimization can’t be used for the output buffers since the output buffer is only available after doing the filter calculations. The eZdsp has four DMA controllers total with four channels each. Currently only 4 channels are used which leaves 3 controllers available. Only 2 channels are needed for this optimization.

To have a better interface on the eZdsp than digital input switches a display could be used. This adds the big advantage of visible feedback to the ezdsp. Information of the current applied filter can be shown and two simple press switches can be used to traverse through a very large number of different filters. A 32 character LCD screen (http://www.sparkfun.com/products/9393) could be

18 | P a g e

Page 19: Real-time audio filter examples with the ezDSP c5505_v2

used as such a display. The display supports serial communication which makes it relatively easy to communicate with to show text information.

Additional filter operations like a LMS algorithm could be implemented. The dsplib library already has a build in LMS algorithm. Using two mono inputs an adaptive filter can be made to show the resulting effect of filtering a noisy signal with a reference signal to filter a desired signal.

19 | P a g e

Page 20: Real-time audio filter examples with the ezDSP c5505_v2

10 ConclusionThe goal of the project was to implement real-time filters on the eZdsp to help students understand the basics of signal processing operations. Students can input any stereo audio signal to be filtered in real-time. The filtered audio output can be heard through speakers/headphones and the real-time fft spectrum of the signal can be shown by connecting the output to a laptop running the Spectrum analyses software. There are three frequency amplitude filters in the program(low-pass,high-pass,band-pass) but any FIR/IIR filter can be easily added by using the matlab export scripts. Echo filters are included to show the basic concept of a FIR/IIR filter: adding the same signal to the original with a delay and a multiply factor. A downsampling filter without prefiltering shows the effects of frequencies above the nyquist frequency in the downsampled signal. These filters combined should give a good idea what happens to a signal’s frequency components in common signal processing operations.

20 | P a g e

Page 21: Real-time audio filter examples with the ezDSP c5505_v2

11 Appendix A: ScriptsCustom fir filter function

MATLAB FIR filter export

MATLAB IIR biquad filter export

21 | P a g e

/**  * Own implementation of the fir filter function  * Assumes history values to be available in memory before x  * @param x array of input samples  * @param h filter coefficients  * @param y array of output samples  * @param hn number of filter coefficients  */void fir_filter(Int16*x, Int16 onchip *h ,Int16 *y, Int16 hn){ Int16 j,k; Int32 y_temp; //Apply filter to each sample for (j = 0; j < LENGTH ; j++){ y_temp=0; for (k = 0; k < hn ; k++){ //compiler optimises this to MACM instruction //(saturating multiply+add in 1 cycle) y_temp+= (Int32)h[k]*(Int16)x[j-k]; } //convert 32bit value back to 16bit. y[j]=(Int16) (y_temp >> 15); }}

function fir_export(filter) h = fopen('fir_filter.txt','w'); filter_16b=fi(filter,1,'FractionLength',15) filter_16b=filter_16b.int fprintf(h,'fir_filter = {%i',filter_16b(1)); for k=2:length(filter_16b) fprintf(h,',%i',filter_16b(k)); end fprintf(h,'};'); fclose(h);end

function iir_export(b,a) h = fopen('iir_filter.txt','w'); %create biquad filter biquad=tf2sos(b,a); %conver to fixed integer values biquad_16b=fi(biquad); bits=(biquad_16b.word-biquad_16b.fract-1); biquad_16b=biquad_16b.int; %write in format for standard ezdsp function fprintf(h,'filter = {'); for k=1:size(biquad_16b,1) fprintf(h,'%i ,%i, %i, %i, %i',biquad_16b(k,5),biquad_16b(k,2), biquad_16b(k,6),biquad_16b(k,3),biquad_16b(k,1)); if(k~=size(biquad_16b,1)) fprintf(h,',\n'); end end fprintf(h,'};'); fclose(h); %show scale factor printf('Left shift result by %i for scale factor %i',bits,power(2,bits));end

Page 22: Real-time audio filter examples with the ezDSP c5505_v2

12 Appendix B: Library setup

Figure 10: Code composer studio, include path configuration

Figure 11: Code composer studio, library configuration

22 | P a g e

Page 23: Real-time audio filter examples with the ezDSP c5505_v2

13 Appendix C: Documentation

Topic Manual

Radix Hardware FFT sprabb6a.pdfDSPLIB function manual spru422j.pdfReal time clock RTC.pdfDMA controllers DMA.pdfDAC/ADC AUDIO.pdfCSL library CSL.pdfGeneral input/output GPIO.pdf

23 | P a g e