【问题标题】:Trying to discretize a continuous signal but I'm trying to plot the regular signal given roots试图离散化连续信号,但我试图绘制给定根的常规信号
【发布时间】:2019-01-20 02:15:17
【问题描述】:

我需要根据根绘制一个函数,我可以使用 poly() 来获取多项式。但是,每当我运行该函数时,它都会给我一个错误。我希望能够修复错误,以便继续实现我的进一步目标。

我需要根据我提供的时间域绘制函数,根据采样指数 nVec 乘以采样率 deltaT 绘制函数,然后绘制离散信号。我现在停下来,因为我无法绘制连续信号(第一个图)。它一直给我一个错误。我尝试将根 (rootsVec) 从负包含更改为纯正,因此我可以从 poly() 中获得方程,并将采样率用于时间增量,但无济于事。

    function [tVec,nVec,xVec] = 
    fxNthOrderPolyDTSignal(domainVec,noOfSamples,rootsVec)
    DSIntervals = noOfSamples - 1;
    deltaT = (max(domainVec) - min(domainVec))/DSIntervals;
    %time = input("Please input a specific time within the domain: ");
    nVec = min(domainVec)/deltaT;
    tVec = min(domainVec) + (nVec * deltaT);
    Eqtn = poly(rootsVec);
    x = linspace(domainVec(1),0.5,max(domainVec));
    figure(1)
    plot(Eqtn(x),x)
    figure(2)
    plot(Eqtn,(nVec*deltaT))
    end

预期结果只是带有以下输入参数的信号图: domainVec = [-10, 10](这是信号存在的时间);

noOfSamples = 30;

rootsVec = [-3, 8](又名二阶多项式);

实际结果如下错误:数组索引必须是正整数或逻辑值。

【问题讨论】:

    标签: matlab signals


    【解决方案1】:

    检查这段代码,变量的正确命名,更多的信号处理风格......

    当 n=10 时,您将开始看到离散化。

    function [t,x,dt] = f(tlim,n,p)
    %% Function (Press 'Run Section' from here)
    
    % Parameters (Delete these for function to work)
    tlim=[-10 10];
    n=30;
    p=[-3 8];
    
    % Polinomial Coefficients from Roots
    a=poly(p);
    
    % Sampling Time
    dt=(tlim(2)-tlim(1))/n;
    
    % Evaluate
    t=linspace(tlim(1),tlim(2),n)';
    x=a(1)*t.^0+a(2)*t.^1+a(3)*t.^2;
    
    % Plot
    plot(t,x)
    

    【讨论】:

      【解决方案2】:

      我想通了。这是我的问题的正确答案。感谢您的帮助!

      function [tVec,nVec,xVec] = 
      fxNthOrderPolyDTSignal(domainVec,noOfSamples,rootsVec)
      deltaT = (max(domainVec) - domainVec(1))/noOfSamples;
      nVec = [0 : noOfSamples];
      tVec = [];
      for i = nVec
          tVec(end + 1) = min(domainVec) + (i*deltaT);
      end
      nomial = poly(rootsVec);
      xVec = polyval(nomial,tVec);
      subplot(3,1,1)
      plot(tVec,xVec)
      title('x(t)')
      subplot(3,1,2)
      stem(tVec,xVec)
      title('x[n]')
      subplot(3,1,3)
      stem(tVec,tVec*0)
      title('x(nDeltaT)')
      end
      

      【讨论】:

        猜你喜欢
        • 2015-04-22
        • 1970-01-01
        • 2016-06-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多