Main Content

freqz

Compute frequency response

Description

[H,f] = freqz(obj) returns a matrix of complex frequency responses for each filter designed by obj.

example

[H,f] = freqz(obj,ind) returns the frequency response of filters with indices corresponding to the elements in vector ind.

example

[H,f] = freqz(___,N=n) returns the N-point complex frequency response.

example

freqz(___) with no output arguments plots the frequency response of the filter bank.

example

Examples

collapse all

Create a gammatoneFilterBank object. Call freqz to get the complex frequency response, H, of the filter bank and a vector of frequencies, f, at which the response is calculated. Plot the magnitude frequency response of the filter bank.

gammaFiltBank = gammatoneFilterBank;
[H,f] = freqz(gammaFiltBank);

plot(f,abs(H))
xlabel("Frequency (Hz)")

Figure contains an axes object. The axes object with xlabel Frequency (Hz) contains 32 objects of type line.

To get the frequency response of a subset of filters in the filter bank, specify the second argument as a row vector of indices between one and the number of filters in the filter bank. Get the frequency response of the 10th filter in the filter bank and plot the magnitude frequency response.

[H,f] = freqz(gammaFiltBank,10);

plot(f,abs(H))
xlabel("Frequency (Hz)")

Figure contains an axes object. The axes object with xlabel Frequency (Hz) contains an object of type line.

To specify the number of points in the frequency response, use the N name-value argument. Specify that the frequency response contains 128 points. Plot the magnitude frequency response.

[H,f] = freqz(gammaFiltBank,N=128);

plot(f,abs(H))
xlabel("Frequency (Hz)")

Figure contains an axes object. The axes object with xlabel Frequency (Hz) contains 32 objects of type line.

To visualize the magnitude frequency response only, call freqz without any output arguments. Plot the magnitude frequency response, in dB, of filters 20, 21, and 22 with 1024 points.

freqz(gammaFiltBank,[20,21,22],N=1024)

Figure contains an axes object. The axes object with xlabel Frequency (Hz), ylabel Magnitude (dB) contains 3 objects of type line.

Create an octaveFilterBank object. Call freqz to get the complex frequency response, H, of the filter bank and a vector of frequencies, f, at which the response is calculated. Plot the magnitude frequency response in dB.

octFiltBank = octaveFilterBank;
[H,f] = freqz(octFiltBank);

plot(f,20*log10(abs(H)))
xlabel("Frequency (Hz)")
ylabel("Magnitude (dB)")
set(gca,XScale="log")
axis([10 octFiltBank.SampleRate/2 -100 2])

Figure contains an axes object. The axes object with xlabel Frequency (Hz), ylabel Magnitude (dB) contains 10 objects of type line.

To get the frequency response of a subset of filters in the filter bank, specify the second argument as a row vector of indices between one and the number of filters in the filter bank. Get the frequency response of the 5th filter in the filter bank and plot the magnitude frequency response in dB.

[H,f] = freqz(octFiltBank,5);

plot(f,20*log10(abs(H)))
xlabel("Frequency (Hz)")
ylabel("Magnitude (dB)")
set(gca,XScale="log")
axis([10 octFiltBank.SampleRate/2 -100 2])

Figure contains an axes object. The axes object with xlabel Frequency (Hz), ylabel Magnitude (dB) contains an object of type line.

To specify the number of points in the frequency response, use the N name-value argument. Specify that the frequency response contains 8192 points. Plot the magnitude frequency response in dB.

[H,f] = freqz(octFiltBank,N=8192);

plot(f,20*log10(abs(H)))
xlabel("Frequency (Hz)")
ylabel("Magnitude (dB)")
set(gca,XScale="log")
axis([10 octFiltBank.SampleRate/2 -100 2])

Figure contains an axes object. The axes object with xlabel Frequency (Hz), ylabel Magnitude (dB) contains 10 objects of type line.

To visualize the magnitude frequency response only, call freqz without any output arguments. Plot the magnitude frequency response, in dB, of filters 4, 5, and 6 with 1024 points.

freqz(octFiltBank,[4,5,6],N=1024)

Figure contains an axes object. The axes object with xlabel Frequency (Hz), ylabel Magnitude (dB) contains 3 objects of type line.

Input Arguments

collapse all

Object to get filter frequency responses from, specified as an object of gammatoneFilterBank or octaveFilterBank.

Indices of filters to calculate frequency responses from, specified as a row vector of integers with values in the range [1, N]. N is the total number of filters designed by obj.

Number of points in the frequency response, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Complex frequency response of each filter, returned as an M-by-N matrix. M is the number of points, specified by n. N is the number of filters, which is either length(ind) or, if ind is not specified, the total number of filters in the filter bank.

Data Types: double

Frequencies at which the response is computed in Hz, returned as a column vector.

Data Types: double

Version History

Introduced in R2019a