DSP Implementation Using The TMS320C6711 Demo

advertisement

Slide 1

DSP Implementation Using The

TMS320C6711 Demo

Texas

Instruments

Slide 2

Learning Objectives

Why process signals digitally?

Definition of a real-time application.

Why use D igital S ignal P rocessing processors?

What are the typical DSP algorithms?

Parameters to consider when choosing a

DSP processor.

Slide 3

Why go digital?

Digital signal processing techniques are now so powerful that sometimes it is extremely difficult, if not impossible, for analogue signal processing to achieve similar performance.

Examples:

 FIR filter with linear phase.

 Adaptive filters.

Slide 4

Why go digital?

Analogue signal processing is achieved by using analogue components such as:

 Resistors.

 Capacitors.

 Inductors.

The inherent tolerances associated with these components, temperature, voltage changes and mechanical vibrations can dramatically affect the effectiveness of the analogue circuitry.

Slide 5

Why go digital?

With DSP it is easy to:

 Change applications.

 Correct applications.

 Update applications.

Additionally DSP reduces:

 Noise susceptibility.

 Chip count.

 Development time.

 Cost.

 Power consumption.

Slide 6

Why NOT go digital?

 High frequency signals cannot be processed digitally because of two reasons:

 A nalog to D igital C onverters, ADC cannot work fast enough.

 The application can be too complex to be performed in real-time.

Slide 8

Why do we need DSP processors?

 Why not use a General Purpose

Processor (GPP) such as a Pentium instead of a DSP processor?

 What is the power consumption of a

Pentium and a DSP processor?

 What is the cost of a Pentium and a DSP processor?

Slide 9

Why do we need DSP processors?

Use a DSP processor when the following are required:

 Cost saving.

 Smaller size.

Low power consumption.

Processing of many “high” frequency signals in real-time.

Use a GPP processor when the following are required:

 Large memory.

 Advanced operating systems.

Slide 10

What are the typical DSP algorithms?

 The Sum of Products (SOP) is the key element in most DSP algorithms:

Algorithm

Finite Impulse Response Filter

Equation y ( n )

M

 k

0 a k x ( n

 k )

Infinite Impulse Response Filter y ( n )

M

 k

0 a k x ( n

 k )

 k

N 

1 b k y ( n

 k )

Convolution

Discrete Fourier Transform

Discrete Cosine Transform F y ( n )

N

0 k x ( k ) h ( n

 k )

X ( k )

N 

1 n

0 x ( n ) exp[

 j ( 2

/ N ) nk ]

N x

1

0 c ( u ).

f ( x ).

cos



2 N u

2 x

1

 



Floating vs. Fixed point processors

Slide 11

Applications which require:

 High precision.

 Wide dynamic range.

 High signal-to-noise ratio.

 Ease of use.

Need a floating point processor.

Drawback of floating point processors:

 Higher power consumption.

 Can be higher cost.

 Can be slower than fixed-point counterparts and larger in size.

Slide 12

Floating vs. Fixed point processors

It is the application that dictates which device and platform to use in order to achieve optimum performance at a low cost.

For educational purposes, use the floating-point device (C6711) as it can support both fixed and floating point operations.

Slide 13

Learning Objectives

Introduction to Code Composer Studio

(CCS).

Introduction to the DSK.

Laboratory.

Slide 14

Code Composer Studio

 The Code Composer Studio (CCS) application provides an integrated environment with the following capabilities:

Integrated development environment with an editor, debugger, project manager, profiler, etc.

‘C/C++’ compiler, assembly optimiser and linker (code generation tools).

 Simulator.

 Real-time operating system (DSP/BIOS™).

 Real-Time Data Exchange (RTDX™) between the Host and Target.

 Real-time analysis and data visualisation.

Slide 15

Using CCS

 Start CCS by either:

 Using the desktop icon:

 Start -> Programs -> Texas Instruments ->

Code Composer Studio 2 -> Code Composer

Studio.

 Run cc_app.exe in c:\ti\cc\bin\

Slide 16

Troubleshooting

 If the following window appears on your screen then:

 Check that the DSK is connected properly and powered up.

 Check if the port address and mode is correct

(See Slide 7).

Slide 17

Introduction to the ‘C6711 DSK

The ‘C6711 DSK provides a powerful, low-cost development environment.

The DSK comes with CCS code development tools (does not include the simulator).

A laboratory at the end of this section takes you through the DSK setup and shows you how to run the confidence test to check it is working correctly.

DSK Contents

Hardware ( Schematics )

 150 MHz ‘C6711 DSP

TI 16-bit A/D Converter (‘AD535)

External Memory

 16M Bytes SDRAM

 128K Bytes Flash ROM

LED’s

Daughter card expansion

 Power Supply & Parallel Port Cable

Software

 Code Generation Tools

(C Compiler, Assembler & Linker)

Code Composer Debugger

(256K program limitation)

Example Programs & S/W Utilities

Power-on Self Test

Flash Utility Program

Board Confidence Test

Host access via DLL

Sample Program(s)

Slide 18

Hardware: (1) Overview

 The daughter card interface socket provides a method for accessing most of the C6711 DSP for hardware extension.

1.8V Power Supply 16M SDRAM 128K FLASH

Daughter Card I/F

(EMIF Connector)

Parallel

Port I/F

Power

Jack

Power

LED

3.3V Power Supply

JTAG Header

TMS320C6711

Reset

Emulation

JTAG Header

‘C6711

DSP

D. Card I/F

(Periph Con.)

User DIP switches

Three User LEDs

16-bit codec (A/D & D/A)

Line Level Input (microphone)

Line Level Output (speakers)

Slide 19

Hardware: (2) Power On Self Test (POST)

Slide 20

There are three LEDs to provide the user with feedback from the test procedure.

The test program (stored in the FLASH memory, code available on the DSK CD-ROM) runs every time DSK is powered on and reset.

5

6

3

4

7

1

2

Test LED 3 LED 2 LED 1 Description

0 0 0 0 Start state

0

0

0

1

1

0

DSP internal SRAM test

External SDRAM test

0

1

1

1

1

1

0

0

1

1

1

0

1

0

1

DSP McBSP0 loop back test

External codec read/write test

External codec tone generation test

External LED and DSP timer test

Unused – available for future test use

B L I N K A L L All tests completed successfully

CCS Reset

Menu selection:

Debug  DSP Reset

Resets ‘C6711 DSP

Causes bootload from FLASH which overwrites internal memory

Hardware: (3) Resets

TMS320C6711

Absolute Reset

On rare occasions you might have to:

Pull power jack

Pull parallel port

Apply Power

POST runs

Slide 21

Reset Pushbutton

Don’t push when CCS is running

Does not force FULL system reset

To fully reset board, pull power plug

Power On Self Test (POST)

Counts 1 - 7

4:   mic input  spkr out

5:    sinewave  spkr out

Don’t start CCS until end

(all 3 LEDs flash at the end)

If switches are set to 0100, a fast version of

POST is run

Software: (1) PC Host Utilities

DSK Loader dsk6ldr.exe filename.out

Runs on PC host

Downloads .out file to DSK memory map

Stand alone DSK loader for when you want to bypass CCS

FLASH Programming hex6x.exe f.out h.cmd flash.exe f.hex

First, convert file.out to file.hex

The flash utility downloads the hex file into the on-DSK FLASH

Both programs run on the PC host. Links\SPRA804.pdf

DSK Confidence Test dsk6xtst

Run from MSDOS prompt

Command-line utility tests proper installation of the DSK board

Additionally, it tests: Internal SRAM, SDRAM, FLASH, McBSP, Timers,

EDMA, LEDs and Audio codec

Slide 22

Slide 23

Software: (2) CCS DSK Utilities

Confidence Test

1.

Unload any gel files already loaded in CCS

2.

Load conftest.gel

3.

Run confidence tests from

GEL menu

Quick Test

Run from CCS GEL menu

Defined in dsk6xinit.gel

Non-intrusive test by reading and writing:

LEDs

Switches

 DSK board revision

Outputs switch values

General Extension Language (GEL):

An interpretive language that enables you to write functions to configure the

IDE and access the target processor.

Software: (3) DSK Help

Slide 24

 DSK6711 help is available via the Help menu in CCS.

Laboratory Exercise: DSK Hardware Setup

Slide 25

(1) Connect the following cables:

 Parallel port.

 Audio cables.

(2) Connect the power and observe the Power On Self-

Test (POST) (Refer to Slide 15).

(3) Run the confidence test for the PC. There are three methods to run this test:

(a) Run the “dsk6xtst.exe” by double-clicking on the file in “\Code\Chapter 03 - CCS and DSK\”.

(b) Run the “dsk6xtst.exe” file from windows by double clicking on the file in

“\ti\c6000\dsk\conftest\Host\Debug”.

(c) Open a DOS window and run the “dsk6xtst.exe” file located in the directory above.

Laboratory exercise: DSK hardware setup

Notes:

 The SDRAM may take a while due to the large amount of SDRAM on the ‘C6711 DSK.

The CODEC test performs two operations: (1) a

1kHz tone output, and (2) an audio input to output loopback. You must have a speaker connected to the the output jack to hear the test.

If the confidence test fails:

(1) Remove the power and parallel cable from the DSK.

(2) Reset your PC.

(3) Reconnect the power and the parallel cable.

(4) Invoke CCS.

Slide 26

Laboratory Exercise: Using CCS

Implement: y

 i

N 

1

0 a i x i with: a i

= {40, 39, …, 1} x i

= {1, 2, …, 40}

Slide 27

(1) Create a working directory and copy the following files from \Code\Chapter 03 - CCS and DSK\:

(a) lab3.cdb

(b) lab3.c

(c) lab3cfg.cmd

(2) Create a new project:

(a) Start CCS.

(b) Create a new project as shown on the following slide.

Slide 28

Laboratory Exercise: Using CCS

Slide 29

Laboratory Exercise: Using CCS

(3) Add files to the project (lab3.c, lab3.cdb, lab3cfg.cmd).

Slide 30

Laboratory Exercise: Using CCS

(4) Change the build options (compile and link):

Slide 31

Laboratory Exercise: Using CCS

(5) Build the output program (lab3.out):

(a) Build the project by:

(i) Clicking the Rebuild All toolbar icon.

(ii) Selecting Rebuild All in the project menu.

(b) Verify that the build output window is complete with “0 errors, 0 warnings”:

Slide 32

Laboratory Exercise: Using CCS

(6) Load the output file lab3.out into DSP memory:

(a) The program will be automatically loaded after each project build if the “Program Load after Build” option is selected as shown below:

Slide 33

Laboratory Exercise: Using CCS

(6) Load the output file lab3.out into DSP memory:

(b) Load the lab3.out by selecting File:Load

Program as shown below:

Laboratory Exercise: Using CCS

(7) Debug and run code:

(a) Go to the beginning of the program, that is main() by selecting Debug:Go Main.

(b) Watch variables:

(i) Select the variable (to be watched) from the lab3.c file, right click and select “Add To

Watch Window”. If the variable is y for instance, the following window will be shown.

Slide 34

(ii) To add another variable to the watch select it and then drag and drop it on to the window.

Slide 35

Laboratory Exercise: Using CCS

(7) Debug and run code:

(c) CCS will automatically add the local variables:

Slide 36

Laboratory Exercise: Using CCS

(7) Debug and run code:

(d) You can run or step through the code by using the various icons on the toolbar or use the

Debug menu:

Slide 37

Laboratory Exercise: Using CCS

(e) Stop the processor from running and watch the variable y: y = 0x2cdb or 11480

(8) Benchmarking and profiling code:

(a) Stop the processor, reload the code or select

Debug:Restart then select Debug:Go Main.

(b) Open a new profiling session and name it

“Session 1” and select “Profile All Functions” by clicking the following toolbar button:

Slide 38

Laboratory Exercise: Using CCS

(8) Benchmarking and profiling code:

(c) Expand the lab3.c as shown below:

Slide 39

Laboratory Exercise: Using CCS

(8) Benchmarking and profiling code:

(d) Add a breakpoint at “for(;;);”. This can be done by:

(i) Click the cursor on the highlighted line below.

(ii) Click the “Add Breakpoint” toolbar button:

Slide 40

Laboratory Exercise: Using CCS

(8) Benchmarking and profiling code:

(e) Run the program and examine the profile window:

Slide 41

Part 2

Developing A Simple Program

Slide 42

Learning Objectives

Learn how to create a simple program

Learn basic debug techniques

Understand how CCS facilitates development

Slide 43

Creating a New Project

 Double-click the Code Composer Studio icon on your desktop.

Slide 44

Creating a New Project

From the Project menu, choose New.

In the Project Name field, type volume1.

In the Location field, browse to the working folder you created in step 1.

In the Project Type field, select

Executable (.out).

In the Target field, select the target you have CCS configured for and click Finish.

Slide 45

Adding Files to a Project

Choose Project→Add Files to Project.

Select volume.c and click Open.

Choose Project→Add Files to Project.

 Select Asm Source Files (*.a*, *.s*) in the

Files of type box.

 Select vectors.asm and load.asm, and click

Open.

Choose Project→Add Files to Project.

 Select Linker Command File (*.cmd) in the

Files of type box.

 Select volume.cmd and click Open.

Slide 46

Adding Files to a Project

Choose Project→Add Files to Project.

Go to the compiler library folder

( C:\ti \c6000\cgtools\lib).

 Select Object and Library Files (*.o*, *.lib) in the Files of type box.

 Select the rts.lib

file for the target you are configured for and click Open.

In the Project View window, right-click on volume1.pjt and select Scan All

Dependencies.

 volume.h should appear under the Include folder in the Project View window.

Slide 47

Adding Files to a Project

Expand the Project list by clicking the + signs next to

Project, volume1.pjt,

Libraries, and

Source.

This list is called the Project View.

Slide 48

Reviewing the Source Code

The processing function multiplies each value in the input buffer by the gain and puts the resulting values into the output buffer.

It also calls the assembly load routine, which consumes instruction cycles based on the processingLoad value passed to the routine.

The dataIO function in this example does not perform any actions other than to return.

Rather than using C code to perform I/O, we will use a Probe Point within Code Composer

Studio to read data from a file on the host into the inp_buffer location.

Slide 49

Building and Running the Program

Choose Project→Rebuild All or click the

(Rebuild All) toolbar button.

By default, the .out file is built into a debug directory located under your current project folder.

 Choose File→Load Program. Select the program you just rebuilt, Volume1.out, and click Open.

Choose View®Mixed Source/ASM.

 This allows you to view your c source and the resulting assembly code at the same time.

Slide 50

Building and Running the Program

Choose Debug→Go Main to begin execution from the main function. The execution halts at main and is identified by .

Choose Debug→Run or click the (Run) toolbar button.

Choose Debug→ Halt to quit running the program.

From the View menu,

 choose Mixed Source/ASM. This allows you to view c code without the assembly so you can accomplish the next task: Changing Program Options and Fixing

Syntax errors

Slide 51

Changing Program Options and Fixing

Syntax Errors

Choose

Project→Build

Options.

In the Compiler tab of the Build

Options window,

 select Preprocessor from the Category list. Type FILEIO in the Define Symbols field. Press the Tab key.

Slide 52

Changing Program Options and Fixing

Syntax Errors

Click OK to save your new option settings.

Choose Project→Rebuild All or click the (Rebuild

All) toolbar button. You need to rebuild all the files whenever the project options change.

A build message indicates the program contains compile errors. Click the Build tab and scroll up in the Build tab area. You see a syntax error message.

Slide 53

Changing Program Options and Fixing

Syntax Errors

Double-click on the red text that describes the location of the syntax error (line 68). Notice that the volume.c source file opens, and your cursor is on the following line:

 processing(input, output);

Fix the syntax error in the line above the cursor location (The semicolon is missing.) It should look like this:

 puts("begin processing");

Notice that an asterisk (*) appears next to the filename in the Edit window's title bar, indicating that the source file has been modified. The asterisk disappears when the file is saved.

Choose File→Save or press Ctrl+S to save your changes to volume.c.

Slide 54

Changing Program Options and Fixing

Syntax Errors

Choose Project→Build or click the (Incre-mental

Build) toolbar button. Code Composer Studio rebuilds files that have been updated.

Choose File→Load Program and select volume1.out.

Choose Debug→Go Main to begin execution from the main function. The execution halts at main and is identified by .

Choose Debug→Run or click the (Run) toolbar button.

Choose Debug→ Halt to quit running the program.

Slide 55

Adding a Probe Point for File I/O

To transfer input data from a file on the host PC to a buffer on the target for use by the algorithm

To transfer output data from a buffer on the target to a file on the host PC for analysis

To update a window, such as a graph, with data

Slide 56

Adding a Probe Point for File I/O

Choose File→Load Program. Select volume1.out, and click Open.

Double-click on the volume.c file in the Project

View.

Put your cursor in the line of the main function that says:

 dataIO();

Click the (Toggle Probe Point) toolbar button. The selection margin indicates that a probepoint has been set.

From the File menu, choose File I/O.

 The File I/O dialog appears so that you can select input and output files.

Adding a Probe Point for File I/O

Slide 57

In the File Input tab, click Add File.

Browse to the volume1 project folder you created, select sine.dat and click Open.

In the File I/O dialog, change the

Address to inp_buffer and the

Length to 100. Also, put a check mark in the Wrap

Around box.

Adding a Probe Point for File I/O

Slide 58

Click Add Probe Point. The

Probe Points tab of the

Break/Probe Points dialog appears.

In the Probe Point list, highlight the line that says

VOLUME.C line 61 --> No

Connection.

In the Connect To field, click the down arrow and select the sine.dat file from the list.

Click Replace. The Probe

Point list changes to show that this Probe Point is connected to the sine.dat file.

Click OK. The File I/O dialog shows that the file is now connected to a Probe

Point.

Click OK to close the File

I/O dialog.

Displaying Graphs

Slide 59

Choose

View→Graph→Time/Frequency.

In the Graph Property Dialog, change some of the variable properties to the values shown here.

Click OK. An Input graph window for the Input Buffer appears.

Right-click on the Input graph window and choose Clear Display from the pop-up menu.

Choose

View→Graph→Time/Frequency again.

This time, change the Graph Title to Output and the Start Address to out_buffer. All the other settings are correct.

Click OK to display the Output graph window.

Slide 60

Animating the Program and Graphs

In the volume.c window, put your cursor in the line that calls dataIO.

Click the (Toggle Breakpoint) toolbar button or press F9. A red icon is placed in the selection margin to represent the breakpoint.

Arrange the windows so that you can see both graphs.

Click the (Animate) toolbar button or press

F12 to run the program.

Each time the Probe Point is reached, Code

Composer Studio gets 100 values from the sine.dat file and writes them to the inp_buffer address.

Animating the Program and Graphs

Slide 61

Choose Debug→Halt to quit running the program.

Slide 62

Adjusting the Gain

Choose View→Watch Window and select the

Watch1 tab.

Click on the expression icon in the Name column and type gain as the name of the variable to watch.

Click on the white space in the watch window to save the change. The value should immediately appear as in the following example.

Slide 63

Adjusting the Gain

If you have halted the program, click the

(Animate) toolbar button to restart the program.

Observe the input and output graph you created earlier.

From the Debug menu, choose Halt.

In the Watch Window, select the value of gain (1) and change it to 10.

From the Debug menu, choose Animate. Notice that the amplitude of the signal in the Output graph changes to reflect the increased gain as in the following example:

Adjusting the Gain

Slide 64

From the Debug menu, choose Halt.

From the Project menu, choose Close.

Close all other windows and graphs.

Slide 65

Part 3

Finite Impulse Response (FIR) Filters

Slide 66

Learning Objectives

Introduction to the theory behind FIR filters:

 Properties (including aliasing).

 Coefficient calculation.

 Structure selection.

Implementation in Matlab and C.

Slide 67

Introduction

Amongst all the obvious advantages that digital filters offer, the FIR filter can guarantee linear phase characteristics.

Neither analogue or IIR filters can achieve this.

There are many commercially available software packages for filter design.

However, without basic theoretical knowledge of the FIR filter, it will be difficult to use them.

Slide 68

Properties of an FIR Filter

 Filter coefficients: y

N k

1

0 b k

 x

 n

 k

 x[n] represents the filter input, b k represents the filter coefficients, y[n] represents the filter output,

N is the number of filter coefficients

(order of the filter).

Slide 69

Properties of an FIR Filter

 Filter coefficients: y

N k

1

0 b k

 x

 n

 k

FIR equation z

-1 x(n) x b

0 z

-1 x b

1 z

-1 x b

2 z

-1 x b

N-1

+ +

Filter structure

+ y(n)

Slide 70

Properties of an FIR Filter

 Filter coefficients: y

N k

1

0 b k

 x

 n

 k

 If the signal x[n] is replaced by an impulse

[n] then: y

N k

1

0 b k

 n

 k

 y

 

 b

0

 

 b

1

 

   b k

 

Slide 71

Properties of an FIR Filter

 Filter coefficients: y

N k

1

0 b k

 x

 n

 k

 If the signal x[n] is replaced by an impulse

[n] then: y

N k

1

0 b k

 n

 k

 y

 

 b

0

 

 b

1

 

   b k

 n

N

Slide 72

Properties of an FIR Filter

 Filter coefficients: y

N k

1

0 b k

 x

 n

 k

 If the signal x[n] is replaced by an impulse

[n] then: y

N k

1

0 b k

 n

 k

 n

 k

1 for n

0 for n

 k

 k

Slide 73

Properties of an FIR Filter

 Filter coefficients: y

N k

1

0 b k

 x

 n

 k

 Finally: b

0 b

1

 h

  h

  b k

 h

 

Slide 74

Properties of an FIR Filter

 Filter coefficients: y

N k

1

0 b k

 x

 n

 k

With: b k

 h

 

 The coefficients of a filter are the same as the impulse response samples of the filter.

Slide 75

Frequency Response of an FIR Filter

 By taking the z-transform of h[n], H(z):

H

 n

N 

1

0 h

  z

 n

 Replacing z by e -j

 in order to find the frequency response leads to:

H z

 e j

H

N n

1

0 h

  e

 jn

Slide 76

Frequency Response of an FIR Filter

 Since e -j2

 k = 1 then:

H

 

2

N n

1

0 h

  e

 jn

  

2

 

N

1 h

  e n

0

 jn

 Therefore:

H

 

2 k

H

 

 FIR filters have a periodic frequency response and the period is 2

.

Slide 77

Frequency Response of an FIR Filter

 Frequency response: H

 

2

H

  x[n] FIR y[n]

F s

/2

Freq

F s

/2

Freq

Slide 78

Frequency Response of an FIR Filter

 Solution: Use an anti-aliasing filter.

x(t) ADC x[n]

FIR

Analogue

Anti-Aliasing y[n]

F s

/2

Freq

F s

/2

Freq

Slide 79

Phase Linearity of an FIR Filter

 A causal FIR filter whose impulse response is symmetrical is guaranteed to have a linear phase response.

h(n) h(n)

N = 2n + 2 N = 2n + 1

0 1 n n+1 2n 2n+1 n

0 1 n-1 n n+1 2n-1 2n n

Even symmetry Odd symmetry

Slide 80

Phase Linearity of an FIR Filter

 A causal FIR filter whose impulse response is symmetrical (ie h[n] = h[N-1-n] for n = 0, 1, …, N-1) is guaranteed to have a linear phase response.

Condition h

  

N

 n

1

Positive Symmetry

Phase k

 

N

2

1 k

Phase Property

Linear phase

Filter Type

Odd Symmetry – Type 1

Even Symmetry – Type 2

Phase Linearity of an FIR Filter

 Application of 90° linear phase shift:

I 90 o

IH

+

Reverse delay +

Signal separation delay

-

Forward

Q 90 o

+

QH

I

A cos

 f t

B sin

 r t

Q

A sin

 f t

B cos

 r t

IH

A cos

A sin

 f f t t

2

B

B cos

 r t sin

 r t

2

IH

Q

2 B cos

 r t

QH

I

2 B sin

 f t

Slide 81

Slide 82

Design Procedure

 To fully design and implement a filter five steps are required:

(1) Filter specification.

(2) Coefficient calculation.

(3) Structure selection.

(4) Simulation (optional).

(5) Implementation.

Slide 83

Filter Specification - Step 1

|H(f)|

1 pass-band stop-band

|H(f)|

(dB)

 p

0

-3

 s pass-band f c : cut-off frequency

(a) transition band stop-band f s /2 f(norm)

|H(f)|

(linear)

1

  p

1

1

  p pass-band ripple stop-band ripple f s

/2

 s f(norm) f sb : stop-band frequency f c

: cut-off frequency f pb : pass-band frequency

(b)

Slide 84

Coefficient Calculation - Step 2

There are several different methods available, the most popular are:

 Window method.

 Frequency sampling.

 Parks-McClellan.

We will just consider the window method.

Slide 85

Window Method

First stage of this method is to calculate the coefficients of the ideal filter.

This is calculated as follows: h d

1

2

1

2



2

 

H

  e j

 n d

 c

1

 e j

 n d

 f c

  c sin n

 n

 c

 c

2 f c for n for n

0

0

Slide 86

Window Method

Second stage of this method is to select a window function based on the passband or attenuation specifications, then determine the filter length based on the required width of the transition band.

Window Type

Rectangular

Hanning

Hamming

Blackman

Kaiser

Normalised Transition

Width (

 f(Hz))

0 .

9

N

3 .

1

N

3 .

3

N

5 .

5

N

2 .

93

N

5 .

71

N

4 .

54

8 .

96

Passband Ripple(dB)

Stopband Attenuation

(dB)

0.7416

21

0.0546

0.0194

0.0017

0.0274

0.000275

44

53

74

50

90

Using the Hamming

Window:

N

3 .

3

 f

1 .

2

3 .

3

1 .

4

 kHz

8 kHz

132

Slide 87

Window Method

 The third stage is to calculate the set of truncated or windowed impulse response coefficients, h[n]: h

 

 h d

    for

N

1

 n

2

N

2

 n

N

N

2

1 for N

 odd for N

 even

2

Where:

W

0 .

54

0 .

54

0 .

46

0 .

46 cos

2

N n cos

2

 n

133

 for 

66

 n

66

Window Method

Slide 88

 close all; clear all;

Matlab code for calculating coefficients: fc = 8000/44100;

N = 133; n = -((N-1)/2):((N-1)/2); n = n+(n==0)*eps;

[h] = sin(n*2*pi*fc)./(n*pi);

[w] = 0.54 + 0.46*cos(2*pi*n/N); d = h.*w;

[g,f] = freqz(d,1,512,44100);

% cut-off frequency

% number of taps

% avoiding division by zero

% generate sequence of ideal coefficients

% generate window function

% window the ideal coefficients

% transform into frequency domain for plotting figure(1) plot(f,20*log10(abs(g))); axis([0 2*10^4 -70 10]); figure(2); stem(d); xlabel('Coefficient number'); ylabel ('Value'); title('Truncated Impulse Response'); figure(3) freqz(d,1,512,44100); axis([0 2*10^4 -70 10]);

% plot transfer function

% plot coefficient values

% use freqz to plot magnitude and phase response

Slide 89

0.3

0.2

0.1

0

-0.1

0

0.4

Window Method

Truncated Impulse Response

20 40 60 80

Coefficient number

100 120 140

-2000

-4000

-6000

0

0

-20

-40

-60

0

0

0.2

0.4

0.6

0.8

1 1.2

Frequency (Hz)

1.4

1.6

1.8

x 10

4

2

0.5

1

Frequency (Hz)

1.5

2 x 10

4

Slide 90

Realisation Structure Selection - Step 3

 Direct form structure for an FIR filter:

H

N k

1

0 b k z

 k

Y

 

H

    y

 

 b

0 x

 

 b

1 x

 n

1

....

 b

N

1 x

 n

N

1

 z

-1 z

-1 z

-1 x(n) b

0 b

1 b

2 b

N-1

+ + + y(n)

Slide 91

Realisation Structure Selection - Step 3

 Direct form structure for an FIR filter:

H

N k

1

0 b k z

 k

 Linear phase structures:

 N even:

H

N k

2 

1

0 b k

 z

 k  z

N

 k

1

 N Odd:

H

N

1 k

2 

0 b k

 z

 k  z

N

 k

1

 b

N

1 z

N

1

2

2

Slide 92

Realisation Structure Selection - Step 3 z

-1 z

-1 (a) N even.

(b) N odd.

z

-1

+

(a)

+ z

-1

+ z

-1

+ b

0 b

1 b

2

+

+ y(n) b

N/2-1

+ x(n) z

-1 z

-1 z

-1 z

-1

+ z

-1

+ z

-1

+ b

0 b

1 b

2

+

+

+ b

(N-3)/2

+ y(n) +

(b)

Slide 93

Realisation Structure Selection - Step 3

 Direct form structure for an FIR filter:

H

N k

1

0 b k z

 k

 Cascade structures:

H

N k

1

0 b k z

 k  b

0

 b

1 z

1  b

2 z

2 

...

 b

N

1 z

N

1

 b

0

1

 b

1 b

0 b

0 k

M 

1

1

 z

1  b k , 1 z

1 b

2 b

0 z

2 

...

 b k , 2 z

2

 b

N

1 b

0 z

N

1

Slide 94

Realisation Structure Selection - Step 3

 Direct form structure for an FIR filter:

H

N k

1

0 b k z

 k

 Cascade structures: x(n) b

0

+ z -1 b

1,1 z -1 b

1,2

+

+ z -1 b

2,1

+ z -1 b

2,2 z -1 z -1

+ y(n) b

M,1

+ b

M,2

Slide 95

Implementation - Step 5

Implementation procedure in ‘C’ with fixed-point:

 Set up the codec ( \Links\CodecSetup.pdf

).

Transform: to ‘C’ code. y k

0 b k x

 n

 k

( \Links\FIRFixed.pdf

)

 Configure timer 1 to generate an interrupt at

8000Hz ( \Links\TimerSetup.pdf

).

 Set the interrupt generator to generate an interrupt to invoke the Interrupt Service

Routine (ISR) ( \Links\InterruptSetup.pdf

).

Slide 96

Implementation - Step 5

Implementation procedure in ‘C’ with floating-point:

Same set up as fixed-point plus:

 Convert the input signal to floating-point format.

 Convert the coefficients to floating-point format.

 With floating-point multiplications there is no need for the shift required when using

Q15 format.

See \Links\FIRFloat.pdf

Slide 97

Implementation - Step 5

 Implementation procedure in assembly:

Same set up as fixed-point, however:

 is written in assembly.

y

N k

1

0 b k

 x

 n

 k

( \Links\FIRFixedAsm.pdf

)

 The ISR is now declared as external.

Download