用差分方程两边进行z变换,再变量带换得到频率响应函数(或转移函数,即LTI系统脉冲响应的DTFT)。

代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 3.17 \n\n'); banner();
%% ------------------------------------------------------------------------ %% --------------------------------------------------------------
%% 1 y(n)=0.2*[x(n)+x(n-1)+x(n-2)+x(n-3)+x(n-4)]
%% --------------------------------------------------------------
a = [1]; % filter coefficient array a
b = [0.2, 0.2, 0.2, 0.2, 0.2]; % filter coefficient array b MM = 500; H = freqresp1(b, a, MM); magH = abs(H); angH = angle(H); realH = real(H); imagH = imag(H); %% --------------------------------------------------------------------
%% START H's mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 3.17.1 H1');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magH); grid on; axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angH/pi); grid on; axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 3.17.1 H1');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realH); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagH); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END X's mag ang real imag
%% ------------------------------------------------------------------- %% --------------------------------------------------------------
%% 2 y(n)=x(n)-x(n-2)+0.95y(n-1)-0.9025y(n-2)
%% --------------------------------------------------------------
a = [1, -0.95, 0.9025]; % filter coefficient array a
b = [1, 0, -1]; % filter coefficient array b MM = 500; H = freqresp1(b, a, MM); magH = abs(H); angH = angle(H); realH = real(H); imagH = imag(H); %% --------------------------------------------------------------------
%% START H's mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 3.17.2 H2');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magH); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angH/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 3.17.2 H2');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realH); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagH); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END X's mag ang real imag
%% ------------------------------------------------------------------- %% --------------------------------------------------------------
%% 3 y(n)=x(n)-x(n-1)-x(n-2)+0.95y(n-1)-0.9025y(n-2)
%% --------------------------------------------------------------
a = [1, -0.95, 0.9025]; % filter coefficient array a
b = [1, -1, -1]; % filter coefficient array b MM = 500;
H = freqresp1(b, a, MM); magH = abs(H); angH = angle(H); realH = real(H); imagH = imag(H); %% --------------------------------------------------------------------
%% START H's mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 3.17.3 H3');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magH); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angH/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 3.17.3 H3');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realH); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagH); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END X's mag ang real imag
%% ------------------------------------------------------------------- %% --------------------------------------------------------------
%% 4 y(n)=x(n)-1.7678x(n-1)+1.5625x(n-2)
%% +0.95y(n-1)-0.9025y(n-2)
%% --------------------------------------------------------------
a = [1, -0.95, 0.9025]; % filter coefficient array a
b = [1, -1.7678, 1.5625]; % filter coefficient array b MM = 500;
H = freqresp1(b, a, MM); magH = abs(H); angH = angle(H); realH = real(H); imagH = imag(H); %% --------------------------------------------------------------------
%% START H's mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 3.17.4 H4');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magH); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angH/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 3.17.4 H4');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realH); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagH); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END X's mag ang real imag
%% ------------------------------------------------------------------- %% ------------------------------------------------------------------------------
%% 5 y(n)=x(n)-0.5y(n-1)-0.25y(n-2)-0.125y(n-3)-0.0625y(n-4)-0.03125y(n-5)
%%
%% ------------------------------------------------------------------------------
a = [1, 0.5, 0.25, 0.125, 0.0625, 0.03125]; % filter coefficient array a
b = [1]; % filter coefficient array b MM = 500;
H = freqresp1(b, a, MM); magH = abs(H); angH = angle(H); realH = real(H); imagH = imag(H); %% --------------------------------------------------------------------
%% START H's mag ang real imag
%% --------------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 3.17.5 H5');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi,magH); grid on; %axis([-1,1,0,1.05]);
title('Magnitude Response');
xlabel('frequency in \pi units'); ylabel('Magnitude |H|');
subplot(2,1,2); plot(w/pi, angH/pi); grid on; %axis([-1,1,-1.05,1.05]);
title('Phase Response');
xlabel('frequency in \pi units'); ylabel('Radians/\pi'); figure('NumberTitle', 'off', 'Name', 'Problem 3.17.5 H5');
set(gcf,'Color','white');
subplot(2,1,1); plot(w/pi, realH); grid on;
title('Real Part');
xlabel('frequency in \pi units'); ylabel('Real');
subplot(2,1,2); plot(w/pi, imagH); grid on;
title('Imaginary Part');
xlabel('frequency in \pi units'); ylabel('Imaginary');
%% -------------------------------------------------------------------
%% END X's mag ang real imag
%% -------------------------------------------------------------------

  运行结果:

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

  1. 《DSP using MATLAB》Problem 6.17

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

  2. 《DSP using MATLAB》Problem 5.17

    1.代码 %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% ...

  3. 《DSP using MATLAB》Problem 2.17

    1.代码: %% ------------------------------------------------------------------------ %% Output Info abo ...

  4. 《DSP using MATLAB》Problem 8.17

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

  5. 《DSP using MATLAB》Problem 4.17

  6. 《DSP using MATLAB》Problem 5.22

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% O ...

  7. 《DSP using MATLAB》Problem 5.15

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

  8. 《DSP using MATLAB》Problem 2.18

    1.代码: function [y, H] = conv_tp(h, x) % Linear Convolution using Toeplitz Matrix % ----------------- ...

  9. 《DSP using MATLAB》Problem 7.28

    又是一年五一节,朋友圈都是晒名山大川的,晒脑袋的,我这没钱的待在家里上网转转吧 频率采样法设计带通滤波器,过渡带中有一个样点 代码: %% ++++++++++++++++++++++++++++++ ...

随机推荐

  1. C#中的约束类型

  2. Asp.Net MVC中Action跳转

    首先action的跳转大致归类: 1跳转到与当前同一控制器内的action和不同控制器内的action. 2带有参数的action跳转和不带参数的action跳转. 3跳转到指定视图,不经过Contr ...

  3. [Java学习] Java类的基本运行顺序

    我们以下面的类来说明一个基本的 Java 类的运行顺序: 1. public class Demo{ 2. private String name; 3. private int age; 4. 5. ...

  4. LeetCode--069--x的平方根

    问题描述: 实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: ...

  5. 百度安卓SDK秘钥Key错误

    下载官方安卓地图demo,输入报名和sha1申请AK,发现key错误 构建的时候要指定生成的key 安卓定位BaiduLocDemo出现aapt.exe finished with non-zero ...

  6. hdu-4023-博弈(模拟)

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Submis ...

  7. spring cloud shutdown graceful 优雅停机

    spring cloud shutdown graceful 优雅停机 当一个服务启动后,会注册到eureka中,其他的服务也可以从eureka获取到新注册的服务.但当我们要停止一个服务的时候,如果直 ...

  8. PHP:第三章——PHP中返回引用的函数

    <?php header("Content-Type:text/html;charset=utf-8"); $i=1; function &F(){ global $ ...

  9. flashfxp 命令行

    以后更新软件时,尽量用bat命令行 http://www.flashfxp.com/forum/flashfxp/frequently-asked-questions-faq-/14748-comma ...

  10. java web中的多条件查询

    转自:http://blog.csdn.net/xulu_258/article/details/46623317 所谓多条件查询即为用户输入想要查询的条件,然后根据用户输入的条件进行查询. 当用户有 ...