# Tag Info

37

OK, I'll try to answer your questions: Q1: the number of taps is not equal the to the filter order. In your example the filter length is 5, i.e. the filter extends over 5 input samples [$x(n), x(n-1), x(n-2), x(n-3), x(n-4)$]. The number of taps is the same as the filter length. In your case you have one tap equal to zero (the coefficient for $x(n-1)$), so ...

30

filtfilt is zero-phase filtering, which doesn't shift the signal as it filters. Since the phase is zero at all frequencies, it is also linear-phase. Filtering backwards in time requires you to predict the future, so it can't be used in "online" real-life applications, only for offline processing of recordings of signals. lfilter is causal forward-in-time ...

17

Digital filter design is a very large and mature topic and - as you've mentioned in your question - there is a lot of material available. What I want to try here is to get you started and to make the existing material more accessible. Instead of digital filters I should actually be talking about discrete-time filters because I will not consider coefficient ...

16

OK, let's try to derive the best: $$\begin{array}{lcl} y[n] &=& \alpha x[n] + (1 - \alpha) y[n - 1] \\ &=& \alpha x[n] + (1 - \alpha) \alpha x[n-1] + (1 - \alpha)^2 y[n - 2]\\ &=& \alpha x[n] + (1 - \alpha) \alpha x[n-1] + (1 - \alpha)^2 \alpha x[n-2] + (1 - \alpha)^3 y[n - 3]\\ \end{array}$$ so that the coefficient of $x[n-m]$ is ...

16

There's a nice discussion of this problem in Embedded Signal Processing with the Micro Signal Architecture, roughly between pages 63 and 69. On page 63, it includes a derivation of the exact recursive moving average filter (which niaren gave in his answer), $$H(z) = { 1 \over{N} } { 1 - z^{-N} \over { 1 - z^{-1} } }.$$ For convenience with respect to ...

11

My favorite "Rule of thumb" for the order of a low-pass FIR filter is the "fred harris rule of thumb": $N=[f_s/delta(f)]*[atten(dB)/22]$ where delta(f) is the transition band, in same units of $f_s$ $f_s$ is the sample rate of the filter atten(dB) is the target rejection in dB For example if you have a transition band of 100 Hz in a system sampled at 1KHz,...

10

You are correct. FFT based processing adds inherent latency to your system. However there are ways to tweak this. Let's assume you have an FIR filter of length "N". This can be implement FFT-based using the standard overlap add or overlap save method, where the FFT length would be 2*N. Overall system latency will also be roughly 2*N: you need to accumulate ...

10

There is no analytic solution for $\alpha$ being a scalar (I think). Here is a script that gives you $\alpha$ for a given $K$. If you need it online you can build a LUT. The script finds the solution that minimizes $$\int_{0}^{\pi} dw \quad \left|H_1(jw) - H_2(jw)\right|^2$$ where $H_1$ is the FIR frequency response and $H_2$ is the IIR frequency ...

10

If linear phase is a requirement, that will probably steer you toward an FIR implementation. It is possible to build IIR filters that have approximate linear phase, but it is easy to design a linear-phase FIR. If you're concerned about latency, forward-backward filtering as in filtfilt isn't really a good option. In general, it's really meant to be used an ...

10

what is fraction saving? can you write a code.so that i can understand more clearly? Let's call the quantizer operator $\operatorname{Quant}\{\cdot\}$ . So the output of the quantizer, with $v[n]$ going in, is $$y[n] = \operatorname{Quant}\{ v[n] \}$$ which we shall model as an additive error source: $$y[n] = v[n] + q[n]$$ No matter how the ...

10

Note that for stable IIR filters, the impulse response does approach zero as $n$ goes to infinity. It just never becomes exactly zero. However, the sum of the absolute values is finite. Just as an example, take the exponential impulse response $$h[n]=a^nu[n],\qquad |a|<1\tag{1}$$ where $u[n]$ is the unit step function. The sum $$\sum_{n=-\infty}^{\... 8 This isn't really a MATLAB-specific issue; I see a couple more general questions: How do you implement a digital IIR filter? You can apply any general digital filter by convolving its impulse response with the signal that you want to filter. That looks like:$$ y[n] = \sum_{k=0}^{N-1} x[k] h[n-k] $$This works great for FIR filters, but you run into ... 8 Although this seems like a remarkably simple questions, it requires a remarkably complicated answer. I don't think there is a "one-size" fits all solution. The best choice of algorithm will depend on what noise you can tolerate and the type of low pass (steepness & frequency). For example at 44.1 KHz sample rate a 4th order Butterworth at 10 kHz is ... 8 The Butterworth filter's frequency response is the result of specific formulas and its characteristic is the flat passband frequency response. Consequently, if the coefficients of the IIR filter are modified in any way, the filter might not maintain the "Butterworth" characteristics. In addition to the responses by "Hilmar" and "Jason R", maybe you could ... 8 The frequency response of a single FFT bin filter looks like a Sinc function, which has a massive amount of overshoot or ripple at frequencies between FFT bins. So your filter is only useful if you can strictly guarantee that the input to the FFT only contains unmodulated frequencies that are strictly and exactly periodic in the FFT aperture length (e.g. ... 8 In more standard DSP terms, you have the following filter:$$ y[n] = (1-a) x[n] + a y[n-1] $$where x[n] and y[n] are the input and output signals at time n respectively. The transfer function (which you didn't ask for) is:$$ H(z) = \frac{1-a}{1 - az^{-1}} $$so here is your single pole, at z=a in the complex plane. This filter is also known as ... 8 The two solutions in a floating point implementation are assumed to be identical, with the two BiQuads being a factored version of the standard difference equation. The BiQuad is the better way to go for fixed point as you isolate two 2nd order systems and in doing so will be easier to keep stable under variations due to the quantization involved. For more ... 7 If you apply two filters in a series cascade, then the behavior of the cascade can be expressed in two different ways. In the time domain, the overall system's impulse response can be calculated by convolving the impulse responses of y[n] and y_2[n] together. For IIR filters, this can be somewhat cumbersome. In the frequency domain, the overall system's ... 7 Answer by @endolith is complete and correct! Please read his post first, and then this one in addition to it. Due to my low reputation I was unable to respond to comments where @Thomas Arildsen and @endolith argue about effective order of filter obtained by filtfilt: lfilter does apply given filter and in Fourier space this is like applying filter transfer ... 7 I would say that the answer to your question - if taken literally - is 'no', there is no general way to simply convert an FIR filter to an IIR filter. I agree with RBJ that one way to approach the problem is to look at the FIR filter's impulse response and use a time domain method (such as Prony's method) to approximate that impulse response by an IIR ... 7 The given single-pole IIR filter is also called exponentially weighted moving average (EWMA) filter, and it is defined by the following difference equation:$$y[n]=\alpha x[n]+(1-\alpha)y[n-1],\qquad 0<\alpha<1\tag{1}$$Its transfer function is$$H(z)=\frac{\alpha}{1-(1-\alpha)z^{-1}}\tag{2}$$The exact formula for the required value of \alpha ... 7 Short answer: You can't. If an attacker can insert a signal that covers the whole bandwidth (e.g. a white signal, or at least one that has no spectral zeros) into the system (and he can do that over an arbitrarily long time, or add up observations), they will get an output, and can through the magic of correlation get the impulse response. 6 Here is a little bit of demo code to show why you are better off cascading 2nd order sections. clc sr = 44100; order = 13; [b,a] = butter(order,1000/(sr/2),'low'); [sos] = tf2sos(b,a); x = [1; zeros(299,1)]; %impulse % all in one Y = filter(b,a,x); % cascaded biquads Z = x; for nn = 1:size(sos,1); Z = filter(sos(nn,1:3),sos(nn,4:6), Z ); end cla; ... 6 Assuming that you perform vector operations M elements at a time, you can unroll the difference equation by a factor of M pretty easily for the simple single-pole filter. Assume that you have already calculated all outputs up to y[n]. Then, you can calculate the subsequent ones as follows:$$ \begin{align} y[n+1] &= (1-a)y[n] + ax[n+1] \\ y[n+2] ...

6

There is no magic bullet, I'm afraid. You can use an elliptic filter to independently control pass band ripple and stop band attenuation, however you will find that the decay rate is closely related to the steepness and overall bandwidth of the filter. You can make the filter decay drastically faster by reducing the filter order to 1, but then again the ...

6

The frequency response of the two complementary filters are $H_2(e^{j\theta}) = 1 - H_1(e^{j\theta})$, or the impulse responses $h_2[n] = \delta[n] - h_1[n]$. For an IIR filter, $H_1(z)$ can be written as $\frac{b_0 + b_1 z^{-1} + \ldots}{a_0 + a_1 z^{-1} + \ldots}$. Then $H_2(z)$ should be something like $\frac{(a_0 - b_0) + (a_1 - b_1) z^{-1} + \ldots}{... 6 Unstable typically means and unbounded output for a bounded input. In other words the output of, say , a filter can get infinitely large although the input is perfectly okay and of "normal" size. A simple example would be the difference equation$y[n] = x[n] + y[n-1]$. If we calculate the step response, i.e.$x[n] = u[n]$, we get y[0] = 1, y[1] = 2, y[2] = ... 6 Peter's correct. at least if fixed-point arithmetic is used. the DF2 has poles before zeros. that means the signal is getting boosted by the poles before the zeros (which are often sitting very close to the poles) beat the gain back down to reasonable levels. so if the signal overflows, saturates, and distorts due to this gain, the attenuation offered by ... 6 If the Z-transform of the feedforward section is divisible by the Z-transform of the feedback section, the filter is FIR. Consider your example:$y[n] = y[n-1] + x[n] - x[n-3]$. The Z-transform is$\mathrm Y(z)- z^{-1}\mathrm Y(z) = \mathrm X(z) - z^{-3}\mathrm X(z)$, and the Z-transform of the response is$\mathrm H(z) = \mathrm Y(z)/\mathrm X(z) = (1 - z^...

6

As you have already pointed out in your question, it is not possible (without using optimization methods) to compute an exact L2 solution for the frequency domain design problem of IIR filters due to the non-linear relationship between the filter coefficients and the error function. There is, however, a method which can come close and which transforms the ...

Only top voted, non community-wiki answers of a minimum length are eligible