Lakshmi Narayanan
Lakshmi Narayanan

Reputation: 5342

Bandpass filter matlab explanation

I am trying to learn about bandpass filter, and I understood the theory, or the basic idea. However, I have been trying to work with the following code, but am able to understand it completely and mold it to the working I want it to.

    clc;
    close all;
    clear all;

    n=0:300000;
    delay = 10000;
    wc=.2*pi;
    w0=.4*pi;

    hLP=(wc/pi)*sinc((wc/pi)*(n-delay));
    hBP=2*cos(n*w0).*hLP;
    [Happrox,W]=freqz(hBP,1); 
    plot(W,abs(Happrox));
    xlabel('frequency'); 
    ylabel('magnitude');
    title('Band pass Filter');

I got the following filter design when I run this code

enter image description here

I wanted the X axis to extended till 255 and I was able to achieve that using xlim. Now, I am facing problems when it comes to altering the frequency limits of the bandpass. That is why I felt I need to understand the code. Please help me with an explanation.

wc and w0 are the values to be altered for changing the frequency bands, but am not able to get the exact value of the frequency I require, for eg say from 12 to 250. If you can help me with an explanation, I feel I can get it done.

Thanks in advance

Upvotes: 3

Views: 4692

Answers (1)

outdoor_guy
outdoor_guy

Reputation: 146

The W variable that you got from the freqz function has unites of radians per sample and extends from 0 to pi. To get the frequency in Hz, you need to provide the sample rate, Fs and also the number of points you want, N.

Replace your call to freqz with these lines:

N = 200; % 200 points in frequency vector
Fs = 100; % 100 Hz sample rate
[Happrox,W]=freqz(hBP,1, N, Fs);

Upvotes: 2

Related Questions