FIR Filters

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 48

0 - 1

2010 Texas Instruments Inc


Practical Audio Experiments using the TMS320C5505 USB Stick
FIR Filters
Texas Instruments University Programme
Teaching Materials
Chapter 6 - Slide 2
2010 Texas Instruments Inc


Finite Impulse Response
Filters
Chapter 6 - Slide 3
2010 Texas Instruments Inc
Introduction
Finite Impulse Response (FIR) filters are used for:
Low pass filters
High pass filters
Band pass filters
Band stop filters.
They are widely used in Digital Signal Processing
(DSP).
Chapter 6 - Slide 4
2010 Texas Instruments Inc
Objectives
To briefly look at a statistical data series on a graph
To apply principle this to audio
To introduce filter design software tools
To run a range of FIR filters on the TMS320C5505
USB stick.

Chapter 6 - Slide 5
2010 Texas Instruments Inc


Moving Averages
Chapter 6 - Slide 6
2010 Texas Instruments Inc
Statistical Data Series
Before we move on to audio, let us first look at a
typical data series on a graph.

Chapter 6 - Slide 7
2010 Texas Instruments Inc
A Typical Data Series
Data Series
0
100
200
300
400
500
600
700
800
900
1000
1 2 3 4 5 6 7 8 9 10 11 12 13
Data Series Averaged Data
Question: How do we identify the trend?
Chapter 6 - Slide 8
2010 Texas Instruments Inc
Show Data Trend
Moving Average
0
100
200
300
400
500
600
700
800
900
1000
1 2 3 4 5 6 7 8 9 10 11 12 13
Original Data Averaged Data
Answer: Calculate the moving average.
Trend Line
Chapter 6 - Slide 9
2010 Texas Instruments Inc
Mathematics of Moving Average
The graph used the moving average of 4 samples.
To calculate the moving average:
Add together 4 consecutive inputs
Divide the sum by 4:



4
) 4 ( ) 3 ( ) 2 ( ) 1 (
) 4 (
x x x x
y

Chapter 6 - Slide 10
2010 Texas Instruments Inc
Moving Average for Audio
A moving average can also be applied to audio.


Averaging Filter
-2500
-2000
-1500
-1000
-500
0
500
1000
1500
2000
2500
3000
1 2 3 4 5 6 7 8 9 10 11 12
Signal Input Filtered Output
Chapter 6 - Slide 11
2010 Texas Instruments Inc
Frequency Response of Moving Average
The moving average is a low pass digital filter
Chapter 6 - Slide 12
2010 Texas Instruments Inc
Changing Some Constants
This moving average can also be written as:


As an experiment, change the sign of two constants:
) 4 ( 25 . 0 ) 3 ( 25 . 0 ) 2 ( 25 . 0 ) 1 ( 25 . 0 ) 4 ( x x x x y
) 4 ( 25 . 0 ) 3 ( 25 . 0 ) 2 ( 25 . 0 ) 1 ( 25 . 0 ) 4 ( x x x x y
now negative
Chapter 6 - Slide 13
2010 Texas Instruments Inc
Different Values of Constants
The output has changed. Note the delay.
Different Values of Constants
-1500
-1000
-500
0
500
1000
1500
1 2 3 4 5 6 7 8 9 10 11 12 13
Audio Input Filtered Output
Chapter 6 - Slide 14
2010 Texas Instruments Inc
New Frequency Response
We now have a band pass filter.
Chapter 6 - Slide 15
2010 Texas Instruments Inc
Summary of Moving Average
A moving average is a digital filter
There is a delay between the input and the output
Change constants to change the frequency response.

Chapter 6 - Slide 16
2010 Texas Instruments Inc


Finite Impulse Response
Filters
Chapter 6 - Slide 17
2010 Texas Instruments Inc
The FIR Filter
The general formula for a FIR filter is:


N
k
k n x k h n y
0
) ( ) ( ) (
The moving average is a FIR filter with:
) ( ... ) 3 ( ) 2 ( ) 1 ( ) 0 ( N h h h h h
Chapter 6 - Slide 18
2010 Texas Instruments Inc
Block Diagram of FIR Filter
Chapter 6 - Slide 19
2010 Texas Instruments Inc
FIR Coefficients
The terms h(0) to h(N) are called the coefficients.
They can be calculated from the Fourier series
Typically for a C program they would be stored in a
.h file.
Chapter 6 - Slide 20
2010 Texas Instruments Inc
Impulse Applied to FIR
An impulse is commonly used to test filters.
Chapter 6 - Slide 21
2010 Texas Instruments Inc
Why is the Filter Finite?
The output is
derived purely
from the input.
The output is
completely gone
after N samples,
where N is the
FIR filter size.
Here N = 50.

Impulse In
FIR Filter Out
Chapter 6 - Slide 22
2010 Texas Instruments Inc


Implementing FIR Filters
Chapter 6 - Slide 23
2010 Texas Instruments Inc
Ideal vs. Practical FIR Filter
Ideal FIR filter => infinite coefficients.





Practical filter design is a compromise.
FIR Filter 10 coefficients
Practical FIR Filter 10 coefficients
Ideal
Filter
Chapter 6 - Slide 24
2010 Texas Instruments Inc
Using Window Functions
A window function modifies coefficients to
approximate an infinite series.

Chapter 6 - Slide 25
2010 Texas Instruments Inc
Window Types
Some commonly used window functions are:
Rectangular (simple truncation of infinite series)
Hamming
Hanning (or von Hann)
Blackman
Kaiser.

Chapter 6 - Slide 26
2010 Texas Instruments Inc
Rectangular vs. Hamming Window
FIR Filter 5000Hz 50 coefficients Rectangular Window
FIR Filter 5000Hz 50 coefficients Hamming Window
-50dB
-50dB
Better
Chapter 6 - Slide 27
2010 Texas Instruments Inc


Filter Design using Matlab

Chapter 6 - Slide 28
2010 Texas Instruments Inc
Filter Design Toolbox
Chapter 6 - Slide 29
2010 Texas Instruments Inc
Generation of Coefficients
Matlab can export filter coefficients as a .h file.
Chapter 6 - Slide 30
2010 Texas Instruments Inc


Web Based Filter Design
Software

Chapter 6 - Slide 31
2010 Texas Instruments Inc
Free Online Software
A free online filter design package is available at:
www.dsptutor.freeuk.com

Chapter 6 - Slide 32
2010 Texas Instruments Inc
Free Software Output
Supports low pass, band pass and high pass filters.
Chapter 6 - Slide 33
2010 Texas Instruments Inc
Filter Output Coefficients
Filter coefficients are in floating-point format.
Chapter 6 - Slide 34
2010 Texas Instruments Inc
Converting to Fixed-Point
Coefficients lie in the range -1.000 to +1.000
To convert them to fixed-point, multiply each by
32767 then round to nearest integer.

Chapter 6 - Slide 35
2010 Texas Instruments Inc
C Code Implementation of FIR
A simple FIR implementation in C:
Chapter 6 - Slide 36
2010 Texas Instruments Inc


Introduction to Laboratory

Chapter 6 - Slide 37
2010 Texas Instruments Inc
Setup for TMS320C5505
USB to PC
Headphones
CD Player
USB Stick
Chapter 6 - Slide 38
2010 Texas Instruments Inc
Installing the Application




Use the code given in Application 6 FIR Filters.
Follow the steps previously given in Chapter 1 to
set up the new project.


Chapter 6 - Slide 39
2010 Texas Instruments Inc
Create New CCS Project
Chapter 6 - Slide 40
2010 Texas Instruments Inc
Files Used in Project
Chapter 6 - Slide 41
2010 Texas Instruments Inc
Filter Coefficients
Filter coefficients are contained in the four #include
files starting at hamming.h:
Chapter 6 - Slide 42
2010 Texas Instruments Inc
About the Program
Contains a series of FIR filters.
Divides music into bass and treble at different
crossover frequencies:
Low pass filter puts bass on left-hand headphone.
High pass filter puts treble on right-hand headphone.


Chapter 6 - Slide 43
2010 Texas Instruments Inc


Experiments

Chapter 6 - Slide 44
2010 Texas Instruments Inc
Sampling Rates
Run the same filters but at a lower sampling rate, for
example 12000 Hz.
How does this affect the frequencies of the filters?
Chapter 6 - Slide 45
2010 Texas Instruments Inc
Using New Filter Coefficients
You can design your own filter coefficients using
Matlab FDATool or the Web-based tool discussed
earlier.
New coefficients can be added to a new .h file.
You will need to #include this .h file in your project.
Chapter 6 - Slide 46
2010 Texas Instruments Inc
Bass Middle and Treble
Design a series of filters so you can work out at what
frequency the transition occurs between:
bass and mid range
mid range and treble.
Clue: the frequencies are lower than you might first
think.
Chapter 6 - Slide 47
2010 Texas Instruments Inc
Questions
The filters are called Finite Impulse Response filters.
Why is the word finite used?
What is a window function as applied to a digital
filter?
How can a window function be used to improve the
performance of the filter?
How are filter coefficients calculated?
Chapter 6 - Slide 48
2010 Texas Instruments Inc
References
Digital Signal Processing, A Practical Approach by
Emmanuel C. Ifeachor and Barrie W. Jervis. ISBN
0201-59619-9.
Digital Signal Processing with C and the TMS320C30
by Rulph Chassaing. ISBN 0-471-557800-3.

You might also like