阻带衰减50dB,我们选Hamming窗

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.12 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % highpass
ws1 = 0.4*pi; wp1 = 0.6*pi; As = 50; Rp = 0.004;
tr_width = (wp1-ws1);
M = ceil(6.6*pi/tr_width) + 1; % Hamming Window
fprintf('\nFilter Length: M = %d.\n', M); n = [0:1:M-1]; wc1 = (ws1+wp1)/2; %wc = (ws + wp)/2, % ideal LPF cutoff frequency hd = ideal_lp(pi, M) - ideal_lp(wc1, M);
w_hamm = (hamming(M))'; h = hd .* w_hamm;
[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: 0.9*pi/delta_w))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(1 :1: ws1/delta_w+1 ))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1, delta2] = db2delta(Rp, As) % Plot figure('NumberTitle', 'off', 'Name', 'Problem 7.12 ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.4 0.3]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_hamm); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Hamming Window'); subplot(2,2,3); stem(n, h); axis([0 M-1 -0.4 0.3]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -100 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-52,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'52';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.12 h(n) ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -100 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-52,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'52';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 2 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,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.12 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.4,0.6,1,1.4,1.6,2]); h_check = fir1(M, wc1/pi, 'high');
[db, mag, pha, grd, w] = freqz_m(h_check, [1]);
[Hr,ww,P,L] = ampl_res(h_check); figure('NumberTitle', 'off', 'Name', 'Problem 7.12 fir1 Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.4 0.3]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_hamm); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Hanning Window'); subplot(2,2,3); stem([0:M], h_check); axis([0 M -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 -100 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-52,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'52';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.12 h(n) fir1 Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -100 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-52,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'52';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,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.4,0.6,1,1.4,1.6,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');

  运行结果:

Hamming窗长度为M=34,实际最小阻带衰减为52dB,满足设计要求。

振幅响应的高通部分

低阻部分

下面是用fir1函数(默认Hamming窗)来求得脉冲响应,再计算其幅度响应(dB和Absolute单位)、相位响应和群延迟响应,

可以看出,两种方法得到的幅度响应和相位响应在接近π的较高频率部分,还是有差别的。

《DSP using MATLAB》Problem 7.12的更多相关文章

  1. 《DSP using MATLAB》Problem 6.12

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  2. 《DSP using MATLAB》Problem 5.12

    1.从别的地方找的证明过程: 2.代码 function x2 = circfold(x1, N) %% Circular folding using DFT %% ----------------- ...

  3. 《DSP using MATLAB》Problem 8.12

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  4. 《DSP using MATLAB》Problem 4.12

    代码: function [As, Ac, r, v0] = invCCPP(b0, b1, a1, a2) % Determine the signal parameters Ac, As, r, ...

  5. 《DSP using MATLAB》Problem 3.12

  6. 《DSP using MATLAB》Problem 7.6

    代码: 子函数ampl_res function [Hr,w,P,L] = ampl_res(h); % % function [Hr,w,P,L] = Ampl_res(h) % Computes ...

  7. 《DSP using MATLAB》Problem 6.22

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  8. 《DSP using MATLAB》Problem 6.8

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  9. 《DSP using MATLAB》Problem 5.21

    证明: 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

随机推荐

  1. Zedboard初体验

    前言 这是我学习Zedboard时做的笔记 Zedboard是什么 Zedboard是Xilinx公司推出的搭载了Zynq芯片的开发板,其中Zynq芯片采用全新的设计理念,将ARM处理器嵌入FPGA可 ...

  2. QuerySet API

    模型objects:这个对象是 django.db.model.manager.Manger 的对象,这个类是一个空壳类,它上面的所有方法都是从 QuerySet 这个类中拷贝过来的. >> ...

  3. Springboot静态文件不更新的解决办法,以及Springboot实现热部署

    Springboot静态文件不更新的解决办法,以及Springboot实现热部署 原文链接:https://www.cnblogs.com/blog5277/p/9271882.html 原文作者:博 ...

  4. ugui 灰度shader mask冲突解决 转。。。

    项目上遇到了一个问题,灰度shader无法在mask下使用,两个之间会一定的冲突.经查验是mask组件对shader的相关属性有要求,添加相关的属性则可符合要求使其他shader使用UGui里的mas ...

  5. ES6标准之箭头函数

    语法 具有一个参数的简单函数 var single = a => a single('hello, world') // 'hello, world' 没有参数的需要用在箭头前加上小括号 var ...

  6. Ubuntu 16.04上搭建CDH5.16.1集群

    本文参考自:<Ubuntu16.04上搭建CDH5.14集群> 1.准备三台(CDH默认配置为三台)安装Ubuntu 16.04.4 LTS系统的服务器,假设ip地址分布为 192.168 ...

  7. PHP中buffer的认知

    buffer其实就是缓冲区,一个内存地址空间,只要用于存储数据区域. <?php echo 1; 运行这段代码,浏览器会显示1,其实中间会经历一个buffer(数据1先到buffer,当buff ...

  8. Lab 6-4

    In this lab, we'll analyze the malware found in the file Lab06-04.exe. Questions and Short Answers W ...

  9. .net asp 实现json 格式跨域访问 的方法

    在<configuration> 配置目录下添加允许跨域的头部信息 //webapi 默认的web.config有配置 //1)删除 下面参数 否者WEB API 会 出现405 错误 没 ...

  10. 拒绝服务(DoS)理解、防御与实现

    一.说明 我一直不明白为什么拒绝服务,初学着喜欢拿来装逼.媒体喜欢吹得神乎其神.公司招聘也喜欢拿来做标准,因为我觉得拒绝服务和社会工程学就是最名不副实的两样东西.当然由于自己不明确拒绝服务在代码上是怎 ...