Design Con 2015
Breaking News
Maxís Cool Beans

MSGEQ7-Based DIY Audio Spectrum Analyzer: Software & Timing

NO RATINGS
Page 1 / 2 Next >
View Comments: Newest First | Oldest First | Threaded View
Max The Magnificent
User Rank
Blogger
Re: Noise Filtering
Max The Magnificent   8/5/2014 2:48:32 PM
NO RATINGS
@Elizabeth: I've used averaging to reduce the noise on an anlog signal but the way I usually do it is to capture sets of samples 2 or 4 times as fast as you need them...

I can't wait to get the main display up and running, and to hen start playing with differenmt filtering techniques to see which works and looks best on the display.

 

Wnderer
User Rank
CEO
Re: Noise Filtering
Wnderer   8/5/2014 7:11:20 AM
NO RATINGS
@elizabethsimon:

Okay, I see what you're doing now. Thanks.

elizabethsimon
User Rank
CEO
Re: Noise Filtering
elizabethsimon   8/5/2014 12:15:58 AM
NO RATINGS
Yes you are right about the first example I gave being a moving average FIR filter of order two. And it would be mroe efficient to do it using a circular buffer..


In the second example I was trying to show an IIR filter. I think it would work as written but might be clearer if it was broken into steps like this

...

   newSpectrumLeft[i] = analogRead(channelLeft) / 4; // new sample

   spectrumLeft[i] = (spectrumLeft[i] + newSpectrumLeft[i]) / 2; average

...

The difference between this example and the first one is that it's always influenced by ALL previous samples although the older samples have much less influence.


As an example, say you had the following values for newSpectrumLeft and you started with everything at zero

32 32 0 0 0 0 0

with the first example that I gave you would have

16 32 16 0 0 0 0

the second example should give

16 24 12 6 3 1

At least that's the idea I was trying to get across

 

Wnderer
User Rank
CEO
Re: Noise Filtering
Wnderer   8/4/2014 6:46:32 PM
NO RATINGS
@elizabethsimon

I don't think that's exactly right. I believe your first example is a moving average filter of order 2 which is an FIR filter. I think your second example keeps getting bigger.  See the Wiki page.

http://en.wikipedia.org/wiki/Finite_impulse_response

I'm not sure the way he is averaging now is doing anything beneficial since he just averages short bursts of values. Implementing a moving average filter might improve the signal, but Max would need to implement a circular buffer for the spectrum values in between channel reads.

 

Some Notes on moving average filters, that seem to be missing from the Wiki.


A moving average filter implements a sinc function

H[f] = |sin(pi *f *M)/(M*sin(pi*f))| where M is the order of the filter. 

The full sampling frequency is divided into M humps.

The peak at the center of sampling frequency has an amplitude of 1/M for odd M. The peaks near the center will be close to this value for even M.

The amplitude of the second hump that occurs at 1.5/M approaches 1/1.5pi as M gets large.

 

 

elizabethsimon
User Rank
CEO
Noise Filtering
elizabethsimon   8/4/2014 4:44:17 PM
NO RATINGS
I've used averaging to reduce the noise on an anlog signal but the way I usually do it is to capture sets of samples 2 or 4 times as fast as you need them.


so in main you would have

...

   delayMicroseconds(sampleTime/2);

   readMSGEQ7s();

...

while in your subroutine you would have

...

   oldSpectrumLeft[i] = newSpectrumLeft[i];

   newSpectrumLeft[i] = analogRead(channelLeft) / 4;

   spectrumLeft[i] = (oldSpectrumLeft[i] + newSpectrumLeft[i]) / 2;

...

This is the simplest form of FIR (Finite Impulse Response) filter

 

Or if you wanted a "running average" you could use something like

...

   spectrumLeft[i] = (spectrumLeft[i] + (analogRead(channelLeft) / 4)) / 2;

...

If you do this though, you need to make sure that you initialize spectrumLeft[i] to zero in your startup code. This is the simplest form of IIR (Infinite Impulse Response) filter.

The averaging technique your friend Steve showed you is most useful if you have a lot of noise on the analog signal which might occur if you had long wires or you were using adjacent signals to run PWM to a motor or something similar.

 

Sheepdoll
User Rank
Blogger
waveform hardware
Sheepdoll   8/4/2014 2:59:11 PM
NO RATINGS
Max;

Your timing diagrams look similar to the ones I have for my pipe organ playback and paper roll conversions.  May be some similarity here as music is recorded as discreet 'events' which relate to frequency (pitch) and duration.

My preference on the Arduinos when dealing with sample and hold type shift registers, is to cascade the hardware timers.  This is how the USB scanner I showed at EELive! works.

One timer is set to the width of the clock pulse.  This toggles the clock line through the output compare. The cascaded timer (which can be done through the timer configuration) counts the clock pulses and can toggle the output compare pin automatically to generate the strobe.  This keeps the ISR routines small.  The overhead plus a shift of the bit in or out. 

For really tight constraints, Unrolled loops work well.  This is a code space/clock speed tradeoff.  AVRs have a lot of code space.

 

 

 

Most Recent Comments
Radio
LATEST ARCHIVED BROADCAST
EE Times Senior Technical Editor Martin Rowe will interview EMC engineer Kenneth Wyatt.
Top Comments of the Week
Like Us on Facebook

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
EE Times on Twitter
EE Times Twitter Feed
Flash Poll