From: gpezzella on
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
From: Jerry Avins on
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.
�����������������������������������������������������������������������
From: gpezzella on
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
From: gpezzella on
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
From: Jerry Avins on
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.