DSPRelated.com
Forums

Testing FIR filter

Started by smartie_625 December 11, 2007
Hi,

I am doing a low-pass and high-pass 7-tap moving average filter filter
on Xilinx Virtex II Pro FPGA.

I am recording a sound, storing it in DDR RAM and filtering it and
playing it back. But, the output sounds like noise for both low-pass
and high-pass filters. Could someone please let me know what I could
be doing wrong?

Also, how can I calculate the cut-off frequencies for a seven-tap
moving average filter?

I have pasted my code below. I hope it is understandable. Xuint32 is
just a data type pre-defined in Xilinx libraries.

/*************************************************************
Function: low_pass_filter does the low pass 7-point moving average filter
@Param *aBuf: This is the array of 32-bit values stored in DDR RAM
*********************************************************************/
Xuint32* low_pass_filter(Xuint32 *aBuf)
{
//Lowpass:
const int mSamples = SAMPLES;

Xuint32 *mOut; //output buffer

int i;

xil_printf("\r\nBegin loop");

for(i = 6; i {
mOut[i] = aBuf[i+6] + aBuf[i+5] + aBuf[i+4] + aBuf[i+3] + aBuf[i+2]
+ aBuf[i+1] + aBuf[i];
mOut[i] /= 7.0;
}

xil_printf("\r\nEnd loop");

return mOut;
}

/************************************************************
Function: high_pass_filter does the high pass 7-point moving average
filter
@Param *aBuf: This is the array of 32-bit values stored in DDR RAM
*****************************************************************/

Xuint32* high_pass_filter(Xuint32 *aBuf)
{
int mSamples = SAMPLES;

Xuint32 *mOut;//output buffer

int i;

xil_printf("\r\nBegin loop");

for(i = 0; i {
mOut[i] = aBuf[i+6] - aBuf[i+5] + aBuf[i+4] - aBuf[i+3] + aBuf[i+2]
- aBuf[i+1] + aBuf[i];
mOut[i] /= 7.0;
}

xil_printf("\r\nEnd loop");

return mOut;

}

/*****************************************************************
End of code
*****************************************************************/

Thanks,
Abhishek
Hi,
There are 2 issues with this filter

1. If you are sampling sound then you would have both positive and negative samples. So an unsigned int32 datatype is not suitable for storing data.
2. The values will overflow if you do not give enough guard bits. So you might consider dividing by 7.0 before addition. You might as well make it 8 tap filter and shift right the input by 3.

Regards,
Amit
----- Original Message ----
From: smartie_625
To: a...
Sent: Saturday, 8 December, 2007 4:37:18 AM
Subject: [audiodsp] Testing FIR filter

Hi,

I am doing a low-pass and high-pass 7-tap moving average filter filter
on Xilinx Virtex II Pro FPGA.

I am recording a sound, storing it in DDR RAM and filtering it and
playing it back. But, the output sounds like noise for both low-pass
and high-pass filters. Could someone please let me know what I could
be doing wrong?

Also, how can I calculate the cut-off frequencies for a seven-tap
moving average filter?

I have pasted my code below. I hope it is understandable. Xuint32 is
just a data type pre-defined in Xilinx libraries.

/*********** ********* ********* ********* ********* ********* *****
Function: low_pass_filter does the low pass 7-point moving average filter
@Param *aBuf: This is the array of 32-bit values stored in DDR RAM
************ ********* ********* ********* ********* ********* ********* ***/
Xuint32* low_pass_filter( Xuint32 *aBuf)
{
//Lowpass:
const int mSamples = SAMPLES;

Xuint32 *mOut; //output buffer

int i;

xil_printf(" \r\nBegin loop");

for(i = 6; i {
mOut[i] = aBuf[i+6] + aBuf[i+5] + aBuf[i+4] + aBuf[i+3] + aBuf[i+2]
+ aBuf[i+1] + aBuf[i];
mOut[i] /= 7.0;
}

xil_printf(" \r\nEnd loop");

return mOut;
}

/*********** ********* ********* ********* ********* ********* ****
Function: high_pass_filter does the high pass 7-point moving average
filter
@Param *aBuf: This is the array of 32-bit values stored in DDR RAM
************ ********* ********* ********* ********* ********* ********/

Xuint32* high_pass_filter( Xuint32 *aBuf)
{
int mSamples = SAMPLES;

Xuint32 *mOut;//output buffer

int i;

xil_printf(" \r\nBegin loop");

for(i = 0; i {
mOut[i] = aBuf[i+6] - aBuf[i+5] + aBuf[i+4] - aBuf[i+3] + aBuf[i+2]
- aBuf[i+1] + aBuf[i];
mOut[i] /= 7.0;
}

xil_printf(" \r\nEnd loop");

return mOut;

}

/*********** ********* ********* ********* ********* ********* *********
End of code
************ ********* ********* ********* ********* ********* ********/

Thanks,
Abhishek