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


33

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

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


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

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


9

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


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

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


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

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

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


6

In the general case you have $$H(z)=\frac{P(z)}{Q(z)}$$ where $P(z)$ and $Q(z)$ are polynomials in $z$. If - as is the case in your example - $Q(z)$ just has one single term, $H(z)$ is definitely FIR, because you can simply divide each term of $P(z)$ by that respective power of $z$, and the number of terms of $H(z)$ equals the number of terms of $P(z)$. ...


6

Your questions still leave me wondering as to what you're actually designing. For software implementation on modern x86 CPUs, CICs make almost no sense, but they are extremely elegant in hardware. These filter definitions are ridiculous if you're planning to use a FIR – a transition width of 1mHz means that a minimum phase equiripple filter [1, (5.75), p. ...


6

This is just "faking" the magnitude response of an IIR filter. The output's magnitude spectrum looks just like it has been filtered by the IIR filter with the given frequency response. Although it may somehow work, there are some limitations: Frequency-domain filtering is usually much more computationally demanding. It is not for real-time. The problem ...


6

That formula for the cut-off frequency is a very inaccurate approximation. In this answer I derived the exact relation between the coefficient of a first order recursive averaging filter and its 3-dB cut-off frequency. Note that in the quoted answer I used the constant $\alpha=1-b$. From formula $(3)$ in that answer we get for the coefficient $b$ $$b = 2-\...


6

Let's consider a causal IIR filter with the following transfer function: $$H(z)=\frac{B(z)}{A(z)}=\frac{\displaystyle\sum_{n=0}^{M}b[n]z^{-n}}{1+\displaystyle\sum_{n=1}^{N}a[n]z^{-n}}\tag{1}$$ Note that $M$ need not be equal to $N$. Let $K$ be the number of samples that must be removed from the impulse response corresponding to the system $(1)$, so the new ...


6

A causal first-order IIR filter is characterized by the following difference equation: $$y[n]=b_0x[n]+b_1x[n-1]-a_1y[n-1]\tag{1}$$ with $x[n]$ the input signal, and $y[n]$ the output signal. The impulse response of that system can be computed via the $\mathcal{Z}$-transform or otherwise, and it turns out to be $$h[n]=b_0\delta[n]+(-a_1)^{n-1}(b_1-b_0a_1)u[...


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