《DSP using MATLAB》Problem 7.29
代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.29 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % bandpass
ws1 = 0.25*pi; wp1 = 0.4*pi; wp2 = 0.6*pi; ws2 = 0.75*pi;
As = 50; Rp = 1; [delta1, delta2] = db2delta(Rp, As);
deltaH = max(delta1,delta2); deltaL = min(delta1,delta2); f = [ws1, wp1, wp2, ws2]/pi; m = [0, 1, 0]; delta = [delta2, delta1, delta2]; [N, f, m, weights] = firpmord(f, m, delta);
N h = firpm(N, f, m, weights);
[db, mag, pha, grd, w] = freqz_m(h, [1]);
delta_w = 2*pi/1000;
ws1i = floor(ws1/delta_w)+1; wp1i = floor(wp1/delta_w)+1;
ws2i = floor(ws2/delta_w)+1; wp2i = floor(wp2/delta_w)+1; Asd = -max(db(1:1:ws1i)) N = N + 2 % Length M=25
h = firpm(N, f, m, weights); [db, mag, pha, grd, w] = freqz_m(h, [1]);
Asd = -max(db(1:1:ws1i)) M = N + 1
l = 0:M-1;
%% --------------------------------------------------
%% Type-1 BPF
%% --------------------------------------------------
[Hr, ww, a, L] = Hr_Type1(h); Rp = -(min(db(floor(wp1/delta_w)+1 :1: floor(wp2/delta_w)))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(floor(ws2/delta_w)+1 : 1 : 501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1_db, delta2_db] = db2delta(Rp, As) % Plot
figure('NumberTitle', 'off', 'Name', 'Problem 7.29 h(n), Parks-McClellan Method')
set(gcf,'Color','white');
subplot(2,2,1); stem([0:M-1], h); axis([0 M-1 -0.5 0.5]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response, M=25'); subplot(2,2,2); plot(w/pi, db); axis([0 1 -90 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-53,-9,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['53';' 9';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.33,0.4,0.6,0.66,0.75,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); subplot(2,2,3); plot(ww/pi, Hr); axis([0, 1, -0.2, 1.2]); grid on;
xlabel('frequency in \pi nuits'); ylabel('Hr(w)'); title('Amplitude Response');
set(gca,'XTickMode','manual','XTick',[0,0.25,0.33,0.4,0.6,0.66,0.75,1])
set(gca,'YTickMode','manual','YTick',[0,1]); subplot(2,2,4);
sb1w = ww(1:1:ws1i)/pi; sb1e = Hr(1:1:ws1i);
pbw = ww(wp1i:wp2i)/pi; pbe = Hr(wp1i:wp2i)-1;
sb2w = ww(ws2i:501)/pi; sb2e = Hr(ws2i:501);
plot(sb1w,sb1e,pbw,pbe*(delta2/delta1),sb2w,sb2e); % weighted error
%plot(sb1w,sb1e,pbw,pbe,sb2w,sb2e); % error axis([0, 1, -deltaL, deltaL]); grid on;
xlabel('frequency in \pi units'); ylabel('Hr(w)');
title('Weighted Error');
%title('Error Response');
set(gca,'XTickMode','manual','XTick',f)
set(gca,'YTickMode','manual','YTick',[-deltaL, 0,deltaL]);
set(gca,'XGrid','on','YGrid','on') figure('NumberTitle', 'off', 'Name', 'Problem 7.29a Parks-McClellan Method')
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -90 10]);
set(gca,'YTickMode','manual','YTick',[-53,-9,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['53';' 9';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.4,0.6,0.75,1,1.25,1.4,1.6,1.75,2]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); 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.25,0.4,0.6,0.75,1,1.25,1.4,1.6,1.75,2]);
set(gca,'YTickMode','manual','YTick',[0,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.29 AmpRes of h(n), Parks-McClellan Method')
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_db ,0,delta2_db , 1-delta1_db, 1, 1+delta1_db]);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.4,0.6,0.75,1]);
运行结果:
阶数N=22时,阻带衰减43dB,不满足要求。
所以增大N,当N=24时,As=52dB,滤波器长度M=25
《DSP using MATLAB》Problem 7.29的更多相关文章
- 《DSP using MATLAB》Problem 8.29
来汉有一月,往日的高温由于最近几个台风沿海登陆影响,今天终于下雨了,凉爽了几个小时. 接着做题. %% ------------------------------------------------ ...
- 《DSP using MATLAB》Problem 5.30
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 8.28
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 8.27
7月底,又一个夏天,又一个火热的夏天,来到火炉城武汉,天天高温橙色预警,到今天已有二十多天. 先看看住的地方 下雨的时候是这样的 接着做题 代码: %% ----------------------- ...
- 《DSP using MATLAB》Problem 8.26
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《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 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- iOS疑问
1.__NSFrozenDictionaryM在数组类簇中是什么角色?
- requests 返回 521
网页端抓数据免不了要跟JavaScript打交道,尤其是JS代码有混淆,对cookie做了手脚.找到cookie生成的地方要费一点时间. 那天碰到这样一个网页,用浏览器打开很正常.然而用request ...
- 第十一篇:一点一滴学ibatis(一)
一.常见ORM框架1.原生的JDBC.自己写的JDBC,基本上就只够程序跑起来,缺陷和漏洞一堆堆.回顾下jdbc的几个操作,加载驱动,建立连接,预处理语句,执行,结果集遍历.这个过程中,因为连接Con ...
- SpringAOP中的aop:config标签
我们使用Spring的AOP功能的时候发现,我们使用普通的配置方式的时候,我们无法精确的确定将切面类中的哪个方法切入到哪个切入点上, 所以我们可以使用aop的专用标签来完成相关的配置.其中主要表现是使 ...
- 17.splash_case06_ScrapySplashTest-master
taobao.py # -*- coding: utf-8 -*- from scrapy import Spider, Request from urllib.parse import quote ...
- Python Flask高级编程之从0到1开发《鱼书》精品项目 ✍✍✍
Python Flask高级编程之从0到1开发<鱼书>精品项目 一 .安装环境我们使用 flask web框架,并用 sqlalchemy来做数据库映射,并使用 migrate做数据迁移 ...
- python字典的常用操作,数据类型划分
一.数据类型划分之一 可分为:可变数据类型,不可变数据类型 不可变数据类型:元祖,布尔值(Bool),数值 int ,字符串 str 可哈希 可变数据类型: list,d ...
- java 测试时 程序的 运行时间
检测一个JAVA程序的运行时间方法:long startTime = System.currentTimeMillis();//获取当前时间//doSomeThing(); //要运行的java程 ...
- 现代软件工程HW1:词频统计
作业详细要求:http://www.cnblogs.com/denghp83/p/8627840.html 基本功能 1. 统计文件的字符数(只需要统计Ascii码,汉字不用考虑,换行符不用考虑,'\ ...
- 使用HttpStaus自定义返回状态
一.导入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...