# Determine frequency response from impulse response

I'm studying signal processing, using MATLAB to plot filter responses. So far, I understand I can use the impulse response to apply a filter to a signal. For example, the impulse response of an $L$-length passband filter is:

$$h[n]=(2/L) \cos(\hat\omega_c n)$$

Where $0\leq n<L$ and $\hat\omega_c$ is the center frequency that defines the frequency location of the passband. I can use firfilt(h, xx) to apply the filter above to a signal xx. So far so good.

Now I would like to plot the frequency response of the system. For the system above, the study material states the frequency response is:

$$H(e^{j\hat\omega})=\sum\limits_{k=0}^{L-1} b_ke^{-j\hat\omega k}$$

According to the study material, the frequency response can be plotted in MATLAB by using ones(1, L) / L for filter coefficients:

bb = ones(1, L) / L;
ww = -pi:(pi / 100):pi;
HH = freqz(bb, 1, ww);

subplot(2, 1, 1), plot(ww, abs(HH));
subplot(2, 1, 2), plot(ww, angle(HH));


Now I'm starting to get confused. Two questions so far:

• How are the coefficients ones(1, L) / L derived from the formula for $H(e^{j\hat\omega})$? Are they?
• The frequency response is always centered at the origin. Can I introduce a different center frequency, so it matches with the impulse response?

Things get even more complicated when a second filter is introduced with a Hamming window. The impulse response is given as:

$$h[n]=0.54-0.46\cos(2\pi n/(L-1)))\cos(\hat\omega_c(n-(L-1)/2)$$

I know how to apply the impulse response to any given signal, but when asked to plot the frequency response, I'm assuming I need to convert the impulse response to a set of filter coefficients. In other words:

• How do I determine the frequency response based on the impulse response?

The ones(1, L) / L is not derived from the formula for $H$. When you call freqz, the first argument are the filter coefficients applied to the input signal samples, and the second argument is the filter coefficients applied to the previous outputs. To be precise, if you look at help filter, you will see the following formula:

a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)


The the vector b is the first argument to freqz and the vector a is the second. Thus, when you call freqz as you did, you are calculating the frequency response for the filter with b = ones(1,L)/L and a=1, which is just a low-pass filter centered at DC. If you want to see the frequency response of the other filters, you need pass their coefficients rather than the vector of ones.

Let's take an example using the cosine filter you have above:

L = 50;           % Number of taps in the filter.
omega_c = 0.25;   % Center frequency of the passband (2pi*rad/sample)

% Define the filter coefficients and get their response.
h = 2/L * cos( 2*pi * omega_c * ( 0 : L - 1 ) );
ww = -pi:(pi / 100):pi;
HH = freqz( h, 1, ww );


The function $H(e^{j\omega})$ that you reference is the Discrete-Time Fourier Transform, which along with the closely related Discrete Fourier Transform, is ubiquitous in signal processing. For FIR filters, you can take the DFT of the filter coefficients to get their frequency response, which is all that equations says.

Keep reading. It will become clear but it takes time.

• This is really elaborate, thank you! I did check help freqz among others, but was somehow expecting ones(1, L) / L to relate to the cosine filter. Thanks for filling in the blanks. Jun 12, 2014 at 10:03