数字信号处理复习(总结版)

freqs求解的是模拟滤波器的频率响应,freqz求解的是数字滤波器的频率响应。
Rp(通带最大衰减)越小,Rs(阻带最小衰减)越大,阶数N越大,滤波效果越好,但是越复杂!


一、绪论

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

先平移 -> 伸缩 -> 翻转

相关运算

  • x和y的互相关 = y和x的互相关,即:Rxy = Ryx(其中Rxy = x[k] 卷积 y[-k])
  • x的自相关,在x=0的值最大,计算结果偶对称

在这里插入图片描述

四、数字滤波器

在这里插入图片描述
LTI系统被称为IIR系统

在这里插入图片描述

4.1 IIR数字滤波器

在这里插入图片描述
在这里插入图片描述
数字滤波器设计,先通过频率变换将数字滤波器设计指标转换为模拟滤波器设计指标,然后设计出模拟滤波器,最后再通过双线性不变法或者脉冲响应不变法设计出对应的数字滤波器。

上述数字滤波器设计思路的关键,则是设计模拟滤波器。设计模拟滤波器过程如下:先通过频率变换,将任意模拟滤波器设计指标转化为低通模拟滤波器设计指标,然后设计出低通的模拟滤波器,最后通过复频率变换转换,将模拟的低通滤波器转换为任意的模拟滤波器。

进而低通的模拟滤波器成为了设计核心,低通的模拟滤波器设计通常使用BW、CB和C三个设计模板进行设计。

数字滤波器设计指标
在这里插入图片描述

模拟滤波器设计指标
在这里插入图片描述
在这里插入图片描述
增益函数:G(w) = 20log(|H(jw)|)
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
切比雪夫I:通带波动,Wp = Wc
切比雪夫II:阻带波动,Ws = Wc
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

阶数越小,成本越低

在这里插入图片描述

极点在左半平面是稳定的!(连续)
绩点在单位圆内!(离散)

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
巴特沃兹模拟低通滤波器频率响应不是一个带限信号,造成设计的数字低通滤波器频谱混叠。
在这里插入图片描述

解决办法:提高设计指标!或者使用双线性变换法

在这里插入图片描述
双线性变换法又称为改进的脉冲响应不变法,即把非带限信号转化为了带限信号,避免了频谱混叠。

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

双线性变化法可以设计:低通、高通、带通、带阻

在这里插入图片描述

4.2、MATLAB设计滤波器

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[例] 设计一个满足下列指标的BW型模拟低通滤波器 fp=1kHz, fs=2kHz, Ap≤1dB, As≥40dB

clc;
clear;
Wp=2*pi*1000;Ws=2*pi*2000;Ap=1;As=40; % Analog filter specifications
[N,Wc]=buttord(Wp,Ws,Ap,As,'s'); %Computer the order of analog filter
[num,den] = butter(N,Wc,'s'); %Compute AF coefficients
disp('Numerator polynomial'); fprintf('%.4e\n',num);
disp('Denominator polynomial'); fprintf('%.4e\n',den);
omega=[Wp Ws]; h = freqs(num,den,omega); %Compute Ap and As of AF
fprintf('Ap= %.4f\n',-20*log10(abs(h(1))));
fprintf('As= %.4f\n',-20*log10(abs(h(2))));
omega = [0: 200: 3000*2*pi];
h = freqs(num,den,omega); %Compute the frequency response of the AF
gain=20*log10(abs(h)); plot(omega/(2*pi),gain);
xlabel('Frequency in Hz'); ylabel('Gain in dB');

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
高通W0任意取,通常取1。带通、带阻的W0和B是理论计算的,公式如下图最后一栏:
在这里插入图片描述

[例] 试设计满足下列指标的BW型模拟高通滤波器 fp=5kHz, fs=1kHz, Ap≤1dB, As≥40dB。

fp=5000;fs=1000; Ap=1;As=40; % AF specifications
wLp=1/(2*pi*fp); wLs=1/(2*pi*fs); % HP specifications to LP’s
[N,Wc]=buttord(wLp,wLs,Ap,As,'s'); % Computer AF order
[num,den] = butter(N,Wc,'s'); % Compute AF coefficients
[numt,dent] = lp2hp(num,den,2); % LP to HP
omega=[2*pi*fp, 2*pi*fs];
h = freqs(numt, dent, omega);
fprintf('Ap= %.4f\n',-20*log10(abs(h(1))));
fprintf('As= %.4f\n',-20*log10(abs(h(2))));
omega = [0: 200: 6000*2*pi];
h = freqs(numt, dent, omega); % Compute the frequency response of the AF
gain=20*log10(abs(h)); plot(omega/(2*pi),gain);
xlabel('Frequency in Hz'); ylabel('Gain in dB')

在这里插入图片描述
[例] 试设计满足下列指标的BW型模拟带通滤波器 wp1=6 rad/s, wp2=8 rad/s, Ap≤1dB,ws1=4 rad/s, ws2=11 rad/s, As≥32dB

wp=1; ws=3.3182; Ap=1; As=32; % AF specifications
w0=sqrt(48); B=2;
[N,Wc]=buttord(wp,ws,Ap,As,'s'); % Computer low-pass AF order
[num,den] = butter(N,Wc,'s'); % Compute low-pass AF coefficients
[numt,dent] = lp2bp(num,den,w0,B); % LP to BP
omega=[6 8 4 11];
h = freqs(numt,dent,omega); %Compute Ap and As of the AF
fprintf('Ap1= %.4f\n',-20*log10(abs(h(1))));
fprintf('Ap2= %.4f\n',-20*log10(abs(h(2))));
fprintf('As1= %.4f\n',-20*log10(abs(h(3))));
fprintf('As2= %.4f\n',-20*log10(abs(h(4))));
w=linspace(2,12,1000);
h=freqs(numt,dent,w);
plot(w,20*log10(abs(h))) ; grid on;
xlabel('Frequency in rad/s');
ylabel('Gain in dB')

在这里插入图片描述

[例] 试设计满足下列指标的BW型模拟带阻滤波器
wp1=10 rad/s, wp2=30 rad/s, Ap≤1dB,
ws1=19 rad/s, ws2=21 rad/s, As≥20dB

Ap=1;As=20; wp1=10; wp2=30; ws1=19; ws2=21; % BS AF specification
B=ws2-ws1;w0=sqrt(ws1*ws2);
wLp1=B*wp1/(w0*w0-wp1*wp1); wLp2=B*wp2/(w0*w0-wp2*wp2);
wLp=max(abs(wLp1),abs(wLp2)); wLs=1;
[N,Wc]=buttord(wLp, wLs, Ap, As, 's' ); % Computer low-pass AF order
[num,den] = butter(N, Wc, 's' ); % Compute low-pass AF coefficients
[numt,dent]=lp2bs(num,den,w0,B); % LP to BS
omega=[10 30 19 21];
h = freqs(numt,dent,omega);
fprintf('Ap1= %.4f\n',-20*log10(abs(h(1))));
fprintf('Ap2= %.4f\n',-20*log10(abs(h(2))));
fprintf('As1= %.4f\n',-20*log10(abs(h(3))));
fprintf('As2= %.4f\n',-20*log10(abs(h(4))));
w=linspace(5,35,1000); h=freqs(numt,dent,w);
plot(w,20*log10(abs(h)));
xlabel('Frequency in rad/s'); ylabel('Gain in dB')

在这里插入图片描述
在这里插入图片描述

其中Fs是T的倒数,实际Fs取值可以任取,不影响最后的结果。
或者说这个Fs要同数字频率转换为模拟频率时的T对应!
在这里插入图片描述
[例] 利用BW型模拟低通滤波器设计满足指标
Wp=0.2p rad, Ws=0.6p rad, Ap≤2dB, As≥15dB的数字低通滤波器。

% 数字滤波器
Wp=0.2*pi; Ws=0.6*pi; Ap=2; As=15;%DF BW LP specification
Fs=1; %Sampling frequency(Hz)
wp=Wp*Fs; ws=Ws*Fs;%Analog Butterworth specification
[N,wc]=buttord(wp,ws,Ap,As,'s');%determine the order of AF filter
[numa,dena]=butter(N,wc,'s');%determine the AF-BW filter
[numd,dend]=impinvar(numa,dena,Fs);%determine the DF filter
% [numd,dend]=bilinear(numa,dena,Fs);
w=linspace(0,pi,1024);%plot the frequency response
h=freqz(numd,dend,w);
plot(w/pi,20*log10(abs(h)));
xlabel('frequency in rad');
ylabel('Gain in dB');
%computer Ap As of the designed filter
w=[Wp Ws];
h=freqz(numd,dend,w);
fprintf('Ap= %.4f\n',-20*log10( abs(h(1))));
fprintf('As= %.4f\n',-20*log10( abs(h(2))));

在这里插入图片描述

在这里插入图片描述

数字滤波器的设计,除了将其转化为模拟滤波器这种设计方法外,MATLAB还直接提供了数字滤波器的设计函数,下面一一介绍!

BW型,不加s即为设计数字型。
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
[例] 试设计满足下列指标的BW型数字带通滤波器
Wp1=0.45π rad, Wp2=0.55π rad, Ap≤3dB,
Ws1=0.40π rad, Ws2=0.60π rad, As≥30dB

Wp=[0.45*pi, 0.55*pi]; Ws=[0.40*pi, 0.60*pi]; Ap=3; As=30; % BP-DF specifications
[N,Wc]=buttord(Wp/pi, Ws/pi, Ap, As) ; % Computer low-pass DF order
fprintf('N=%.0f\n',N);
[numd,dend]=butter(N,Wc) % Compute band-pass DF coefficients
fprintf('numd= %.4f\n',numd); fprintf('dend= %.4f\n',dend);
omega=[Wp Ws];
h = freqz(numd,dend,omega); %Compute Ap and As of the DF
fprintf('Ap1= %.4f\n',-20*log10(abs(h(1))));
fprintf('Ap2= %.4f\n',-20*log10(abs(h(2))));
fprintf('As1= %.4f\n',-20*log10(abs(h(3))));
fprintf('As2= %.4f\n',-20*log10(abs(h(4))));
w=linspace(0.3*pi,0.7*pi,1000);
h=freqz(numd,dend,w);
plot(w/pi, 20*log10(abs(h))); % Plot the DF frequency response
xlabel('Frequency in rad'); ylabel('Gain in dB');

在这里插入图片描述

脉搏信号谱分析

%信号采样率参数
fs=200; %A/D设备
T=1/fs;
%脉搏时域信号
x=load('x.txt'); %读取一段音频除去噪音与之类似
M=length(x);
t=[0:M-1]*T;
figure(1);plot(t,x);
xlabel('time/(s)');ylabel('x(t)');
title('脉搏时域信号');grid on;
%FFT频谱分析
N=M*2-1; % 这个有点不太明白???
X=fft(x,N);
figure(2);
f=[-M+1:M-1]*fs/N;
plot(f,abs(fftshift(X)));
xlabel('frequence/(Hz)');ylabel('amplitude');
title('脉搏频谱');grid on;

【例】脉搏信号频率范围: 1-20Hz噪声信号频率范围: 0-1Hz、 20Hz以上。设计方案:高通和低通滤波器级联。高通指标 fs=0.1 Hz;fp=0.9 Hz;Ap=0.5 dB;As=40 dB。低通指标fp=30 Hz;fs=50 Hz;Ap=3 dB;As=60 dB

%Butterworth高通数字滤波器;
Wp1= 2*pi*fp/fsam; Ws1= 2*pi*fs/fsam;
[n,Wn]=buttord(Wp1/pi,Ws1/pi, Ap, As);
[b,a] = butter(n,Wn,'high');
figure(3);freqz(b,a,512,200); title('Butterworth Highpass Filter')
y=filtfilt(b,a,x); figure(4); plot(t,y);
xlabel('time/(s)'); ylabel('x(t)'); title('Butterworth高通滤波后脉搏信号');grid on;
Y=fft(y,N);figure(5); plot(f,abs(fftshift(Y)));
xlabel('frequence/(Hz)'); ylabel('amplitude'); title('FFT(幅频曲线)');grid on;
% Butterworth低通数字滤波器;
Wp = 2*pi*fp/fsam; Ws =2*pi*fs/fsam; Ap = 3; As = 60;
[n,Wc] = buttord(Wp/pi, Ws/pi, Ap, As);
[b,a] = butter(n,Wc,'low');
figure(6);freqz(b,a,512,200); title('Butterworth Lowpass Filter')
q=filter(b,a,y);figure(7); plot(t,q);
xlabel('time/(s)'); ylabel('x(t)'); title('Butterworth低通滤波脉搏信号');grid on;
Y=fft(q,N);figure(8); plot(f,abs(fftshift(Y)));
xlabel('frequence/(Hz)'); ylabel('amplitude'); title('FFT(幅频曲线)');grid on;

FIR滤波器

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/ReCclay/article/details/106422799