且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带通滤波器的matlab解释

更新时间:2022-10-15 15:50:00

从freqz函数获得的W变量每个样本的弧度单位,从0延伸到pi。为了得到频率为Hz,你需要提供采样率,Fs和你想要的点数N。

用这些行代替你的呼叫到freqz :

  N = 200;频率矢量中的200个点
Fs = 100; %100 Hz采样率
[Happrox,W] = freqz(hBP,1,N,Fs);


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

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

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);