sdr.FIR.frequency_response(freqs: int = 1024, sample_rate: float = 1.0, whole: bool = True, decades: int | None = None) tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[complex128]]]
sdr.FIR.frequency_response(freqs: float, sample_rate: float = 1.0) complex
sdr.FIR.frequency_response(freqs: ndarray[Any, dtype[float64]], sample_rate: float = 1.0) ndarray[Any, dtype[complex128]]

Returns the frequency response \(H(\omega)\) of the FIR filter.

Parameters:
freqs: int = 1024
freqs: float
freqs: ndarray[Any, dtype[float64]]

The frequency specification.

  • int: The number of frequency points. The endpoint is not included.

  • float: A single frequency.

  • npt.NDArray[float]: Multiple frequencies.

sample_rate: float = 1.0

The sample rate \(f_s\) of the filter in samples/s.

whole: bool = True

Only used if freqs is an integer.

  • True: The maximum frequency is max_f = sample_rate.

  • False: The maximum frequency is max_f = sample_rate / 2.

decades: int | None = None

Only used if freqs is an integer.

  • None: f = np.linspace(0, max_f, freqs, endpoint=False).

  • int: f = np.logspace(np.log10(max_f) - decades), np.log10(max_f), freqs, endpoint=False).

Returns:

  • The frequency vector \(f\), only if freqs is an integer.

  • The frequency response of the FIR filter \(H(\omega)\).

Examples

In [1]: h = sdr.lowpass_fir(100, 0.2, window="hamming"); \
   ...: fir = sdr.FIR(h)
   ...: 

Compute the frequency response at 1024 evenly spaced frequencies.

In [2]: fir.frequency_response()
Out[2]: 
(array([0.00000000e+00, 9.76562500e-04, 1.95312500e-03, ...,
        9.97070312e-01, 9.98046875e-01, 9.99023438e-01]),
 array([1.        +0.j        , 0.95337172-0.30202676j,
        0.8178049 -0.5759632j , ..., 0.6058636 +0.79630028j,
        0.8178049 +0.5759632j , 0.95337172+0.30202676j]))

Compute the frequency response at 0.0 rad/s.

In [3]: fir.frequency_response(0.0)
Out[3]: np.complex128(1.0000000000000002+0j)

Compute the frequency response at several frequencies in Hz.

In [4]: fir.frequency_response([100, 200, 300, 400], sample_rate=1000)
Out[4]: 
array([5.00391660e-01+8.14686183e-17j, 5.53081763e-04+3.88127210e-17j,
       2.62720131e-04-2.03715849e-17j, 1.83622458e-04-3.27280811e-17j])