Implementing IIR filter in Excel and VHDL

Status
Not open for further replies.

Meach_bzh

Newbie level 6
Joined
Nov 10, 2009
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Tallinn
Activity points
1,407
Hello,

I want to implement a high-pass butterworth filter of 4th order in VHDL.
To design it, I use Octave and once I find a suitable filter, I write down its coefficients:

a = {1 ; a1 ; a2 ; a3 ; a4}
b = {b0 ; b1 ; b2 ; b3 ; b4}

Then in my VHDL code I use the following equation with the coefficients above:

y[n] = b0.x[n] + b1.x[n - 1] + b2.x[n - 2] + b3.x[n - 3] + b4.x[n - 4]
- a1.y[n - 1] - a2.y[n - 2] - a3.y[n - 3] - a4.y[n - 4]

I simulate it with the same set of data I used in Octave but the results I have is far from the one expected.
So in order to check what I am doing wrong, I open an Excel spreadsheet and apply the same equation with the same set of data and I got pretty much the same result as in my VHDL code.

On the picture below are the different signals, plotted in Excel.


For some reason both the data calculated in Excel and extracted from the VHDL simulation work nicely until approximately the 50th sample and then it get "crazy".
I know that the difference between the data calculated in Excel and extracted from VHDL is due to the accuracy of my signals in my VHDL. But I have no idea why at some point the data start raising exponentially.

Does anyone has idea about why this is happening?


Thanks,


Meach
 

Divergence in the Excel implementation suggests wrong (instable) filter coefficients. In VHDL, it may be an overflow problem as well. It would prefer to see the filter coeffcients and filter specification to determine.
 

Thank you for your answer.
Looking at the VHDL simulation, it doesn't seems to be an overflow problem (at least at the beginning, but after some time as the output value increase very quickly, then there is this problem too).



The sampling frequency is 3200Hz and I am using the following command in Octave to design my filter:
[b,a] = butter (4, 5/1600, 'high');

The coefficients are:
b =
0.98725 -3.94902 5.92353 -3.94902 0.98725
a =
1.00000 -3.97435 5.92337 -3.92369 0.97467
 

The low cutoff frequency involves effectively unreasonable numerical accuracy requirements. As a first step, you can switch to a cascaded dual 2nd order filter. You possibly need to adjust the fixed point coefficients to achiece stability.
 
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…