0
$\begingroup$

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.enter image description hereCode 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

enter image description here

$\endgroup$
7
  • $\begingroup$ 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.) $\endgroup$ Feb 2 at 10:39
  • $\begingroup$ yeah, it's a programming bug: you always add to y(1,1), which makes no sense. $\endgroup$ Feb 2 at 10:39
  • $\begingroup$ 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 :) $\endgroup$ Feb 2 at 10:41
  • $\begingroup$ 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 $\endgroup$
    – Deepa
    Feb 2 at 11:09
  • 1
    $\begingroup$ 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) $\endgroup$
    – Hilmar
    Feb 2 at 12:49

1 Answer 1

3
$\begingroup$

Fixed point processing is complicated. For a more detailed description of the process required see: Fixed point scaling; float -> Q31 -> float

In your specific case the choice of filter structure seems highly questionable. Direct Form II is terrible for fixed implementation since the gain between the input and the state variables can become very large. In your case the max gain appears to be in the order of a whopping 120 dB, so you will need at least 20 guard bits just to prevent your state from clipping.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.