• 《DSP using MATLAB》Problem 2.8


    1、代码:

    从MATLAB官方网上下载的。

    %*************************************************************************%
    %A code for the Downsampler%
    %Author: Yashwant Marathe%
    %Date:20-12-2010%
    function [y ny] = dnsample(x,n,M)
    %x is a sequence over indices specified by vector n,M is the downsampling factor.
    
    param=n/M;
    %generates the parameter vector.This vector will decide which input samples will be present in the output.
    
    samp=fix(param)==param;
    %only those output vectors corresponding to indices where samp==1 will be present in the output.
    
    y=x(samp==1);
    %generates the output sequence
    
    ny=n(samp==1)/M;
    %generates the indices of the output sequence
    
    end
    %**************************************************************************

    2、代码

    %% ------------------------------------------------------------------------
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 2.8.2 
    
    ');
    
    banner();
    %% ------------------------------------------------------------------------
    
    n = [-50:1:50]; 
    x = sin( 0.125 * pi * n ); 
    
    M = 4;
    
    [y, m] = dnsample(x, n, M);
    
    
    figure('NumberTitle', 'off', 'Name', 'Problem 2.8.2')
    set(gcf,'Color',[1,1,1])                  % 改变坐标外围背景颜色
    
    subplot(2,1,1); stem(n, x); title('x sequence');
    xlabel('n'); ylabel('x(n)') ;
    grid on
    subplot(2,1,2); stem(m, y); title('y sequence');
    xlabel('n'); ylabel('y(m)');
    grid on;
    

      运行结果:

    3、代码

    %% ------------------------------------------------------------------------
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 2.8.3 
    
    ');
    
    banner();
    %% ------------------------------------------------------------------------
    
    n = [-50:1:50]; 
    x = sin( 0.5 * pi * n ); 
    
    M = 4;
    
    [y, m] = dnsample(x, n, M);
    
    
    figure('NumberTitle', 'off', 'Name', 'Problem 2.8.3')
    set(gcf,'Color',[1,1,1])                  % 改变坐标外围背景颜色
    
    subplot(2,1,1); stem(n, x); title('x sequence');
    xlabel('n'); ylabel('x(n)') ;
    grid on
    subplot(2,1,2); stem(m, y); title('y sequence');
    xlabel('n'); ylabel('y(m)');
    grid on;
    

      运行结果:

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    C# comboBox实现省市两级联动(winform)
    Alter用法
    封装SQLHelper
    杨中科版C#射击游戏
    C# TXT文件导入至数据库
    C# 手机号码归属地查询
    C#中从数据库导出至txt
    解决C#中txt文档导入数据库时,中文显示乱码的问题
    第一篇博文与技术无关 纯瞎扯
    全国省市数据库
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/7990073.html
Copyright © 2020-2023  润新知