DSPRelated.com
Forums

Testing FIR filter

Started by Rockerboy December 7, 2007
Hi,

I am new to DSP. 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<mSamples-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<mSamples-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;

}

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

Thanks,
Abhishek
Rockerboy wrote:
(snip)

> 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?
(snip)
> Xuint32* low_pass_filter(Xuint32 *aBuf) > { > //Lowpass: > const int mSamples = SAMPLES; > Xuint32 *mOut; //output buffer
Assuming this is C, which is what it looks like, you have to assign some value to a pointer variable before you use it. Either newly allocated, or a pointer to existing memory. -- glen
On Dec 7, 5:51 pm, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:
> > > Xuint32* low_pass_filter(Xuint32 *aBuf) > > { > > //Lowpass: > > const int mSamples = SAMPLES; > > Xuint32 *mOut; //output buffer > > Assuming this is C, which is what it looks like, you have to assign > some value to a pointer variable before you use it. Either newly > allocated, or a pointer to existing memory. > > -- glen
It is C. I tried assigning the output buffer to DDR RAM. Xuint32 *mBuf = (Xuint32*)DDR_ADDR2; //input buffer. SAMPLES is the no. of samples Xuint32 *mOut = (Xuint32*)DDR_ADDR2 + SAMPLES*4; //output buffer But I am getting the same result. Thanks, Abhishek
On Dec 7, 6:41 pm, Rockerboy <rka...@gmail.com> wrote:
> On Dec 7, 5:51 pm, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote: > > > > > > Xuint32* low_pass_filter(Xuint32 *aBuf) > > > { > > > //Lowpass: > > > const int mSamples = SAMPLES; > > > Xuint32 *mOut; //output buffer > > > Assuming this is C, which is what it looks like, you have to assign > > some value to a pointer variable before you use it. Either newly > > allocated, or a pointer to existing memory. > > > -- glen > > It is C. I tried assigning the output buffer to DDR RAM. > > Xuint32 *mBuf = (Xuint32*)DDR_ADDR2; //input buffer. SAMPLES > is the no. of samples > Xuint32 *mOut = (Xuint32*)DDR_ADDR2 + SAMPLES*4; //output buffer > > But I am getting the same result. > > Thanks, > Abhishek
Th problem was that I was having a 32 bit input buffer and 32 bit output buffer.So, when I did the filtering, I was getting an overflow. I changed my input buffer to 16 bits and now its working! -Abhishek
Rockerboy wrote:

> On Dec 7, 5:51 pm, glen herrmannsfeldt <g...@ugcs.caltech.edu> wrote:
>>>Xuint32* low_pass_filter(Xuint32 *aBuf) >>>{ >>> //Lowpass: >>> const int mSamples = SAMPLES; >>> Xuint32 *mOut; //output buffer
>>Assuming this is C, which is what it looks like, you have to assign >>some value to a pointer variable before you use it. Either newly >>allocated, or a pointer to existing memory.
> It is C. I tried assigning the output buffer to DDR RAM.
> Xuint32 *mBuf = (Xuint32*)DDR_ADDR2; //input buffer. SAMPLES > is the no. of samples > Xuint32 *mOut = (Xuint32*)DDR_ADDR2 + SAMPLES*4; //output buffer
> But I am getting the same result.
Again, assuming C you should add SAMPLES, not SAMPLES*4, as C knows to multiply by four (bytes). Assuming the DDR RAM is big enough, that should still work, though. -- glen