# freqz

Frequency response of filter

## Syntax

```[h,w] = freqz(hfilt)[h,w] = freqz(hfilt,n)freqz(hfilt)[h,w] = freqz(hs)[h,w] = freqz(hs,n)[h,w] = freqz(hs,Name,Value)freqz(hs)```

## Description

`freqz` returns the frequency response based on the current filter coefficients. This section describes common `freqz` operation with discrete-time filters and multirate filters, and filter System objects. For more input options, refer to `freqz` in Signal Processing Toolbox™ documentation.

```[h,w] = freqz(hfilt)``` returns the frequency response `h` and the corresponding frequencies `w` at which the filter response of `hfilt` is computed. The frequency response is evaluated at 8192 points equally spaced around the upper half of the unit circle.

```[h,w] = freqz(hfilt,n)``` returns the frequency response `h` and corresponding frequencies `w` for the filter or vector of filters `hfilt`. The frequency response is evaluated at `n` points equally spaced around the upper half of the unit circle. `freqz` uses the transfer function associated with the filter to calculate the frequency response of the filter with the current coefficient values.

`freqz(hfilt)` uses FVTool to plot the magnitude and unwrapped phase of the frequency response of the filter `hfilt`. If `hfilt` is a vector of filters, `freqz` plots the magnitude response and phase for each filter in the vector.

```[h,w] = freqz(hs)``` returns a frequency response for the filter System object™ `hs` using 8192 samples.

```[h,w] = freqz(hs,n)``` returns a frequency response for the filter System object `hs` using `n` samples.

```[h,w] = freqz(hs,Name,Value)``` returns a frequency response with additional options specified by one or more `Name,Value` pair arguments.

`freqz(hs)` uses FVTool to plot the magnitude and unwrapped phase of the frequency response of the filter System object `hs`.

## Input Arguments

collapse all

 `hfilt` `hfilt` is either: A discrete-time `dfilt`, or multirate filter System objectA vector of discrete-time or multirate filter objects `hs` Filter System object. The following Filter System objects are supported by this analysis function: `dsp.SampleRateConverter` is also supported by `freqz`. `n` Number of samples. For an FIR filter where `n` is a power of two, the computation is done faster using FFTs. Default: 8192

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside single quotes (`' '`). You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

### `'Arithmetic'` — Value types:`‘double'` | `'single'` | `'fixed'`

For filter System object inputs only, specify the arithmetic used during analysis. When you specify `'double'` or `'single'`, the function performs double- or single-precision analysis. When you specify `'fixed'` , the arithmetic changes depending on the setting of the `CoefficientDataType` property and whether the System object is locked or unlocked.

When you do not specify the arithmetic for non-CIC structures, the function uses double-precision arithmetic if the filter System object is in an unlocked state. If the System object is locked, the function performs analysis based on the locked input data type. CIC structures only support fixed-point arithmetic.

## Output Arguments

 `h` Complex, `n`-element frequency response vector. If `hfilt` is a vector of filters, `h` is a complex, `length(hfilt)`-by-`n` matrix of frequency response vectors corresponding to each filter in `hfilt`. If `n` is not specified, the function uses a default value of 8192. `w` Frequency vector of length `n`, in radians/sample. `w` consists of `n` points equally spaced around the upper half of the unit circle (from 0 to π radians/sample). If `n` is not specified, the function uses a default value of 8192.

## Examples

Plot the estimated frequency response of a filter. This example uses discrete-time filters, but `hd` can be any `dfilt` object, or filter System object. First plot the results for one filter.

```b = fir1(80,0.5,kaiser(81,8)); hd = dfilt.dffir(b); freqz(hd); ```

If you have more than one filter, you can plot them on the same figure using a vector of filters.

```b = fir1(40,0.5,kaiser(41,6)); hd2 = dfilt.dffir(b); h = [hd hd2]; freqz(h); ```

expand all

### Tips

There are several ways of analyzing the frequency response of filters. `freqz` accounts for quantization effects in the filter coefficients, but does not account for quantization effects in filtering arithmetic. To account for the quantization effects in filtering arithmetic, refer to function `noisepsd`.

### Algorithms

`freqz` calculates the frequency response for a filter from the filter transfer function Hq(z). The complex-valued frequency response is calculated by evaluating Hq(ejω) at discrete values of w specified by the syntax you use. The integer input argument `n` determines the number of equally-spaced points around the upper half of the unit circle at which `freqz` evaluates the frequency response. The frequency ranges from 0 to π radians per sample when you do not supply a sampling frequency as an input argument. When you supply the scalar sampling frequency `fs` as an input argument to `freqz`, the frequency ranges from 0 to `fs`/2 Hz.