fir2 | R Documentation |
Produce a FIR filter with arbitrary frequency response over frequency bands.
fir2(n, f, m, grid_n = 512, ramp_n = NULL, window = hamming(n + 1))
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 |
m |
vector of the same length as |
grid_n |
length of ideal frequency response function. |
ramp_n |
transition width for jumps in filter response (defaults to
|
window |
smoothing window. The returned filter is the same shape as the
smoothing window. Default: |
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.
The FIR filter coefficients, a vector of length n + 1
, of
class Ma
.
Paul Kienzle, pkienzle@users.sf.net.
Conversion to R Tom Short,
adapted by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.
Ma
, filter
, fftfilt
,
fir1
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.