简体   繁体   中英

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

I'm very new to the Matlab and 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. 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

I understand it is because of the axis difference. Though, I don't understand why octave gives only a single value for h. The function Impz should describe a curve all along thee values of n, but i doesn't.

Thanks

The issue comes from impz returning a scalar in this case

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). 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. 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:

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 . Alternatively, run which impz to find where is the source for Octave's impz function, and fix it there for yourself now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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