Skip to content Skip to navigation Skip to collection information

OpenStax-CNX

You are here: Home » Content » Microcontroller and Embedded Systems Laboratory » Lab 10: Implementing an FIR filter

Navigation

Lenses

What is a lens?

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

This content is ...

Affiliated with (What does "Affiliated with" mean?)

This content is either by members of the organizations listed or about topics related to the organizations listed. Click each link to see a list of all content affiliated with the organization.
  • TI MSP430 display tagshide tags

    This module and collection are included inLens: Texas Instruments MSP430
    By: Texas Instruments

    Comments:

    "Basic introduction to microcontroller-based embedded systems development. Includes structured laboratory exercises in the following areas: assembly programming, C language programming, peripheral […]"

    "This lab shows you how to set up an FIR filter on the MSP430"

    Click the "TI MSP430" link to see all content affiliated with them.

    Click the tag icon tag icon to display tags associated with this content.

Recently Viewed

This feature requires Javascript to be enabled.

Tags

(What is a tag?)

These tags come from the endorsement, affiliation, and other lenses that include this content.
 

Lab 10: Implementing an FIR filter

Module by: adrian valenzuela, Patrick Frantz. E-mail the authors

Summary: 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:

Figure 1
Figure 1 (fir_eqn.jpg)
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.

Collection Navigation

Content actions

Download:

Collection as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Module as:

PDF | More downloads ...

Add:

Collection to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks

Module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks