From: gpezzella on
Hello Jerry,

I have also found this that seem to be recursive and very simply:
http://www.dspguide.com/ch15/5.htm

This is an implementation in VB6:

100 'MOVING AVERAGE FILTER IMPLEMENTED BY RECURSION
'copyright © 1997-1999 by California Technical Publishing
'published with permission from Steven W Smith, www.dspguide.com
'GUI by logix4u , www.logix4u.net
'modified by logix4u, www.logix4.net
110 'This program filters 512 samples with a 101 point moving
120 'average filter, resulting in 4900 samples of filtered data.
130 'A double precision accumulator is used to prevent round-off
drift.
140 '
150 'DIM X[4999] 'X[ ] holds the input signal
160 'DIM Y[4999] 'Y[ ] holds the output signal
170 'DEFDBL ACC 'Define the variable ACC to be double precision
Dim ACC As Double
180 '
190 'GoSub XXXX 'Mythical subroutine to load X[ ]
200 '
210 ACC = 0 'Find Y[50] by averaging points X[0] to X[100]
220 For I% = 1 To 20
230 ACC = ACC + FuncGen.Samples(I%)
240 Next I%
250 outputarray(20) = ACC / 40
260 ' 'Recursive moving average filter (Eq. 15-3)
270 For I% = 21 To 512
280 ACC = ACC + FuncGen.Samples(I% + 20) - FuncGen.Samples(I% - 21)
290 outputarray(I%) = (ACC / 130)
300 Next I%
310 '
320 'End


Since in my program I only:

1)Must chech if signal under 50Hz are present or not.
2)Verify if signal under 50Hz raise a fixed level.

Could I use very simply Moving Average Filter?

If yes could you help me to understand how many sample I must acquire at
2.48kHz and how to choose the very few other parameter of equation?

Many thanks and sorry for my ignorance in this matter




From: Jerry Avins on
On 6/30/2010 10:56 AM, gpezzella wrote:
> Hello Jerry,
>
> I have also found this that seem to be recursive and very simply:
> http://www.dspguide.com/ch15/5.htm
>
> This is an implementation in VB6:
>
> 100 'MOVING AVERAGE FILTER IMPLEMENTED BY RECURSION
> 'copyright © 1997-1999 by California Technical Publishing
> 'published with permission from Steven W Smith, www.dspguide.com
> 'GUI by logix4u , www.logix4u.net
> 'modified by logix4u, www.logix4.net
> 110 'This program filters 512 samples with a 101 point moving
> 120 'average filter, resulting in 4900 samples of filtered data.
> 130 'A double precision accumulator is used to prevent round-off
> drift.
> 140 '
> 150 'DIM X[4999] 'X[ ] holds the input signal
> 160 'DIM Y[4999] 'Y[ ] holds the output signal
> 170 'DEFDBL ACC 'Define the variable ACC to be double precision
> Dim ACC As Double
> 180 '
> 190 'GoSub XXXX 'Mythical subroutine to load X[ ]
> 200 '
> 210 ACC = 0 'Find Y[50] by averaging points X[0] to X[100]
> 220 For I% = 1 To 20
> 230 ACC = ACC + FuncGen.Samples(I%)
> 240 Next I%
> 250 outputarray(20) = ACC / 40
> 260 ' 'Recursive moving average filter (Eq. 15-3)
> 270 For I% = 21 To 512
> 280 ACC = ACC + FuncGen.Samples(I% + 20) - FuncGen.Samples(I% - 21)
> 290 outputarray(I%) = (ACC / 130)
> 300 Next I%
> 310 '
> 320 'End
>
>
> Since in my program I only:
>
> 1)Must chech if signal under 50Hz are present or not.
> 2)Verify if signal under 50Hz raise a fixed level.
>
> Could I use very simply Moving Average Filter?

You could, but it would have poor performance for your application.

> If yes could you help me to understand how many sample I must acquire at
> 2.48kHz and how to choose the very few other parameter of equation?

The number of samples is determined by the sample rate and the duration
of the signal. If you describe the signal you need to process and the
result you want, we might be able to offer some guidance. Grabbing
snippets of code without understanding them won't get you very far. The
code is intended to be illustrations to help the reader understand the
process, not as plug-in components.

What is the nature of the signal that you want to filter?

What do you want your filter to do to the signal?

What departures from the ideal can you tolerate?

Does your processor do floating-point arithmetic? If not, do you
understand the subtleties of fixed-point programming?

Jerry
--
Engineering is the art of making what you want from things you can get.
From: gpezzella on
Hello Jerry,

I have also found this that seem to be recursive and very simply:
http://www.dspguide.com/ch15/5.htm

This is an implementation in VB6:

100 'MOVING AVERAGE FILTER IMPLEMENTED BY RECURSION
'copyright © 1997-1999 by California Technical Publishing
'published with permission from Steven W Smith, www.dspguide.com
'GUI by logix4u , www.logix4u.net
'modified by logix4u, www.logix4.net
110 'This program filters 512 samples with a 101 point moving
120 'average filter, resulting in 4900 samples of filtered data.
130 'A double precision accumulator is used to prevent round-off
drift.
140 '
150 'DIM X[4999] 'X[ ] holds the input signal
160 'DIM Y[4999] 'Y[ ] holds the output signal
170 'DEFDBL ACC 'Define the variable ACC to be double precision
Dim ACC As Double
180 '
190 'GoSub XXXX 'Mythical subroutine to load X[ ]
200 '
210 ACC = 0 'Find Y[50] by averaging points X[0] to X[100]
220 For I% = 1 To 20
230 ACC = ACC + FuncGen.Samples(I%)
240 Next I%
250 outputarray(20) = ACC / 40
260 ' 'Recursive moving average filter (Eq. 15-3)
270 For I% = 21 To 512
280 ACC = ACC + FuncGen.Samples(I% + 20) - FuncGen.Samples(I% - 21)
290 outputarray(I%) = (ACC / 130)
300 Next I%
310 '
320 'End


Since in my program I only:

1)Must chech if signal under 50Hz are present or not.
2)Verify if signal under 50Hz raise a fixed level.

Could I use very simply Moving Average Filter?

If yes could you help me to understand how many sample I must acquire at
2.48kHz and how to choose the very few other parameter of equation?

Many thanks and sorry for my ignorance in this matter




From: gpezzella on
Dear Jerry,

>What is the nature of the signal that you want to filter?
The signal come from MW detector used in house alarm.
When man walk in front of this detector It generate a beat wave from 10- 40
Hz.

>What do you want your filter to do to the signal?
I would low pass filter with 50Hz cut off frequency for separe signal
generate from man that walk from beat generate by bird that fly, car that
move, simply noise ecc

>What departures from the ideal can you tolerate?
I can tolerate very much because I must only measure the amplitude of
filtered signal.
After only frequency less than 50 Hz are been filtered, I fix a level and
check if one of they raise and go over this level(comparator).
In this case alarm will generate a disturbing sound

>Does your processor do floating-point arithmetic? If not, do you
>understand the subtleties of fixed-point programming?
My compiler manage floating point

Many thanx for your help.
You are the first that really are helping me

Giuseppe

From: Jerry Avins on
On 6/30/2010 1:03 PM, gpezzella wrote:
> Dear Jerry,
>
>> What is the nature of the signal that you want to filter?
> The signal come from MW detector used in house alarm.
> When man walk in front of this detector It generate a beat wave from 10- 40
> Hz.
>
>> What do you want your filter to do to the signal?
> I would low pass filter with 50Hz cut off frequency for separe signal
> generate from man that walk from beat generate by bird that fly, car that
> move, simply noise ecc
>
>> What departures from the ideal can you tolerate?
> I can tolerate very much because I must only measure the amplitude of
> filtered signal.

Then you might be able to use a single or two-section exponential
averager (no floating point needed). You can sample as low as 500 Hz to
save processing time. How will you acquire the signal? According to your
previous posts, you will need a gain of about 200 in front of the ADC.
When you do that, you may find that noise dominates. 50 Hz is the
power-line frequency.

> After only frequency less than 50 Hz are been filtered, I fix a level and
> check if one of they raise and go over this level(comparator).
> In this case alarm will generate a disturbing sound
>
>> Does your processor do floating-point arithmetic? If not, do you
>> understand the subtleties of fixed-point programming?
> My compiler manage floating point

You say that you have very little RAM. I hope you have plenty of ROM for
your floating-point code and enough processor speed to both acquire the
samples and run the code. Your question about how many samples you need
shows that you don't understand the nature of what must be done. This is
a real-time system, so you must process each sample as it arrives for as
long as the detector is on. You have been misled by programs that work
on fixed blocks of data and are written to illustrate the filtering process.

> Many thanx for your help.
> You are the first that really are helping me

I'm afraid that I'm not much help. It should be clear to you that you
don't even know enough to ask the right questions. You have to
understand the system before digging into the details.

Jerry
--
Engineering is the art of making what you want from things you can get.