代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 3.18 \n\n'); banner();
%% ------------------------------------------------------------------------ %% -------------------------------------------------------------------
%% y(n)=x(n)+x(n-2)+x(n-4)+x(n-6)
%% -0.81y(n-2)-0.81*0.81y(n-4)-0.81^3*y(n-6)
%% -------------------------------------------------------------------
a = [1, 0, 0.81, 0, 0.81^2, 0, 0.81^3]; % filter coefficient array a
b = [1, 0, 1, 0, 1, 0, 1]; % filter coefficient array b MM = 500; [H, w] = 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.18 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.18 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
%% ------------------------------------------------------------------- %% --------------------------------------------------
%% x1(n)=5+10*(-1)^n
%% --------------------------------------------------
M = 200;
n1 = [0:M];
x1 = 5 + 10*(-1).^n1; y1 = filter(b, a, x1); figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.1 M = %d',M));
set(gcf,'Color','white');
subplot(2,1,1);
stem(n1, x1);
xlabel('n'); ylabel('x1');
title(sprintf('x1(n) input sequence, M = %d', M)); grid on;
subplot(2,1,2);
stem(n1, y1);
xlabel('n'); ylabel('y1');
title(sprintf('y1(n) output sequence, M = %d', M)); grid on; %% --------------------------------------------------
%% x2(n)=1+cos(0.5pin+pi/2)
%% -------------------------------------------------- n2 = n1;
x2 = 1 + cos(0.5*pi*n2+pi/2); y2 = filter(b, a, x2); figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.2 M = %d',M));
set(gcf,'Color','white');
subplot(2,1,1);
stem(n2, x2);
xlabel('n'); ylabel('x');
title(sprintf('x2(n) input sequence, M = %d', M)); grid on;
subplot(2,1,2);
stem(n2, y2);
xlabel('n'); ylabel('y');
title(sprintf('y2(n) output sequence, M = %d', M)); grid on; %% --------------------------------------------------
%% x3(n)=2sin(pin/4) + 3cos(3pin/4)
%% -------------------------------------------------- n3 = n1;
x3 = 2*sin(pi*n3/4) + 3*cos(3*pi*n3/2); y3 = filter(b, a, x3); figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.3 M = %d',M));
set(gcf,'Color','white');
subplot(2,1,1);
stem(n3, x3);
xlabel('n'); ylabel('x');
title(sprintf('x3(n) input sequence, M = %d', M)); grid on;
subplot(2,1,2);
stem(n3, y3);
xlabel('n'); ylabel('y');
title(sprintf('y3(n) output sequence, M = %d', M)); grid on; %% ------------------------------------------------------------------------------
%% x4(n)=1+2cos(pin/4)+3cos(2pin/4)+4cos(3pin/4)+5cos(4pin/4)+6cos(5pin/4)
%% ------------------------------------------------------------------------------ n4 = n1;
sum = 0;
for i = 0:5
sum = sum + (i+1)*cos(i*pi*n4/4);
end
x4 = sum; y4 = filter(b, a, x4); figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.4 M = %d',M));
set(gcf,'Color','white');
subplot(2,1,1);
stem(n4, x4);
xlabel('n'); ylabel('x');
title(sprintf('x4(n) input sequence, M = %d', M)); grid on;
subplot(2,1,2);
stem(n4, y4);
xlabel('n'); ylabel('y');
title(sprintf('y4(n) output sequence, M = %d', M)); grid on; %% -----------------------------------------------------------------
%% x5(n)=cos(pin)
%% ----------------------------------------------------------------- n5 = n1; x5 = cos(pi*n5); y5 = filter(b, a, x5); figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.5 M = %d',M));
set(gcf,'Color','white');
subplot(2,1,1);
stem(n5, x5);
xlabel('n'); ylabel('x');
title(sprintf('x5(n) input sequence, M = %d', M)); grid on;
subplot(2,1,2);
stem(n5, y5);
xlabel('n'); ylabel('y');
title(sprintf('y5(n) output sequence, M = %d', M)); grid on; %% -----------------------------------------------------------------
%% x0(n)=Acos(w0n+theta)
%% -----------------------------------------------------------------
A = 3;
w0 = 0.2*pi;
theta = 0; n0 = n1; x0 = A * cos(w0*n0+theta); yss = filter(b, a, x0);
figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.6 M = %d',M));
set(gcf,'Color','white');
subplot(2,1,1);
stem(n0, x0);
xlabel('n'); ylabel('x');
title(sprintf('x0(n) input sequence, M = %d', M)); grid on;
subplot(2,1,2);
stem(n0, yss);
xlabel('n'); ylabel('y');
title(sprintf('yss(n) output sequence, M = %d', M)); grid on;

  运行结果:

1、LTI系统的频率响应

第1小题:

第2小题:

第3小题:

第4小题:

第5小题:

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

  1. 《DSP using MATLAB》Problem 6.18

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

  2. 《DSP using MATLAB》Problem 5.18

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

  3. 《DSP using MATLAB》Problem 4.18

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

  4. 《DSP using MATLAB》Problem 2.18

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

  5. 《DSP using MATLAB》Problem 8.18

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

  6. 《DSP using MATLAB》Problem 5.15

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

  7. 《DSP using MATLAB》Problem 4.15

    只会做前两个, 代码: %% ---------------------------------------------------------------------------- %% Outpu ...

  8. 《DSP using MATLAB》Problem 7.27

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

  9. 《DSP using MATLAB》Problem 7.26

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

随机推荐

  1. Mysql错误: Lock wait timeout exceeded 解决办法

    一.临时解决办法: 执行mysql命令:show full processlist; 然后找出插入语句的系统id 执行mysql命令:kill id 或 首先,查看数据库的进程信息: show ful ...

  2. spoj Prime Generator

    题意:判断ll-rr范围内的质数. 一个个用miller-rabin算法判断 //#pragma comment(linker,"/STACK:1024000000,1024000000&q ...

  3. pyoj61 双线DP

    传纸条(一) 时间限制:2000 ms  |  内存限制:65535 KB 难度:5   描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行 ...

  4. UVA-11584 Partitioning by Palindromes (简单线性DP)

    题目大意:给一个全是小写字母的字符串,判断最少可分为几个回文子序列.如:“aaadbccb” 最少能分为 “aaa” “d” “bccb” 共三个回文子序列,又如 “aaa” 最少能分为 1 个回文子 ...

  5. 一、重写(覆盖)override

    一.重写(覆盖)override 子类可以继承父类对象的方法,在继承后,重复提供该方法,就叫做方法的重写,又叫做覆盖override package property; //父类对象 public c ...

  6. SSH执行远程命令和传送数据

    $ ssh user@host 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub ...

  7. vnc xfce tab自动补全失效的解决方法

    edit~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml find the line <proper ...

  8. ubuntu下安装go语言;sublime+gocode搭建;go的卸载和环境变量配个人.bashrc;2空位3个网

    https://blog.csdn.net/needkane/article/details/36891949 https://www.jianshu.com/p/4f79ae4f081c http: ...

  9. sql存储过程中,如何根据指定日期、月数、天数推算预产日期

    我这边有一个业务,根据某个指定日期,推算某个患者的预产日期 原理:比如孕产的预产日期的算法(预产日期 = 末次月经日期+ 10月+8天) 那么我们怎么通过存储过程来实现呢? 首先分析条件 需要一个指定 ...

  10. 小程序数组型图片自适应效果的实现(交流QQ群:604788754)

    //本例代码如有问题,请加群,下载今日日期文件,测试.(如对本例有疑问,也可加群咨询群主) WXML: <view class="imgbox"> <block ...