`Filters`

- filter design and filtering

DSP.jl differentiates between filter coefficients and stateful filters. Filter coefficient objects specify the response of the filter in one of several standard forms. Stateful filter objects carry the state of the filter together with filter coefficients in an implementable form (`PolynomialRatio`

, `Biquad`

, or `SecondOrderSections`

). When invoked on a filter coefficient object, `filt`

does not preserve state.

## Filter coefficient objects

DSP.jl supports common filter representations. Filter coefficients can be converted from one type to another using `convert`

.

Missing docstring for `ZeroPoleGain`

. Check Documenter's build log for details.

Missing docstring for `PolynomialRatio`

. Check Documenter's build log for details.

Missing docstring for `Biquad`

. Check Documenter's build log for details.

Missing docstring for `SecondOrderSections`

. Check Documenter's build log for details.

These filter coefficient objects support the following arithmetic operations: inversion (`inv`

), multiplication (`*`

) for series connection, and integral power (`^`

) for repeated mutlpilcation with itself. For example:

```
julia> H = PolynomialRatio([1.0], [1.0, 0.3])
PolynomialRatio{:z, Float64}(Polynomials.LaurentPolynomial(1.0), Polynomials.LaurentPolynomial(0.3*z⁻¹ + 1.0))
julia> inv(H)
PolynomialRatio{:z, Float64}(Polynomials.LaurentPolynomial(0.3*z⁻¹ + 1.0), Polynomials.LaurentPolynomial(1.0))
julia> H * H
PolynomialRatio{:z, Float64}(Polynomials.LaurentPolynomial(1.0), Polynomials.LaurentPolynomial(0.09*z⁻² + 0.6*z⁻¹ + 1.0))
julia> H^2
PolynomialRatio{:z, Float64}(Polynomials.LaurentPolynomial(1.0), Polynomials.LaurentPolynomial(0.09*z⁻² + 0.6*z⁻¹ + 1.0))
julia> H^-2
PolynomialRatio{:z, Float64}(Polynomials.LaurentPolynomial(0.09*z⁻² + 0.6*z⁻¹ + 1.0), Polynomials.LaurentPolynomial(1.0))
```

## Stateful filter objects

Missing docstring for `DF2TFilter`

. Check Documenter's build log for details.

DSP.jl's `FIRFilter`

type maintains state between calls to `filt`

, allowing you to filter a signal of indefinite length in RAM-friendly chunks. `FIRFilter`

contains nothing more that the state of the filter, and a `FIRKernel`

. There are five different kinds of `FIRKernel`

for single rate, up-sampling, down-sampling, rational resampling, and arbitrary sample-rate conversion. You need not specify the type of kernel. The `FIRFilter`

constructor selects the correct kernel based on input parameters.

Missing docstring for `FIRFilter`

. Check Documenter's build log for details.

## Filter application

Missing docstring for `filt`

. Check Documenter's build log for details.

Missing docstring for `filt!`

. Check Documenter's build log for details.

Missing docstring for `filtfilt`

. Check Documenter's build log for details.

Missing docstring for `fftfilt`

. Check Documenter's build log for details.

Missing docstring for `fftfilt!`

. Check Documenter's build log for details.

Missing docstring for `tdfilt`

. Check Documenter's build log for details.

Missing docstring for `tdfilt!`

. Check Documenter's build log for details.

Missing docstring for `resample`

. Check Documenter's build log for details.

## Filter design

Most analog and digital filters are constructed by composing response types, which determine the frequency response of the filter, with design methods, which determine how the filter is constructed. The response type is `Lowpass`

, `Highpass`

, `Bandpass`

or `Bandstop`

and includes the edges of the bands. The design method is `Butterworth`

, `Chebyshev1`

, `Chebyshev2`

, `Elliptic`

, or `FIRWindow`

, and includes any necessary parameters for the method that affect the shape of the response, such as filter order, ripple, and attenuation. Filter order estimation methods are available in `buttord`

, `cheb1ord`

, `cheb2ord`

, and `ellipord`

if the corner frequencies for different IIR filter types are known. `remezord`

can be used for an initial FIR filter order estimate.

Missing docstring for `analogfilter`

. Check Documenter's build log for details.

Missing docstring for `digitalfilter`

. Check Documenter's build log for details.

For some filters, the design method is more general or inherently implies a response type; these direct design methods include `remez`

which designs equiripple FIR filters of all types, and `iirnotch`

which designs a 2nd order "biquad" IIR notch filter.

### Filter response types

Missing docstring for `Lowpass`

. Check Documenter's build log for details.

Missing docstring for `Highpass`

. Check Documenter's build log for details.

Missing docstring for `Bandpass`

. Check Documenter's build log for details.

Missing docstring for `Bandstop`

. Check Documenter's build log for details.

### Filter design methods

#### IIR filter design methods

Missing docstring for `Butterworth`

. Check Documenter's build log for details.

Missing docstring for `Chebyshev1`

. Check Documenter's build log for details.

Missing docstring for `Chebyshev2`

. Check Documenter's build log for details.

Missing docstring for `Elliptic`

. Check Documenter's build log for details.

### Filter order estimation methods

#### IIR filter order estimation methods

Missing docstring for `buttord`

. Check Documenter's build log for details.

Missing docstring for `cheb1ord`

. Check Documenter's build log for details.

Missing docstring for `cheb2ord`

. Check Documenter's build log for details.

Missing docstring for `ellipord`

. Check Documenter's build log for details.

#### FIR filter order estimation methods

Missing docstring for `remezord`

. Check Documenter's build log for details.

#### FIR filter design methods

Missing docstring for `FIRWindow`

. Check Documenter's build log for details.

### Direct filter design methods

Missing docstring for `remez`

. Check Documenter's build log for details.

Missing docstring for `iirnotch`

. Check Documenter's build log for details.

## Filter response

Missing docstring for `freqresp`

. Check Documenter's build log for details.

Missing docstring for `phaseresp`

. Check Documenter's build log for details.

Missing docstring for `grpdelay`

. Check Documenter's build log for details.

Missing docstring for `impresp`

. Check Documenter's build log for details.

Missing docstring for `stepresp`

. Check Documenter's build log for details.

## Miscellaneous

Missing docstring for `coefb`

. Check Documenter's build log for details.

Missing docstring for `coefa`

. Check Documenter's build log for details.

## Examples

Construct a 4th order elliptic lowpass filter with normalized cutoff frequency 0.2, 0.5 dB of passband ripple, and 30 dB attentuation in the stopband and extract the coefficients of the numerator and denominator of the transfer function:

```
responsetype = Lowpass(0.2)
designmethod = Elliptic(4, 0.5, 30)
tf = convert(PolynomialRatio, digitalfilter(responsetype, designmethod))
numerator_coefs = coefb(tf)
denominator_coefs = coefa(tf)
```

Filter the data in `x`

, sampled at 1000 Hz, with a 4th order Butterworth bandpass filter between 10 and 40 Hz:

```
responsetype = Bandpass(10, 40; fs=1000)
designmethod = Butterworth(4)
filt(digitalfilter(responsetype, designmethod), x)
```

Filter the data in `x`

, sampled at 50 Hz, with a 64 tap Hanning window FIR lowpass filter at 5 Hz:

```
responsetype = Lowpass(5; fs=50)
designmethod = FIRWindow(hanning(64))
filt(digitalfilter(responsetype, designmethod), x)
```

Estimate a Lowpass Elliptic filter order with a normalized passband cutoff frequency of 0.2, a stopband cutoff frequency of 0.4, 3 dB of passband ripple, and 40 dB attenuation in the stopband:

`(N, ωn) = ellipord(0.2, 0.4, 3, 40)`