FIR滤波器设计

 

下图所示为根据已知的参数,绘制频谱响应,其中滤波系数包含一定增益,下面所示为扣除了增益以后的频谱图:

 

 

其中,具体freqz的使用看帮助文档。   filter函数用法参见帮助文档

 

整形滤波器设计:

 

 

 

 

 

 

 

fir滤波器_一种新的FIR滤波器系数量化方法

什么是窗函数?

信号处理--几种常见的窗函数

一文读懂FFT,海宁窗(hann)和汉明窗(hamming)的区别,如何选择窗函数

 

参考链接:

如何快速设计一个FIR滤波器(一)

如何快速设计一个FIR滤波器(二)

利用Matlab filterDesigner 工具生成FIR滤波器函数,并调用实现低通滤波

    function Hd = fir_8
    %FIR_8 Returns a discrete-time filter object.
    
    % MATLAB Code
    % Generated by MATLAB(R) 9.4 and DSP System Toolbox 9.6.
    % Generated on: 09-Apr-2019 11:22:46
    
    % FIR Window Lowpass filter designed using the FIR1 function.
    
    % All frequency values are in Hz.
    Fs = 100;  % Sampling Frequency
    
    N    = 7;        % Order
    Fc   = 10;       % Cutoff Frequency
    flag = 'scale';  % Sampling Flag
    
    % Create the window vector for the design algorithm.
    win = hamming(N+1);
    
    % Calculate the coefficients using the FIR1 function.
    b  = fir1(N, Fc/(Fs/2), 'low', win, flag);
    Hd = dfilt.dffir(b);
    
    % [EOF]

  

    x = 0:0.01:4;%定义400个取样点
    y = 0.1*sin(pi*x) +0.1*sin(2*pi*49*x);%设计含有高频信号与低频信号的输入信号
    figure(1);
    plot(x,y);%画出输入信号图形
    title('输入信号');
    
    Hd = fir_8;%引入滤波器,Hd包含了fir_8滤波器的各项参数
    d = filter(Hd,y);%通过filter函数将信号y送入参数为Hd的滤波器,输出信号d
    figure(2);
    plot(x,d);%画出通过滤波器的信号d的波形
    title('输出信号');
    
    figure(3);
    plot(x,y,'r');%画出输入信号图形
    hold on;%保持画出的输入信号图形
    plot(x,d,'b');%画出输出信号波形
    title('输入/输出信号');
    legend('输出信号','输入信号');

  

 

matlab的FIR滤波器设计

    b=fir1(n,wn);
    b=fir1(n,wn,'ftype');
    b=fir1(n,wn,'ftype',window)
    b=fir1(...,'noscale')

  

clear all; close all; clc;
% 滤波器长度
N=41;
%采样频率
fs=2000;

%各种滤波器的特征频率
fc_lpf=200;
fc_hpf=200;
fp_bandpass=[200 400];
fc_stop=[200 400];

%以采样频率的一般,对频率归一化
wn_lpf=fc_lpf*2/fs;
wn_hpf=fc_hpf*2/fs;
wn_bandpass=fp_bandpass*2/fs;
wn_stop=fc_stop*2/fs;

%采用fir1函数设计FIR滤波器
b_lpf=fir1(N-1,wn_lpf);
b_hpf=fir1(N-1,wn_hpf,'high');
b_bandpass=fir1(N-1,wn_bandpass,'bandpass');
b_stop=fir1(N-1,wn_stop,'stop');

%求幅频响应
m_lpf=20*log(abs(fft(b_lpf)))/log(10);
m_hpf=20*log(abs(fft(b_hpf)))/log(10);
m_bandpass=20*log(abs(fft(b_bandpass)))/log(10);
m_stop=20*log(abs(fft(b_stop)))/log(10);

% 设置频率响应的横坐标单位为hz
x_f=0:(fs/length(m_lpf)):fs/2;

% 单位脉冲响应
subplot(4,2,1);stem(b_lpf);xlabel('n');ylabel('h(n)');legend('lpf');
subplot(4,2,3);stem(b_hpf);xlabel('n');ylabel('h(n)');legend('hpf');
subplot(4,2,5);stem(b_bandpass);xlabel('n');ylabel('h(n)');legend('bandpass');
subplot(4,2,7);stem(b_stop);xlabel('n');ylabel('h(n)');legend('stop');

% 幅频响应
subplot(4,2,2);plot(x_f,m_lpf(1:length(x_f)));xlabel('频率(hz)');ylabel('幅度(db)','fontsize',8);legend('lpf')
subplot(4,2,4);plot(x_f,m_hpf(1:length(x_f)));xlabel('频率(hz)');ylabel('幅度(db)','fontsize',8);legend('hpf')
subplot(4,2,6);plot(x_f,m_bandpass(1:length(x_f)));xlabel('频率(hz)');ylabel('幅度(db)','fontsize',8);legend('bandpass')
subplot(4,2,8);plot(x_f,m_stop(1:length(x_f)));xlabel('频率(hz)');ylabel('幅度(db)','fontsize',8);legend('stop');

 

 

posted @ 2021-12-28 13:59  博客园—哆啦A梦  阅读(891)  评论(0)    收藏  举报