《DSP using MATLAB》Problem 7.9
代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.9 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ws1 = 0.2*pi; wp1 = 0.35*pi; wp2 = 0.55*pi; ws2 = 0.75*pi; As = 40;
tr_width = min((wp1-ws1), (ws2-wp2));
M = ceil(6.2*pi/tr_width) + 1; % Hann Window
fprintf('\nFilter Length is %d.\n', M); n = [0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2; %wc = (ws + wp)/2, % ideal LPF cutoff frequency hd = ideal_lp(wc2, M) - ideal_lp(wc1, M);
w_han = (hann(M))'; h = hd .* w_han;
[db, mag, pha, grd, w] = freqz_m(h, [1]); delta_w = 2*pi/1000;
[Hr,ww,P,L] = ampl_res(h); Rp = -(min(db(wp1/delta_w+1 : 1 : wp2/delta_w))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(ws2/delta_w+1 : 1 : 501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1, delta2] = db2delta(Rp, As) %Plot figure('NumberTitle', 'off', 'Name', 'Problem 7.9 ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.4 0.5]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_han); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Hanning Window'); subplot(2,2,3); stem(n, h); axis([0 M-1 -0.4 0.5]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -150 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-45,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.9 h(n) ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-45,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1,1.2,1.55,2]); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1,1.2,1.55,2]);
set(gca,'YTickMode','manual','YTick',[0.0,0.5,1.0]) subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay'); figure('NumberTitle', 'off', 'Name', 'Problem 7.9 h(n)')
set(gcf,'Color','white'); plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[-delta2,0,delta2,1 - delta1,1, 1 + delta1])
%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
%set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1,1.2,1.55,2]); h_check = fir1(M-1, [wc1 wc2]/pi, 'bandpass', window(@hann,M));
[db, mag, pha, grd, w] = freqz_m(h_check, [1]);
[Hr,ww,P,L] = ampl_res(h_check); figure('NumberTitle', 'off', 'Name', 'Problem 7.9 fir1 Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.4 0.5]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_han); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Hanning Window'); subplot(2,2,3); stem(n, h_check); axis([0 M-1 -0.4 0.5]); grid on;
xlabel('n'); ylabel('h\_check(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -150 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-45,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.9 h(n) fir1 Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-45,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1,1.2,1.55,2]); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1,1.2,1.55,2]);
set(gca,'YTickMode','manual','YTick',[0.0,0.5,1.0]) subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay');
运行结果:
45dB满足设计要求。
理想低通方法加窗截断,获得脉冲响应。其幅度响应(dB和Absolute单位)、相位响应、群延迟
振幅响应,通带部分(放大图)
振幅响应,阻带部分(放大图)
使用fir1函数获得脉冲响应,其幅度响应(dB和Absolute单位)、相位响应、群延迟响应
《DSP using MATLAB》Problem 7.9的更多相关文章
- 《DSP using MATLAB》Problem 7.27
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.25
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.24
又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.23
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.15
用Kaiser窗方法设计一个台阶状滤波器. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.14
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.13
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.12
阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- linux centos7添加ip黑名单禁止某个ip访问
centos7用的是firewall 添加单个黑名单只需要把ip添加到 /etc/hosts.deny 格式 sshd:$IP:deny vim /etc/hosts.deny 添加你要禁止的i ...
- MapReduce 踩坑 :Aggregation is not enabled. Try the nodemanager at IP:HOST
原因:yarn-site.xml 中,有关mapreduce日志查看的aggregation未配置启用 解决:在yarn-site.xml 中加入以下配置 <property> <n ...
- Pandas 基础(12) - Stack 和 Unstack
这节的主题是 stack 和 unstack, 我目前还不知道专业领域是怎么翻译的, 我自己理解的意思就是"组成堆"和"解除堆". 其实, 也是对数据格式的一种 ...
- 第八届蓝桥杯省赛 K倍区间
问题描述 给定一个长度为N的数列,A1, A2, ... AN,如果其中一段连续的子序列Ai, Ai+1, ... Aj(i <= j)之和是K的倍数,我们就称这个区间[i, j]是K倍区间. ...
- 线程(六)之LOCK和synchronized
在java.util.concurrent.locks包中有很多Lock的实现类,常用的有ReentrantLock.ReadWriteLock(实现类ReentrantReadWriteLock), ...
- Spring AOP @Before @Around @After 等 advice 的执行顺序
用过spring框架进行开发的人,多多少少会使用过它的AOP功能,都知道有@Before.@Around和@After等advice.最近,为了实现项目中的输出日志和权限控制这两个需求,我也使用到了A ...
- Android:手把手教你 实现Activity 与 Fragment 相互通信,发送字符串信息(含Demo)
前言Activity 与 Fragment 的使用在Android开发中非常多今天,我将主要讲解 Activity 与 Fragment 如何进行通信,实际上是要解决两个问题: Activity 如何 ...
- SQL SERVER 触发器之After,Instead of
[Ater](同for)先执行增删改操作,再执行触发器操作 [Instead of]直接只执行触发器里的 create trigger triggername on table_name for/af ...
- jQuery 省份选择
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Centos 7 搭建FTP详细配置步骤方法
vsftpd的安裝使用: ftp概述:FTP(File Transfer protocol,文件传输协议)是经典的C/S架构的应用层协议,需要有服务端软件,客户端软件两个部共同组成实现文件传输功能. ...