# Fixed point implementation of IIR filter

I am trying to implement an IIR filter followed by downsampler with the following specifications:

   fs=18000,order=8,3db freq=[500 1000],downsampling factor=6.


First I have designed the filter using inbuilt function ,then downsampled by a factor of 6 and gave a sine wave of frequency 700Hz as input to the filter to plot the output response. Now I have used the IIR decimator filter model to implement the system as shown in figure. Code is as shown below:

Now to convert it into fixed point representation, I have scaled the filter coefficients and then rounded out and tried to implement the difference equation .Now when I plotted the response, the system is becoming unstable • This ludicrous looks more like a coding bug than a signal processing question, and I haven't even read your code (which you did not properly format using the code-formatting button labeled {} in your question editor. Please do that – not your first question.) Feb 2 at 10:39
• yeah, it's a programming bug: you always add to y(1,1), which makes no sense. Feb 2 at 10:39
• Also: You rounded the coefficients – But you're still doing the math in floating point. Floating point loses precision when you add a small value to a large value, and that can destabilize a filter. However, this is really just a bughunt question. You should have found that when you were stepping through your program using matlab's debugger, or when plotting the coefficients over iteration in an attempt to figure out when it starts to destabilize. So, this really more or less boils down to debugging your own code better :) Feb 2 at 10:41
• I don't understand what is wrong in adding to y(1,1). This is direct form 2 equation implementation .y(1,1) is always overwritten with the new value Feb 2 at 11:09
• That doesn't look like a real fixed point simulation. What are your word sizes? Can you use real Matlab fixed point types? (int32 for example) Feb 2 at 12:49