35

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 ...


29

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 ...


20

If you are optimizing for engineering time and are on a platform that supports large FFTs well (i..e not fixed point), then take hotpaw2's advice and use fast convolution. It will perform much better than a naive FIR implementation and should be relatively easy to implement. On the other hand, if you have some time to spend on this to get the best ...


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 ...


13

It's the last thing you said ("Or does the output of the first filter feed as x_in in to the second filter and so on?"). The idea is simple: you treat the biquads as separate second-order filters that are in cascade. The output from the first filter is the input to the second, and so on, so the delay lines are spread out among the filters. If you need to ...


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

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

I'm not sure exactly what you're looking for. As you noted in your question, the transfer functions of the Butterworth filter family are well-understood and easily calculated analytically. It is pretty simple to implement a Butterworth filter structure that is tunable by filter order and cutoff frequency: Based on the selected filter order, cutoff frequency,...


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

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,...


9

A little dated but may deserve a more comprehensive answer, especially since Direct Form II can get you into a lot of trouble. First of all, there is no "one size fits all" and the best choice depends on your specific application and constraints. What you can consider is Memory: Direct Form II and Transposed Form II take a little less state memory then ...


9

First of all, a bit from wikipedia on Direct Form I and II implementation. Direct form I requires more memory, but is a somewhat simpler strategy, and is less likely to have round-off and resonance problems. Direct form II requires less memory, but it has the potential for unusual interactions, larger numbers, and more round off error. Much of this can be ...


9

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 ...


9

There are actually two ways to implement second order sections: parallel and serial. In the serial version, the outputs of section N are the inputs to section N+1. In the parallel version all sections have the same input (and only one real zero instead of a conjugate complex pair of zeros) and each sections output is simply summed up. The two methods are ...


9

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

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

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

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

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

Try an overlap add/save convolution filter with the longest FFT/IFFT that fits your latency and computational performance constraints. You can design extremely long FIR filters when using this method with even longer FFTs. If you can FFT the entire song, or your entire audio signal file, in one very long FFT+IFFT (there are special FFT algorithms for long ...


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}{...


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