fir2 {gsignal}R Documentation

Frequency sampling-based FIR filter design

Description

Produce a FIR filter with arbitrary frequency response over frequency bands.

Usage

fir2(n, f, m, grid_n = 512, ramp_n = NULL, window = hamming(n + 1))

Arguments

n

filter order (1 less than the length of the filter).

f

vector of frequency points in the range from 0 to 1, where 1 corresponds to the Nyquist frequency. The first point of f must be 0 and the last point must be 1. f must be sorted in increasing order. Duplicate frequency points are allowed and are treated as steps in the frequency response.

m

vector of the same length as f containing the desired magnitude response at each of the points specified in f.

grid_n

length of ideal frequency response function. grid_n defaults to 512, and should be a power of 2 bigger than n.

ramp_n

transition width for jumps in filter response (defaults to grid_n / 20). A wider ramp gives wider transitions but has better stopband characteristics.

window

smoothing window. The returned filter is the same shape as the smoothing window. Default: hamming(n + 1).

Details

The function linearly interpolates the desired frequency response onto a dense grid and then uses the inverse Fourier transform and a Hamming window to obtain the filter coefficients.

Value

The FIR filter coefficients, a vector of length n + 1, of class Ma.

Author(s)

Paul Kienzle, pkienzle@users.sf.net.
Conversion to R Tom Short,
adapted by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

See Also

Ma, filter, fftfilt, fir1

Examples

f <- c(0, 0.3, 0.3, 0.6, 0.6, 1)
m <- c(0, 0, 1, 1/2, 0, 0)
fh <- freqz(fir2(100, f, m))
op <- par(mfrow = c(1, 2))
plot(f, m, type = "b", ylab = "magnitude", xlab = "Frequency")
lines(fh$w / pi, abs(fh$h), col = "blue")
# plot in dB:
plot(f, 20*log10(m+1e-5), type = "b", ylab = "dB", xlab = "Frequency")
lines(fh$w / pi, 20*log10(abs(fh$h)), col = "blue")
par(op)


[Package gsignal version 0.3-5 Index]