<< Chapter < Page Chapter >> Page >
In this lab, you will implement an FIR filter on an embedded microcontroller.

In this lab, you will learn how to implement an FIR filter. The discrete convolution equation that describes the behavior of a causal length-N filter is:

where x(n) represents the sampled input, h(n) represents the filter's impulse response (it's coefficients), and y(n) is the filtered output.

Part i: io setup

Adc and timers

In order to have a known sampling rate, the ADC must be interrupt driven. Set up your clock as usual, and let Timer B handle any filter clocks, if available. Set up the ADC to be interrupt driven and triggered by Timer A. Use the following code in order to set up Timer A: /* TIMER A */ TACCR0 = 900; TACCTL1 = OUTMOD_4; TACTL |= TASSEL_2+MC_1; Given these timing settings, what is the sampling rate?

Dma and dac

Configure the DMA to transfer your filtered output sample to DAC0. You can set the DMA trigger inside the ADC12 interrupt service routine after you have finished the filtering.

Circular buffer

Notice that FIR filter equation requires the N last input samples to compute the filtered output. In this case, you will need to store the last 21 samples including the most recent one. Implement a circular buffer to store all the required samples. Once you have reached the end of the buffer, reset your index back to zero.

Testing io setup

Verify that the project is working so far by sending the newest value stored in your buffer to the DAC via DMA. Also, using the memory watch window, make sure that input samples are stored in their correct spot in the buffer. You may have to pause your program every time a sample is taken to verify that the buffer filling up correctly.

Part ii: filter implementation

You will be implementing a 20-tap FIR filter. To obtain the filter's coefficients open up Matlab and type the following: B = remez(20,[0,.5,.55,1],[0,0,1,1]) Next, plot the filter's frequency response with the freqz command. What kind of filter is this, and given the ADC sampling frequency, what is the expected cutoff frequency?

Notice that the array of coefficients includes negative numbers. They will have to be converted to Q-15 (16 bit), two's complement format. You can calculate the new coefficients on your own, or you may include the following line in your project: signed short coeff[21]={0x04F5,0xF4D0,0xFA12,0x03AF,0x0295,0xF86D,0xFCD1,0x0D18,0x032C, 0xD768,0x3CC9,0xD768,0x032C,0x0D18,0xFCD1,0xF86D,0x0295,0x03AF,0xFA12,0xF4D0,0x04F5};

Inside your ADC12 interrupt service routine, compute the filtered output sample by taking the inner product of your input samples with the filter coefficients. The inner product is described mathematically in the equation above. Conceptually, your output can be described as output_sample = most_recent_input_sample*coeff[0] + second_most_recent_input_sample*coeff[1]+...+oldest_input_sample*coeff[20] . This is a simple multiply and accumulate operation.

In order to get real time operation, the MSP's hardware multiplier must be used. Be sure to use signed multiplication. How can you use some of the other multiplier functions to simplify your code? How is the output of the multiplier stored? Since the DAC only transmits 16 bits at a time, which multiplier register should be used as the output, and argue why this is a good scheme?

Part iii: testing

Hook up the function generator and the oscilloscope to the ADC and DAC of the board, respectively. Create a new coefficient array of length 21 consisting of a single one and the rest zeros. ([1,0,0,...,0]) What would you expect the output to be? Do you see that on the oscilloscope? Once this is working, try the original array of coefficients. Try changing the frequency on the function generator and make sure that filtering is taking place.

Now let’slook at the effects of the filter in the frequency domain. Set the oscilloscope to display the FFT of the input. The FFT, Fast Fourier Transform, will take a signal in the time domain and display it in the frequency domain. Look at the spectrum while using the [1,0,...,0] test coefficients and an arbitrary sine wave. Include a screenshot in your write up. Next, generate Gaussian White Noise using the function generator and connect it to the input of the board. White noise has power at all frequencies, so if we take the FFT of the output of the filter, we should get the frequency response of the filter. Does the actual frequency response look like the one generated by Matlab? Take a screenshot and submit it in the write up.

Part iv: extra credit

For extra credit, test your filter implementation with a new set of coefficients. Create a new set of filter coefficients that make up a new filter type. You may even increase the number of taps in the filter for more accurate results.

In order to generate a new set of coefficients, open up your favorite copy of matlab and use either the remez command. Newer versions of Matlab suggest you use FIRPM . If you are unsure how to use the command, type help remez to give you the syntax and usage. You may also try to use the Filter Design Toolbox for a more user friendly interface.

Once you have your coefficients, you must convert them to twos-complement Q-15 numbers. You may use twocomplement.m in order to do the conversion for you.

Questions & Answers

where we get a research paper on Nano chemistry....?
Maira Reply
nanopartical of organic/inorganic / physical chemistry , pdf / thesis / review
Ali
what are the products of Nano chemistry?
Maira Reply
There are lots of products of nano chemistry... Like nano coatings.....carbon fiber.. And lots of others..
learn
Even nanotechnology is pretty much all about chemistry... Its the chemistry on quantum or atomic level
learn
Google
da
no nanotechnology is also a part of physics and maths it requires angle formulas and some pressure regarding concepts
Bhagvanji
hey
Giriraj
Preparation and Applications of Nanomaterial for Drug Delivery
Hafiz Reply
revolt
da
Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
ya I also want to know the raman spectra
Bhagvanji
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
Damian
yes that's correct
Professor
I think
Professor
Nasa has use it in the 60's, copper as water purification in the moon travel.
Alexandre
nanocopper obvius
Alexandre
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
if virus is killing to make ARTIFICIAL DNA OF GRAPHENE FOR KILLED THE VIRUS .THIS IS OUR ASSUMPTION
Anam
analytical skills graphene is prepared to kill any type viruses .
Anam
Any one who tell me about Preparation and application of Nanomaterial for drug Delivery
Hafiz
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Microcontroller and embedded systems laboratory. OpenStax CNX. Feb 11, 2006 Download for free at http://cnx.org/content/col10215/1.29
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Microcontroller and embedded systems laboratory' conversation and receive update notifications?

Ask