简体   繁体   English

我绘制结果时,Octave impz函数出现问题

[英]Problems with Octave impz function, in the moment I plot results

I'm very new to the Matlab and Octave "World". 我对Matlab和Octave“ World”非常陌生。 I've been suffering for some hours to make a simple script run. 为了编写一个简单的脚本,我已经苦了几个小时。 Problem is, my teacher wrote it on Matlab, and I can't find a way to make it work on Octave. 问题是,我的老师在Matlab上写了它,而我找不到使它在Octave上运行的方法。 The script finds the impulse answer for the system and plots the curve. 该脚本找到系统的脉冲答案并绘制曲线。 Here it is: 这里是:

b = [1]; a = [1, -1, 0.9]; n = [0:100];
h = impz(b,a,n);
stem(n,h);
subplot(1,1,1);
title('Impulse Response'); xlabel('n'); ylabel('h(n)');

The error is: 错误是:

error: stem: inconsistent sizes for X and Y error: called from stem >check_stem_arg at line 276 column 11 stem at line 37 column 40 stem at line 127 column 8 questao6_lab2 at line 4 column 1 错误:茎:不一致尺寸X和Y误差:从称为> check_stem_arg在管线276列在第11行 37柱在管线40干127列第4行第1列8 questao6_lab2

I understand it is because of the axis difference. 我了解是因为轴的不同。 Though, I don't understand why octave gives only a single value for h. 虽然,我不明白为什么八度只给h一个值。 The function Impz should describe a curve all along thee values of n, but i doesn't. Impz函数应该沿n的所有值描述一条曲线,但我没有。

Thanks 谢谢

The issue comes from impz returning a scalar in this case 问题来自在这种情况下impz返回标量

octave-gui:26> h = impz (1, [1, -1, 0.9], 0:100)
h =  1

while you are expecting a vector with 100 elements (which is what Matlab does). 而您期望一个包含100个元素的向量(Matlab就是这样做的)。 In Matlab, the third argument ( N ) can be a scalar stating the number of samples of the impulse response, or a vector specifying the values where to compute the impulse response. 在Matlab中,第三个参数( N )可以是表示脉冲响应样本数量的标量,也可以是指定在何处计算脉冲响应的值的向量。 In Octave, you can only specify a number of samples. 在八度中,您只能指定多个样本。 So do this instead: 因此改为:

h = impz (1, [1, -1, 0.9], 101);

In addition, it seems that Octave returns a row vector instead of a column vector so do this: 另外,似乎Octave返回了行向量而不是列向量,所以可以这样做:

h = impz (1, [1, -1, 0.9], 101)(:);

The reason why I am using (:) instead of .' 我之所以使用(:)而不是.' (transpose) is so that it continues working in the next version of the signal package where this will be fixed . (transpose)是这样,它可以继续在信号包的下一版本中修复该问题 Alternatively, run which impz to find where is the source for Octave's impz function, and fix it there for yourself now. 或者,运行which impz来找到Octave的impz函数的来源,然后立即为它自己修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM