element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Embedded and Microcontrollers
  • Technologies
  • More
Embedded and Microcontrollers
Embedded Forum Implementing a digital Filter
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Embedded and Microcontrollers to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 13 replies
  • Answers 8 answers
  • Subscribers 476 subscribers
  • Views 1789 views
  • Users 0 members are here
Related

Implementing a digital Filter

farcane
farcane over 8 years ago

Hallo Guys,

 

I want to implement a digital filter using an Atmega16 Microcontroller, I am getting the Input signal from an 8 bit  ADC "AD9057" to  the Atmega 16  "port C" then I converted my input signal to ASCii Characters ( 0-128)  which are displayed in my Terminal every 1 second , but there is some noise in my output signal and I want to get rid of it, so I want to use a digital filter for this purpose, but I am confused which digital filter may I implement  to get the desired result.

 

just to give you an example:

 

When I apply a constant voltage to my  ADC analog input; I expect a  single digital output representation. but I am getting a range of data.

 

like when I apply 2 V I get a digital output  (0 - 3)

                           2.2 V I get ( 40- 44)

                           2.3 V I get ( 65-70)

                           2.5 V I get ( 118-124)

 

And in each case the desiried output should be just one value " a single digital output representation, lets say the average  " and not a range of data.

 

Any ideas for this issue?

 

regards

Imed

  • Sign in to reply
  • Cancel

Top Replies

  • manlong
    manlong over 8 years ago in reply to farcane +1 suggested
    Imed, First I think you have to add an anti-aliasing filter at the input of your ADC. The cuttoff frequency should be twice as high as the signal frequency. Regards Man Long
  • manlong
    manlong over 8 years ago in reply to michaelkellett +1 suggested
    When you input to an ADC you have to put before an anti aliasing filter. The aim is to reduce the noise. Even you want to measure DC signal. You have to filter and delete all signal above DC. The ADC acquire…
  • michaelkellett
    michaelkellett over 8 years ago in reply to manlong +1 suggested
    @ Man Long Lay I'm sorry but this is NOT the function of an anti-alias filter. The clue is in the name - an anti-alias filter is a low pass filter placed before the ADC to stop frequencies above one half…
Parents
  • manlong
    0 manlong over 8 years ago

    Hello,

    Could you tell me how you apply a constant voltage?

    Is it a sensor? a power supply? a voltage divider?

    If you constant voltage is not constant because of noise, it is normal you have some bit variation.

    Your component have also a noise conversion that generate noise at the output which can varie about 1 bit to 2 bit.

    Regards

    Man Long

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • manlong
    0 manlong over 8 years ago

    Hello,

    Could you tell me how you apply a constant voltage?

    Is it a sensor? a power supply? a voltage divider?

    If you constant voltage is not constant because of noise, it is normal you have some bit variation.

    Your component have also a noise conversion that generate noise at the output which can varie about 1 bit to 2 bit.

    Regards

    Man Long

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
  • farcane
    0 farcane over 8 years ago in reply to manlong

    Hello Man Long,

     

    Thanks for your reply, I am applying a constant voltage from a potentiometer( 0 to +0.5V) throught an inverting amplifier ( AD8041)  which yields an output of ( 2.5V - 2V ) respectively; which is directly connected to the ADC analog input.

     

    Yes you are right that can be the reason why I am getting a range of output digital representation, but how do you think may I implement a digital filter in this case ? should I change the source of the analog input ? knowing that my ADC ( AD9057)  works only with an analag input of 1V pp and its related to the ADC reference voltage, which is in my case 2.5V,  so the analog input range is between ( 2- 3V), have a look at the ADC data sheet page 4 http://www.analog.com/media/en/technical-documentation/data-sheets/AD9057.pdf

     

    regards

    Imed

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • manlong
    0 manlong over 8 years ago in reply to farcane

    Imed,

    First I think you have to add an anti-aliasing filter at the input of your ADC.

    The cuttoff frequency should be twice as high as the signal frequency.

    Regards

    Man Long
    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 8 years ago in reply to manlong

    @ Man Lomg Lay

    If Imed is measuring DC then an anti aliasing filter will make no difference at all.

     

    @Imed,

     

    Your ADC looks very very noisy, much worse than it should be.

    You are using a fast ADC and I think from my recollection of your pcb you don't have very good ground planes (I think none at all) - this may hurt at fast sampling rates.

    Check the noise on your power supplies to the ADC using a scope and possibly increase the values of any decoupling capacitors.

    Check the noise on the ADC input if your scope is good enough - you should be looking for peak - peak noise less than 4mV.

     

    When you get the noise to a reasonable level I can help you with a digital filter, but I would need to know the sampling rate and the bandwidth of the signals you want to measure.

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • manlong
    0 manlong over 8 years ago in reply to michaelkellett

    When you input to an ADC you have to put before an anti aliasing filter.

    The aim is to reduce the noise. Even you want to measure DC signal.

    You have to filter and delete all signal above DC.

    The ADC acquire all signal between DC to 120MHz. If you want only DC signal you have to cutoff the signal above DC.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • farcane
    0 farcane over 8 years ago in reply to michaelkellett

    Hello Michael,

     

    which ADC noise do you mean? because I solved the problem that I told you about before, and now I am getting a reasonble digital output range of 4 to 5 Bits difference only, so for example if I apply 2V to AIN of my ADC I get ( 0-3 ) digital output converted to ASCII, and if I apply 2.2V to AIN I get (40-44), for 2.5V I get (120- 125) knowing that my reference voltage is exactly 2.52V, so I think my ADC is not so noisy and that digital output bits difference is due to a small alternance of 10mV  in the AIN voltage because as you know this voltage is coming from an inverting amplifer output.

    The sampling frequency of my Analog signal is 5MHz, so what kind of digital Filter may I implement with an Atmega16  please ?

     

    Best regards

    Imed Oussalah

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 8 years ago in reply to manlong

    @ Man Long Lay

    I'm sorry but this is NOT the function of an anti-alias filter.

    The clue is in the name - an anti-alias filter is a low pass filter placed before the ADC to stop frequencies above one half of the sampling frequency from appearing at the input. This is because if you, for example, sample a 1.1kHZ sine wave at 2kHz you will see a 100Hz signal in the ADC output  - this effect is called 'aliasing'. If you stop any frequencies above 1000Hz getting into your 2kHz sampling system the effect will not occur.

    Noise is different, there will be noise generated in the ADC itself and noise presented at its input. You can reduce random broadband noise at the input by reducing the bandwidth but this is very unlikely to be Imed's problem, and we know from his earlier posts that he wants eventually to sample faster signals than DC.

     

    @Imed

    4 or 5 bits noise is a bit higher than I might have hoped for but not too dreadful.

    At 5MHz your ATmega16 is not going to cope:

     

    Digital filtering is  a big subject but about the simplest filter you can use is a rolling average:

     

    Add together the last 2,4, 8 or 16 samples and then divide the total by 2,4,8 or 16. The use of powers of two means that the divide can be a shift operation (keep to unsigned data). An you don't need to add up 16 samples each time, just add in the new one and take off the oldest one.

     

    Another kind of filter is a simulated RC

     

    filtered_data = filtered_data + ((new sample - filtered_data)/k)

     

    If you are careful about the value of k then division can be a shift but arithmetic must be signed. For an 8 bit ADC you will need to use at least 16 and quite possibly 32 bit precision for the maths. A typical value for k would be 8.

     

    The first filter is more deterministic than the second, any change in data is worked though in the fixed number of samples you average, the second filter takes (in theory) infinite time to work though a disturbance although in pracitce the precision of the maths controls this.

     

    I don't think an ATmega 16 is capable of implementing either filter at 5MHz sample rate - I'll be impressed if you manage 1MHz.

     

    An ARM Cortex M4 can do either in floating point or 32 bit integer precision at the required speed.

     

    There are much more sophisticated filters possible.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • farcane
    0 farcane over 8 years ago in reply to michaelkellett

    michaelkellett ok, you mean the sampling frequency of my analog input signal right ? which is sampled using the ENCODE pinheader input pf my PCB, that one is 5 MHz.

    but I am getting the digital output on my Terminal every second which means at a freqency of 1 Hz.

     

    Are these algorithms that you told me about digital filtering?  can I implement a typical Digital filter ( like low-pass or High-pass filter FIR or IIR ) with my DC analog input signal and if not with a different signal ?

     

    regards

    Imed

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 8 years ago in reply to farcane

    Imed, you need to read up on digital signal processing.

     

    If you sample at 5MHz your filter needs to run at 5MHz.

     

    Why not set up your ATmega to control the Encode signal, use a timer and make something like 1000 conversions per second, then it will be easy to make a filter such as I describe.

     

    There is no point trying to implement a complex filter until you have  a better feel for what's going on.

     

    The two filters I described are FIR (the first one) and IIR (the second) and both are low pass.

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • abrain
    0 abrain over 6 years ago in reply to michaelkellett

    Hi Michael, I stumbled across this old thread, and I have a feeling that 1.1kHz sampled at 2kHz looks more like 900Hz than 100Hz due the apparent frequencies involved? As you get closer to the sampling frequency, the signal actually appears as a lower and lower frequency, until the two are at the same frequency and the signal looks like dc again.

     

    You can do some neat tricks if you actually filter out below half the sampling frequency, and above the sampling frequency, as you can then sample in that middle range, but working out what on earth you’re looking at gets a little complicated and needs a clear head!

     

    A

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube