Sign in

username or email:

password:



Not a member?
Forgot your password?

Search compdsp



Search tips


Discussion Groups

Free Online Books

See Also

Embedded SystemsFPGA

Discussion Groups | Comp.DSP | Moving average on PSD

There are 6 messages in this thread.

You are currently looking at messages 1 to .


Is this discussion worth a thumbs up?

0

Moving average on PSD - Clay - 2012-08-26 13:14:00

Hi everyone,
I have a baseline PSD plot that is running, but I want to do averaging on
this plot. From what I have been reading online, doing the first-order IIR
exponential moving average filter is the way to do it(memory efficient).
And the formula for that is y[n] = alpha*x[n]+(1-alpha)*y[n-1]. And this is
better than the FIR approach because FIR requires storing N copies of the
PSD.

Computing the basic PSD is straightforward. Assuming we're already in the
frequency domain, it would be something like this:
for (i=0;i<size/2;i++){
    x=imag^2+real^2;
    psd[i]=log10(x);
}
But how exactly do I add the moving average to the psd function? Can anyone
give some hints?

Thanks in advance,
Clay

______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Moving average on PSD - mnentwig - 2012-08-27 05:33:00



>> is the way to do it
depends on what you want.

With an IIR filter you'll get a skewed (asymmetric) result that would be
avoided with a symmetric moving-average filter. 

If you can afford a delay line of the MA length, you can calculate it with
two additions : create an accumulator; add any sample that goes into the
delay line and subtract every one that comes out.

BTW, this piece of code http://www.dsprelated.com/showcode/239.php
could serve as reference. Used correctly, it shows more or less what you'd
see on the screen of a hardware spectrum analyzer if the given signal
repeats periodically. 


______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Moving average on PSD - mnentwig - 2012-08-27 08:48:00

BTW, you didn't say whether you want to average in time ("video bandwidth")
or frequency ("resolution bandwidth"). 
What I wrote applies to frequency. For averaging in time, the one-tap IIR
from your mail looks meaningful. And for an unknown signal you cannot avoid
doing either, explicitly or implicitly.

There is most definitely no single correct way. The hardware instrument I
mentioned has at least a dozen related parameters. 
The concept ("detector") is subtly different, depending on whether you want
to get for example correct readings on sine waves, or are dealing with
noise-like signals and look at power densities.
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Moving average on PSD - maury - 2012-08-27 10:51:00

On Sunday, August 26, 2012 12:14:59 PM UTC-5, Clay wrote:
> Hi everyone, I have a baseline PSD plot that is running, but I want to do averaging on this
plot. From what I have been reading online, doing the first-order IIR exponential moving average
filter is the way to do it(memory efficient). And the formula for that is y[n] =
alpha*x[n]+(1-alpha)*y[n-1]. And this is better than the FIR approach because FIR requires
storing N copies of the PSD. Computing the basic PSD is straightforward. Assuming we're already
in the frequency domain, it would be something like this: for (i=0;i<size/2;i++){
x=imag^2+real^2; psd[i]=log10(x); } But how exactly do I add the moving average to the psd
function? Can anyone give some hints? Thanks in advance, Clay

Clay,
use y(n) - y(n)*alpha

It works fine, espicially if alpha is a factor of 2 (e.g. 1/256) 

y(n) = y(n-1) - y(n-1) >> 8 + x(n) >> 8 

this gives y[n] = alpha*x[n]+(1-alpha)*y[n-1]. So yours would be

for (i=1;i<size/2;i++){ 
avg_psd[i] = avg_psd[i-1] - avg_psd[i]>>8 + psd[i]>>8;}

You will need to provide the first value for avg_psd. this is usually done by assuming that any
average value before i = 0 is identically 0; Therefore avg_psd[0] is alpha*psd[0].

Maurice
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Moving average on PSD - Eric Jacobsen - 2012-08-27 17:42:00

On Mon, 27 Aug 2012 04:33:16 -0500, "mnentwig" <24789@dsprelated>
wrote:

>>> is the way to do it
>depends on what you want.
>
>With an IIR filter you'll get a skewed (asymmetric) result that would be
>avoided with a symmetric moving-average filter. 

Unless you run it both ways.   Assuming the data has a finite length
the effects of an asymmetric filter can be eliminated by running it
both directions across the data block.   In some cases this is still
faster than user a longer, symmetric FIR.


>If you can afford a delay line of the MA length, you can calculate it with
>two additions : create an accumulator; add any sample that goes into the
>delay line and subtract every one that comes out.
>
>BTW, this piece of code http://www.dsprelated.com/showcode/239.php
>could serve as reference. Used correctly, it shows more or less what you'd
>see on the screen of a hardware spectrum analyzer if the given signal
>repeats periodically. 
>
>

Eric Jacobsen
Anchor Hill Communications
www.anchorhill.com
______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.

Re: Moving average on PSD - robert bristow-johnson - 2012-08-27 18:21:00

On 8/27/12 5:42 PM, Eric Jacobsen wrote:
> On Mon, 27 Aug 2012 04:33:16 -0500, "mnentwig"<24789@dsprelated>
> wrote:
>
>> depends on what you want.
>>
>> With an IIR filter you'll get a skewed (asymmetric) result that would be
>> avoided with a symmetric moving-average filter.
>
> Unless you run it both ways.   Assuming the data has a finite length
> the effects of an asymmetric filter can be eliminated by running it
> both directions across the data block.

i think that there's a name for this in MATLAB as well as some other 
environments: FILTFILT() .

> In some cases this is still faster than user a longer, symmetric FIR.

in most cases, i would think.


-- 

r b-j                  r...@audioimagination.com

"Imagination is more important than knowledge."


______________________________
New DSP Code Snippets Section now Live.   Learn more about the reward program for contributors here.