• 《DSP using MATLAB》示例 Example 9.10


    代码:

    %% ------------------------------------------------------------------------
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Exameple 9.10 
    
    ');
    
    time_stamp = datestr(now, 31);
    [wkd1, wkd2] = weekday(today, 'long');
    fprintf('      Now is %20s, and it is %7s  
    
    ', time_stamp, wkd2);
    %% ------------------------------------------------------------------------
    
    % Given parameters:
    n = [0:50]; wxp = 0.5*pi; x = cos(wxp*n);
    n1 = n(1:9); x1 = x(9:17);             % for plotting purposes
    
    I = 5; Rp = 0.01; As = 50; wp = wxp/I; ws = (2*pi-wxp)/I; 
    [delta1, delta2] = db2delta(Rp, As); weights = [delta2/delta1, 1];
    [N, Fo, Ao, weights] = firpmord([wp, ws]/pi, [1, 0], [delta1, delta2], 2); N = N + 2;
    N
    
    %% -----------------------------------------------------------------
    %%                             Plot
    %% -----------------------------------------------------------------  
    
    % Input signal
    Hf1 = figure('units', 'inches', 'position', [1, 1, 8, 6], ...
    	'paperunits', 'inches', 'paperposition', [0, 0, 6, 4], ...
    	'NumberTitle', 'off', 'Name', 'Exameple 9.10');
    set(gcf,'Color','white'); 
    
    TF = 10;
    
    subplot(2, 2, 1); 
    Hs1 = stem(n1, x1, 'filled'); set(Hs1, 'markersize', 2, 'color', 'g');
    axis([-1, 9, -1.2, 1.2]); grid on;
    xlabel('n', 'vertical', 'middle'); ylabel('Amplitude'); 
    title('Input Signal x(n)', 'fontsize', TF);
    set(gca, 'xtick', [0:4:16]); 
    set(gca, 'ytick', [-1, 0, 1]);
    
    
    % Interpolation with Filter Design: Length M=31
    %M = 31; F = [0, wp, ws, pi]/pi; A = [I, I, 0, 0];
    h = firpm(N, Fo, I*Ao, weights); y = upfirdn(x, h, I);
    delay = (N)/2;                                                   % Delay imparted by the filter
    m = delay+1:1:50*I+delay+1; y = y(m); m = 0:40; y = y(81:121);   % for plotting
    
    
    subplot(2, 2, 3); 
    Hs2 = stem(m, y, 'filled'); axis([-5, 45, -1.2, 1.2]); grid on;
    set(Hs2, 'markersize', 2, 'color', 'm');
    xlabel('m', 'vertical', 'middle'); ylabel('Amplitude'); 
    title(' Output Singal y(n): I = 5', 'fontsize', TF);
    set(gca, 'xtick', [0:4:16]*I); 
    set(gca, 'ytick', [-1, 0, 1]);
    
    
    % Filter Desing 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, -1, 6]); grid on;
    xlabel('Frequency in pi units', 'vertical', 'middle'); ylabel('Amplitude'); 
    title('Amplitude Response ', 'fontsize', TF);
    set(gca, 'xtick', [0, wp/pi, ws/pi, 1]); 
    set(gca, 'ytick', [0, I]);
    
    subplot(2, 2, 4); 
    plot(w/pi, Hdb, 'm', 'linewidth', 1.0); axis([0, 1, -70, 10]); grid on;
    xlabel('Frequency in pi units', 'vertical', 'middle'); ylabel('Decibels'); 
    title('Log-magnitude Response ', 'fontsize', TF);
    set(gca, 'xtick', [0, wp/pi, ws/pi, 1]); 
    set(gca, 'ytick', [-70, round(min_attn), 0]);
    

      运行结果:

            设计的滤波器最小阻带衰减为53dB。

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    Linux查看硬盘使用情况
    2020/05/23,帮亲不帮理
    写作,阅读新单词
    fpga与asic的区别
    ASIC NP FPGA CPU有啥区别?
    基因编程时代要来临了?什么物种都可以创造?细思极恐
    视网膜识别VS虹膜识别 谁更胜一筹
    CNN进化史
    生物神经元与人工神经元模型
    tensorflow简介以及与Keras的关系
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/6913396.html
Copyright © 2020-2023  润新知