DSPRelated.com
Forums

sync filter: Can you help me to set 3 parameter?

Started by gpezzella June 29, 2010
Hello 
I'm implementing windowed sync low pass filter on atmega64.
I'm sampling at 2.48khz and need to cut off all frequency over 50Hz. 

Can you help me to set this 3 parameter? Thanks

1)M
2)FC
3)Number of Sample 

Here the link of source code:
http://logix4u.net/DSP/Digital_Filters/Windowed_sinc_filter.html

Here the code:
110 'This program filters 5000 samples with a 101 point windowed-sinc
filter,
120 'resulting in 4900 samples of filtered data.
130 '
140 'DIM X[4999] 'X[ ] holds the input signal --> FuncGen.Samples(j% - I%)
150 'DIM Y[4999] 'Y[ ] holds the output signal --> outputarray(j%)
160 'DIM H[100] 'H[ ] holds the filter kernel --> Kernel
170 '
180 PI = 3.14159265
190 FC = Val(Text1.Text)  'Set the cutoff frequency (between 0 and 0.5)
200 M% = 32 'Set filter length (101 points)
210 '
220 'GoSub XXXX 'Mythical subroutine to load X[ ]
230 '
240 ' 'Calculate the low-pass filter kernel via Eq. 16-4
250 For I% = 0 To 31
260 If (I% - M% / 2) = 0 Then kernel(I%) = 2 * PI * FC
270 If (I% - M% / 2) <> 0 Then kernel(I%) = Sin(2 * PI * FC * (I% - M% /
2)) / (I% - M% / 2)
280 kernel(I%) = kernel(I%) * (0.54 - 0.46 * Cos(2 * PI * I% / M%))
290 Next I%
300 '
310 Sum = 0 'Normalize the low-pass filter kernel for
320 For I% = 0 To 31 'unity gain at DC
330 Sum = Sum + kernel(I%)
340 Next I%
350 '
360 For I% = 0 To 31
370 kernel(I%) = kernel(I%) / Sum
380 Next I%
390 '
400 For j% = 31 To 512 'Convolve the input signal & filter kernel
410 outputarray(j%) = 0
420 For I% = 0 To 31
430 outputarray(j%) = outputarray(j%) + FuncGen.Samples(j% - I%) *
kernel(I%)
440 Next I%
450 Next j%
460 '
470 'End
On 6/29/2010 7:11 AM, gpezzella wrote:
> Hello > I'm implementing windowed sync low pass filter on atmega64. > I'm sampling at 2.48khz and need to cut off all frequency over 50Hz. > > Can you help me to set this 3 parameter? Thanks > > 1)M > 2)FC > 3)Number of Sample
This will make an inferior filter that must process more taps to get the same performance as one designed a good program. You don't say what M and FC are. I can guess, but I don't know unless you say. Try to use something like http://www.dsptutor.freeuk.com/remez/RemezFIRFilterDesign.html. The cutoff frequency is specified as a fraction of the sample frequency. Even when using a cookbook, you need to know what "stir" means. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Hi Jerry, 

for first many thanks for your reply.

M set the filter lenght
FC set the Cut Off Frequency from [0 to 0.5]
Number of Sample are the sample acquired 

Please look here: http://www.dspguide.com/ch16/4.htm for more detail

I'm sampling at 2.48khz and need to cut off all frequency over 50Hz.
Note that I have few ram memory on my microprocessor,.

Thanks
Hi Jerry, 

for first many thanks for your reply.

M set the filter lenght
FC set the Cut Off Frequency from [0 to 0.5]
Number of Sample are the sample acquired 

Please look here: http://www.dspguide.com/ch16/4.htm for more detail

I'm sampling at 2.48khz and need to cut off all frequency over 50Hz.
Note that I have few ram memory on my microprocessor,.

Thanks
On 6/30/2010 4:04 AM, gpezzella wrote:
> Hi Jerry, > > for first many thanks for your reply. > > M set the filter lenght > FC set the Cut Off Frequency from [0 to 0.5] > Number of Sample are the sample acquired
The design of this type of filter doesn't depend on the number of samples acquired. That's an implementation decision for batch processing.
> Please look here: http://www.dspguide.com/ch16/4.htm for more detail
I have the book. I recognized the code.
> I'm sampling at 2.48khz and need to cut off all frequency over 50Hz. > Note that I have few ram memory on my microprocessor,.
You can't "cut off all frequency over 50Hz." You can greatly attenuate them, and you have to know by how much in order to design the filter. You also need to know how much ripple you can tolerate in the passband. In short, you need to know what filters can and cannot do in order to go about designing one. It is not enough to cut off frequencies over 50Hz. You must also deal with those below. Look at line 160 and 200 in the source code. They define the length. Look at line 220. Repeated for reference: 220 'GoSub XXXX 'Mythical subroutine to load X[ ] How do you turn the myth to reality? The program I pointed you to will produce a better filter kernel than windowed sinc. By "better", I mean that the same filter specifications can usually be met with a smaller kernel. Unless you need a linear phase response, you can make better use of your processor's limited resources with a recursive filter. Look in Chapter 19. There are valuable tutorials at http://www.bores.com/courses/intro/index.htm Jerry -- Engineering is the art of making what you want from things you can get.
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 &copy; 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 


 

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 &copy; 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.
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 &copy; 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 


 

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
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.