FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
6669 Discussions

Band Pass filter output data

Altera_Forum
Honored Contributor II
2,929 Views

Hi everyone, 

I use FIR compiler v8.1 to generate a band pass filter 50hz  

Configuration : 

- Input Data unsigned width : 8 bits 

- I use a coef file generated by Matlab  

- coefficients scaling : Auto ... Bit Width : 8 

 

--- Quote Start ---  

 

-0.03758602 

-0.04600525 

-0.05416903 

-0.05998012 

-0.05842221 

-0.04470215 

-0.01824851 

0.01576782 

0.04887938 

0.07399496 

0.08870862 

0.09481480 

0.09481480 

0.08870862 

0.07399496 

0.04887938 

0.01576782 

-0.01824851 

-0.04470215 

-0.05842221 

-0.05998012 

-0.05416903 

-0.04600525 

-0.03758602 

 

--- Quote End ---  

 

and I try to undestand why i have a signed data out ( see image ) 

fir data in/out (http://img190.imageshack.us/img190/9161/firbp.jpg)
0 Kudos
21 Replies
Altera_Forum
Honored Contributor II
1,848 Views

Your coefficients are signed but your input is declared unsigned. I believe this will cause trouble. You can declare your input as signed adding the sign bit = '0' always and see.

0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

one more issue. 

 

You should expect that your output will revert back to signed. The reason is your filter doesn't pass dc. if your input is unsigned it implies dc offset which is filtered off.
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

I can't use signed data in because it's provided from unsigned FIR LP. 

Sorry but I don't understand the relation with DC... In this case, what should i do
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

In that case your input is always treated as positive only i.e. there is dc offset in it (dc equals the mean of the signal). You can remove this by subtraction but better leave it and your bandpass filter will remove the mean. Hence your output will be signed and tending to around zero. There is nothing wrong in this case.

0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

Ok... Thank you

0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

Now with signed filter i have this ( image (http://img200.imageshack.us/img200/1601/firbp2.png) )  

Why the output signal is discontinuous ?
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

You mean your output gets stuck for many samples on same value before it moves to next... 

 

Can you post your input data and output data values and I will get output data through matlab
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

Thanks for your help  

you will find an attachment with input and output data
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

Your output doesn't look right. 

 

your input swings between 0 and 243, yet your output is of +160,000 order with repeated close values.It doesn't look you have done any bit truncations. 

 

Go to matlab and type: 

h = < your above coefficients>; 

x = <your input vector>; 

 

now apply filter: 

y = filter(h,1,x); you should check your results against this as reference 

 

I got an initial y values of +80 followed by +4
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

I got the same thing and i don't know how to resolve the problem!!!!

0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

can you post your FIR Compiler's generated .vhd/.v or a screen shot of the filter setting?

0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

yes i can... I use a signed input data width 9 instead 8 ( sign bit = '0'). 

I tried the same thing with unsigned input data width = 8
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

I have always the same problem with the bandpass filter output signal 

I changed coef more than 20 times.... 

some one can help me please to design a good bandpass 50hz filter 

with the fir compiler 

sample rate 1000hz 

cutoff freq1 : ~ 20 hz  

cutoff freq2 : ~ 60 hz or 70 hz 

number of coef < 30 

data in : unsigned width : 8 bits you can use signed input with 9 bits ( sign ='0')
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

Hi Hayder, 

 

your coefficients(posted at start of this thread) are ok. I checked them in Matlab and your filter does cutoff at .02 and .07 of sampling frequency (passband is 20/1000 to 70/1000). Your problem is not the design of coefficients(that is done). It is in the implementation. You need to check whats going wrong in your FIR compiler settings.
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

In particular make sure that your input data is at 1000Hz, so is your filter and its output.

0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

Hi Kaz, 

this is my config (http://img36.imageshack.us/img36/3730/firconfig.jpg) with coefficients posted at start of this thread 

may be the problem come from coefficients scaling....
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

I don't use fir compiler, so hopefully somebody else may help better. 

It looks ok to me. Though you can choose other structures e.g multipliers(instead of distributed arithmetic, at least for testing), your coefficient width need not be that high(if you wish you may go lower with little or no effect on filter response). Your output resolution need not be different from that of input. 

Again make sure your sampling rate is indeed 1000Hz.
0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

Thanks Kaz for your help

0 Kudos
Altera_Forum
Honored Contributor II
1,848 Views

I'm also not using the FIR compiler, but your results look meaningful. Apparently the test signal as well as the output are sampled with the tenfold of the filter sampling rate, most likely because the test case is for the fully serial FIR compiler option, that uses 10 clocks for a sample. The waveform, you previously posted (and asked, why it's discontinous) shows a 50 Hz sine sampled at 1000 Hz, as requested. 

 

The output scaling comes from selecting "Full resolution" for the output numbering system. Full resolution means something like nInputBits + nCoeffBits + log2(nCoeff), in this case it's 20 Bit, as the Megawizard shows for your design. So everything seems to be in normal operation. 

 

To my opinion, the filter performance is rather bad, particularly the high frequency attenuation. But it's an obvious result of providing too few coefficients for a fs/fc ratio of 20. 

 

There may reasons to use a FIR filter, but I would prefer IIR in this case.
0 Kudos
Altera_Forum
Honored Contributor II
1,799 Views

Thank you  

yes it's an obligation to use FIR :(
0 Kudos
Reply