40

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


38

You can best look at it in the frequency domain. If $x[n]$ is the input sequence and $h[n]$ is the filter's impulse response, then the result of the first filter pass is $$X(e^{j\omega})H(e^{j\omega})$$ with $X(e^{j\omega})$ and $H(e^{j\omega})$ the Fourier transforms of $x[n]$ and $h[n]$, respectively. Time reversal corresponds to replacing $\omega$ by $-\...


36

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


23

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


18

This is the FIR filter, although it looks like an IIR. If you calculate the coefficients you get finite impulse response: $h=[1]$ This happens due to zero-pole cancellation: $Y(z)-0.5Y(z)z^{-1}=X(z)-0.5X(z)z^{-1}$ $H(z)=\dfrac{Y(z)}{X(z)}=\dfrac{1-0.5z^{-1}}{1-0.5z^{-1}}=1 $ Yes, it can be tricky. Seeing $y[n-k]$ coefficients in LCCDE (Linear Constant ...


17

I found this video to be very, very helpful (it elaborates on Matt's answer). Here are some key ideas from the video: Zero-phase will result in no phase distortion, but will result in a non-causal filter. This means that if the data is being filtered as it's gathered, this will not be an option (only valid for stored data which we can post-process). When ...


15

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


14

Jojek's answer is of course correct. I would just like to add some more information because much too often have I seen the terms "IIR" and "recursive" confused. The following implications always hold: $$\begin{align}\text{IIR}& \Longrightarrow\text{recursive}\\ \text{non-recursive}&\Longrightarrow\text{FIR}\end{align}$$ i.e. every IIR filter (i.e. ...


12

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


11

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


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


9

The result will indeed be a high pass filter. From your difference equation, the transfer function of the low pass filter is $$H_l(z)=\frac{\beta}{1-(1-\beta)z^{-1}}\tag{1}$$ with $\beta=1/\alpha$. Note that this is actually a leaky integrator, not a classic low pass filter, because its frequency response does not have a zero at Nyquist. The high pass ...


9

The system $$y[n]=y[n-1]+x[n]\tag{1}$$ is an ideal accumulator, i.e., it computes the cumulative sum of the input samples: $$y[n]=\sum_{k=-\infty}^nx[k]\tag{2}$$ It is in a way analogous to a continuous-time integrator, but this doesn't mean that you will necessarily obtain an ideal integrator by transforming the discrete-time system to a continuous-time ...


9

This depends a lot on how you implement it. A single biquad takes about 10 arithmetic operations. (To be precise a Transposed Form II takes 4-5 multiplies and 3 adds, depending on how the gain management is done). Arithmetic operation translates into clock cycles of your processor. That depends a lot on the efficiency of your instruction set and how good yo ...


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

You've designed a causal filter with a notch at $\omega_0=100\pi$. But the result is probably not what you want. Note that you've designed an FIR (finite impulse response) filter. Its frequency response has a large overshoot towards high frequencies. What you actually want is an IIR filter, with poles away from the origin of the complex $z$-plane. A simple ...


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

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


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


8

The frequency response of a real-valued discrete-time system with linear phase has the form $$H(e^{j\omega})=A(\omega)e^{-j\omega\tau},\qquad\omega\in [-\pi,\pi]\tag{1}$$ where $A(\omega)$ is either a real-valued even function or a purely imaginary odd function, and $\tau$ is some real-valued parameter (the delay). If $A(\omega)$ is purely imaginary, then ...


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

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


7

What you do in step 1 is simply truncate the infinite impulse response to approximate it by an FIR filter. If you use sufficiently many filter taps, the approximation becomes arbitrarily accurate. This means that the resulting FIR filter approximates the magnitude and the phase characteristic of the original IIR filter. So with this approach the phase will ...


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.


7

Yes, Butterworth are IIR. The decay from an impulse technically lasts forever. Yes, all [implementable] IIR are causal. Yes, because of #1 and #2. Don't use signal.filtfilt. Use signal.lfilter. filtfilt does the same thing as lfilter, except twice, in opposite directions, which changes a causal filter into a zero-phase filter. However, as the ...


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

FDLS requires a causal frequency response. Your prototype frequency response has zero phase everywhere, which is most definitely not causal. An IIR filter order of 50 is humongous. When FDLS has too many poles and zeroes available, it "tries" to cancel excess poles with excess zeroes. Unfortunately, due to numerical limitations, the cancellation is often ...


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