参照Example7.27,因为0.1π=2πf1   f1=0.05,0.9π=2πf2   f2=0.45

所以0.1π≤ω≤0.9π,0.05≤|H|≤0.45

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.31 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ f = [0 0.1 0.9 1]; % in w/pi units
m = [0 0.05 0.45 0]; % Magnitude values M = 25; % length of filter
N = M - 1; % Nth-order
h = firpm(N, f, m, 'differentiator');
%h
[db, mag, pha, grd, w] = freqz_m(h, [1]); [Hr, ww, c, L] = Hr_Type3(h);
%[Hr,omega,P,L] = ampl_res(h); l = 0:M-1;
%% -------------------------------------------------
%% Plot
%% -------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 7.31')
set(gcf,'Color','white');
subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -90 10]);
set(gca,'YTickMode','manual','YTick',[-60,-40,-20,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['60';'40';'20';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.1,0.9,1,1.1,1.9,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.1,0.9,1,1.1,1.9,2]);
set(gca,'YTickMode','manual','YTick',[0,1.0,2.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.31')
set(gcf,'Color','white'); subplot(2,2,1); stem(l, h); axis([-1, M, -0.6, 0.5]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response, M=25');
set(gca, 'XTickMode', 'manual', 'XTick', [0,12,25]);
set(gca, 'YTickMode', 'manual', 'YTick', [-0.6:0.2:0.6]); subplot(2,2,3); plot(w/pi, db); axis([0, 1, -80, 10]); grid on;
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB ');
set(gca,'XTickMode','manual','XTick',f)
set(gca,'YTickMode','manual','YTick',[-60,-40,-20,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['60';'40';'20';' 0']); subplot(2,2,4); plot(ww/pi, Hr); axis([0, 1, -0.2, 1.5]); grid on;
xlabel('frequency in \pi nuits'); ylabel('Hr(w)'); title('Amplitude Response'); n = [0:1:100];
x = 3*sin(0.25*pi*n);
y = filter(h,1,x);
y_chk = 0.75*cos(0.25*pi*n); figure('NumberTitle', 'off', 'Name', 'Problem 7.31 x(n)')
set(gcf,'Color','white');
subplot(2,1,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,1,2); stem(n, x); axis([0 100 0 3]); grid on;
xlabel('n'); ylabel('x(n)'); title('Input sequence'); figure('NumberTitle', 'off', 'Name', 'Problem 7.31 y(n) and y_chk(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(n, y); axis([0 100 -1 1]); grid on;
xlabel('n'); ylabel('y(n)'); title('Output sequence'); subplot(2,1,2); stem(n, y_chk); axis([0 100 -1 1]); grid on;
xlabel('n'); ylabel('y\_chk(n)'); title('Output sequence'); % ---------------------------
% DTFT of x
% ---------------------------
MM = 500;
[X, w1] = dtft1(x, n, MM);
[Y, w1] = dtft1(y, n, MM); magX = abs(X); angX = angle(X); realX = real(X); imagX = imag(X);
magY = abs(Y); angY = angle(Y); realY = real(Y); imagY = imag(Y); figure('NumberTitle', 'off', 'Name', 'Problem 7.31 DTFT of x(n)')
set(gcf,'Color','white');
subplot(2,2,1); plot(w1/pi,magX); grid on; %axis([0,2,0,15]);
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude |X|');
subplot(2,2,3); plot(w1/pi, angX/pi); grid on; axis([0,2,-1,1]);
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Radians/\pi'); subplot('2,2,2'); plot(w1/pi, realX); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot('2,2,4'); plot(w1/pi, imagX); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary'); figure('NumberTitle', 'off', 'Name', 'Problem 7.31 DTFT of y(n)')
set(gcf,'Color','white');
subplot(2,2,1); plot(w1/pi,magY); grid on; %axis([0,2,0,15]);
title('Magnitude Part');
xlabel('frequency in \pi units'); ylabel('Magnitude |Y|');
subplot(2,2,3); plot(w1/pi, angY/pi); grid on; axis([0,2,-1,1]);
title('Angle Part');
xlabel('frequency in \pi units'); ylabel('Radians/\pi'); subplot('2,2,2'); plot(w1/pi, realY); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot('2,2,4'); plot(w1/pi, imagY); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary'); figure('NumberTitle', 'off', 'Name', 'Problem 7.31 Magnitude Response')
set(gcf,'Color','white');
subplot(1,2,1); plot(w1/pi,magX); grid on; %axis([0,2,0,15]);
title('Magnitude Part of Input');
xlabel('frequency in \pi units'); ylabel('Magnitude |X|');
subplot(1,2,2); plot(w1/pi,magY); grid on; %axis([0,2,0,15]);
title('Magnitude Part of Output');
xlabel('frequency in \pi units'); ylabel('Magnitude |Y|');

  运行结果:

根据线性相位FIR性质,differentiator为第3类线性相位FIR,下图为脉冲响应、幅度谱和振幅谱。

脉冲响应和输入序列

下图分别用卷积法和数学求导数方法得到的输出,

各自求其离散时间傅氏变换DTFT,得

两种求微分结果幅度谱对比,可以看出:

1、设计滤波器卷积输入,输出的0.5π频率附近出现能量,数学求法没有;

2、设计滤波器卷积输入,幅度较数学求法小(能量有损失?);

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

  1. 《DSP using MATLAB》Problem 5.31

    第3小题: 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Out ...

  2. 《DSP using MATLAB》Problem 8.31

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

  3. 《DSP using MATLAB》Problem 7.26

    注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...

  4. 《DSP using MATLAB》Problem 7.25

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

  5. 《DSP using MATLAB》Problem 7.24

    又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...

  6. 《DSP using MATLAB》Problem 6.12

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

  7. 《DSP using MATLAB》Problem 6.10

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

  8. 《DSP using MATLAB》Problem 2.7

    1.代码: function [xe,xo,m] = evenodd_cv(x,n) % % Complex signal decomposition into even and odd parts ...

  9. 《DSP using MATLAB》Problem 2.6

    1.代码 %% ------------------------------------------------------------------------ %% Output Info abou ...

随机推荐

  1. Big Number HDU - 1212

    As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your ...

  2. layui之input里格式验证

    form.verify({          title: function(value){            if(value.length < 5){              retu ...

  3. 2019 Multi-University Training Contest 6 Snowy Smile (最大字段和变形)

    题意: 求一个子矩阵要求其矩阵内的合最大. 题解: 正常的求最大子矩阵的复杂度是O(n^3) 对于这一题说复杂度过不去,注意到这个题总共只有2000个点关键点在与这里优化 最大子矩阵可以压缩矩阵变成最 ...

  4. jQuery链式编程时修复断开的链

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. mysql的建表约束

    主键约束(primary key) 主键约束能够唯一确定一张表中的记录,也就是可以通过某个字段添加约束,就可以是的该字段不重复,且不为空 create table user (id int prima ...

  6. 窥探C语言程序的编译、链接与.h文件

    概述 C语言程序从源文件经过编译.链接生成可执行文件.那么编译与链接分别做了什么? 开发中为什么使用.h编写函数的声明?接下来使用案例说清楚为什么这样编写代码. C语言程序的编译和链接 C语言程序从源 ...

  7. 笔记:使用Python解析JSON

    使用Python解析JSON json是一种轻量级的数据交换格式,易于阅读和编写. json函数具体作用描述 函数 具体描述作用 json.dumps 将python对象编码为JSON字符串 json ...

  8. 关于Synthesis

    1,当追求面积最小时 会以牺牲Fmax为代价,可以使用一下setting: fit_pack_for_density=on fit_report_lab_usage_stats=on 可在 .qsf ...

  9. DataGridView绑定DataTable的正确姿势

    1. 将DataTable 绑定到BindingSource 2. 将BindingSource绑定到DataGridView 3. DataGridView修改完要从Datatable取值时,同步过 ...

  10. String类的trim() 方法

    用于删除字符串的头尾空白符. 语法:public String trim() 返回值:删除头尾空白符的字符串. public class Test {    public static void ma ...