# Frequency response of a bandpass filter in MATLAB

I want to see the frequency response of 1024 order bandpass filter in MATLAB.

The sampling frequency is 16kHz and the pass band frequency is [376Hz 480Hz]. I have implemented the bandpass filter using inbuilt function fir1 as b1 = fir1(1024,[376/8000 480/8000],'bandpass').
To plot the frequency response of the filter, I have used the inbuilt function freqz(b1,1,10000,16000).

My doubt is -3dB frequency obtained from the MATLAB plot should be at the pass band cut off frequency i.e at 376Hz and 480Hz right?

Now I tried to plot the magnitude response using fdatool in MATLAB, by providing the following details: FIR equiripple filter was selected order=1024 Fs=16000 Fstop1=256 Fpass1=376 Fpass2=480 Fstop2=600 Wstop1=1 Wpass=1 Wstop2=1 and the plot obtained was as below:

There is difference in the frequency response

• You edited your question as I was answering. Originally, you were using a order N = 128 FIR filter and wondering why the cut-off was not at -6dB. Seems you've figured out you needed to increase the order to get the desired result. Hopefully my answer still explains why ;)
– Jdip
Oct 10, 2022 at 7:00
• Why is the frequency response obtained using Matlab fdatool showing normalized gain of 0dB at passband cut off frequencies Oct 10, 2022 at 8:55
• You're using an equiripple design. That's a different method. Change to window method and you'll get your -6dB back if you feel like it ;)
– Jdip
Oct 10, 2022 at 16:12

fir1 designs FIR filters using the window method. Per the documentation:

The cutoff frequency is the frequency at which the normalized gain of the filter is –6 dB.

However, for the cut-off you specify to be at -6dB, you need to have appropriate transition bandwidth. I'm assuming you know what the window method for designing FIR filters is. If you don't, I suggest you study some examples.

Long story short, the transition bandwidth is related to the design window's main-lobe width, which is itself related to the design window's length.
For example, fir1 uses a hamming window by default, which has main lobe width of $$8\pi/M$$, $$M$$ being the length of the window.

The smaller $$M$$ is, the larger your transition bandwidth is.
As a matter of fact, you can estimate that the first side lobes on either part of the main lobe will have peaks at approximately $$\omega_l - 1/2 \cdot8\pi/ M$$ and $$\omega_h + 1/2 \cdot8\pi/ M$$, $$\omega_l$$ and $$\omega_h$$ being the cut-off frequencies for your band-pass. (Note: $$\pi$$ is the normalized nyquist frequency, so replace with $$f_s/2 = 8000$$ in your case)

Here are a few examples using your specs. Notice with $$M$$ increasing, the transition band sharpens, and you get closer to that $$-6$$dB at $$376\, Hz$$ and $$480 \, Hz$$ you're looking for.