代码:

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Exameple 9.14 \n\n'); time_stamp = datestr(now, 31);
[wkd1, wkd2] = weekday(today, 'long');
fprintf(' Now is %20s, and it is %7s \n\n', time_stamp, wkd2);
%% ------------------------------------------------------------------------ % Given Parameters: D = 2; Rp = 0.1; As = 50; wxp = pi/8; wxs = pi/D; wp = wxp; ws = (2*pi/D)-wxs; % Filter Design:
[delta1, delta2] = db2delta(Rp, As); [N, F, A, weights] = firpmord([wp, ws]/pi, [1, 0], [delta1, delta2], 2); N = ceil(N/2)*2;
h = firpm(N, F, A, weights);
delay = N/2; % delay imparted by the filter %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- % Input signal x(n) = cos(2*pi*n/16)
n = [0:256]; x = cos(pi*n/8);
n1 = n(1:33); x1 = x(33:65); % for plotting purposes Hf1 = figure('units', 'inches', 'position', [1, 1, 8, 6], ...
'paperunits', 'inches', 'paperposition', [0, 0, 6, 4], ...
'NumberTitle', 'off', 'Name', 'Exameple 9.14');
set(gcf,'Color','white'); TF = 10; subplot(2, 2, 1);
Hs1 = stem(n1, x1, 'filled'); set(Hs1, 'markersize', 2, 'color', 'g');
axis([-2, 34, -1.2, 1.2]); grid on;
xlabel('n', 'vertical', 'middle'); ylabel('Amplitude', 'vertical', 'middle');
title('Input Singal: x(n) = cos(\pin/8) ', 'fontsize', TF, 'vertical', 'baseline');
set(gca, 'xtick', [0:8:32]);
set(gca, 'ytick', [-1, 0, 1]); % Decimation of x(n): D = 2
y = upfirdn(x, h, 1, D);
m = delay+1:1:128/D+delay+1; y1 = y(m); m = 0:16; y1 = y1(14:30); subplot(2, 2, 3);
Hs2 = stem(m, y1, 'filled'); set(Hs2, 'markersize', 2, 'color', 'm');
axis([-1, 17, -1.2, 1.2]); grid on;
xlabel('m', 'vertical', 'middle'); ylabel('Amplitude', 'vertical', 'middle');
title('Output Singal: y(n): D=2', 'fontsize', TF, 'vertical', 'baseline');
set(gca, 'xtickmode', 'manual', 'xtick', [0:8:32]/D);
set(gca, 'ytickmode', 'manual', 'ytick', [-1, 0, 1]); % Filter Design Plots
[Hr, w, a, L] = Hr_Type1(h); Hr_min = min(Hr); w_min = find(Hr == Hr_min);
H = abs(freqz(h, 1, w)); Hdb = 20*log10(H/max(H)); min_attn = Hdb(w_min);
subplot(2, 2, 2);
plot(w/pi, Hr, 'm', 'linewidth', 1.0); axis([0, 1, -0.1, 1.1]); grid on;
xlabel('Frequency in \pi units', 'fontsize', TF, 'vertical', 'middle');
ylabel('Amplitude', 'vertical', 'cap');
title('Amplitude Response', 'fontsize', TF, 'vertical', 'baseline');
set(gca, 'xtick', [0, wp/pi, ws/pi, 1], 'ytick', [0, 1]); subplot(2, 2, 4);
plot(w/pi, Hdb, 'm', 'linewidth', 1.0); axis([0, 1, -60, 10]); grid on;
xlabel('Frequency in \pi units', 'fontsize', TF, 'vertical', 'middle');
ylabel('Decibels', 'vertical', 'cap');
title('Log-magnitude Response', 'fontsize', TF, 'vertical', 'baseline');
set(gca, 'xtick', [0, wp/pi, ws/pi, 1], 'ytick', [-60, round(min_attn), 0]);

  运行结果:

设计的滤波器达到51dB的衰减,并且减采样的信号是正确的。

《DSP using MATLAB》示例 Example 9.14的更多相关文章

  1. 《DSP using MATLAB》Problem 7.14

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

  2. 《DSP using MATLAB》Problem 6.14

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

  3. 《DSP using MATLAB》Problem 5.14

    说明:这两个小题的数学证明过程都不会,欢迎博友赐教. 直接上代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  4. 《DSP using MATLAB》Problem 4.14

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

  5. 《DSP using MATLAB》Problem 2.14

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

  6. 《DSP using MATLAB》Problem 8.14

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

  7. DSP using MATLAB 示例Example3.21

    代码: % Discrete-time Signal x1(n) % Ts = 0.0002; n = -25:1:25; nTs = n*Ts; Fs = 1/Ts; x = exp(-1000*a ...

  8. DSP using MATLAB 示例 Example3.19

    代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Discrete-time Signa ...

  9. DSP using MATLAB示例Example3.18

    代码: % Analog Signal Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t)); % Continuous-time Fou ...

  10. DSP using MATLAB 示例Example3.23

    代码: % Discrete-time Signal x1(n) : Ts = 0.0002 Ts = 0.0002; n = -25:1:25; nTs = n*Ts; x1 = exp(-1000 ...

随机推荐

  1. com.sun.image.codec.jpeg在Eclipse中报错的解决办法

    在Eclipse中处理图片,需要引入两个包:import com.sun.image.codec.jpeg.JPEGCodec;import com.sun.image.codec.jpeg.JPEG ...

  2. cocos2dx 3.x 拼图小游戏

    .h #define IMAGE_MAX 2 //图片的个数.. //图片结构体 属性 struct IMAGE_DATA { cocos2d::Sprite *m_pImage; bool m_bO ...

  3. ng-深度学习-课程笔记-6: 建立你的机器学习应用(Week1)

    1 训练/验证/测试集( Train/Dev/test sets ) 构建神经网络的时候有些参数需要选择,比如层数,单元数,学习率,激活函数.这些参数可以通过在验证集上的表现好坏来进行选择. 前几年机 ...

  4. python: 基本的日期与时间转换

    需要执行简单的时间转换,比如天到秒,小时到分钟等的转换. 为了执行不同时间单位的转换和计算,请使用datetime 模块.比如,为了表示一个时间段,可以创建一个timedelta 实例,就像下面这样: ...

  5. shell给tcp或udp服务发送16进制报文指令

    指令:(sleep 2;echo "000F737D61747573" | xxd -r -p ;sleep 1)|nc 192.168.137.1 15000|hexdump - ...

  6. [3dSmartSystem] - Java&3d

    Java如果简单的做为Dynamic web project的工具来说,实现数据的前端到后端的传递及存储等. 就像一个银行,你去柜台(前端)给服务人员或者机器一些钱,之后输入密码,然后服务人员(后端处 ...

  7. BZOJ 3572 【HNOI2014】 世界树

    题目链接:世界树 首先看到\(\sum m_i\le 3\times 10^5\)这个条件,显然这道题就需要用虚树了. 在我们构建出虚树之后,就可以用两遍\(dfs\)来求出离每个点最近的议事处了.然 ...

  8. php 关联数组遍历

    <?php $age=array("); foreach($age as $x=>$x_value) { echo "Key=" . $x . ", ...

  9. nohup 不生成 nohup.out的方法

    nohup java -jar /xxx/xxx/xxx.jar >/dev/>& & 关键在于最后的 >/dev/>& 部分,/dev/null是一个 ...

  10. display:box,按比列划分,水平均分,及垂直等高

    一.按比例划分 <div class="test"> <p id="p1">Hello</p> <p id=" ...