필터 지우기
필터 지우기

Subplot function interfering with appropriate plot display

조회 수: 3 (최근 30일)
abbz123
abbz123 2017년 8월 23일
답변: Siambou Camara 2019년 9월 16일
When I try to use subplot to show impulse response and unit step response in the same figure, the impulse response plot displays incorrectly. Any idea why subplot is not plotting both the impulse response and unit step response appropriately? Uncomment the second section of code to see the problem. Thanks!
a = [1,-1,0.9];
b = [1];
n = [-20:120];
h = impz(b,a,n);
subplot(1,2,1); stem(n,h);
title('Impulse response'); xlabel('n'); ylabel('h(n)');
% %Plot unit step response ex. 2.11 b
% x = stepseq(0,-20,120);
% a1 = [1,-1,0.9]; b1 = [1];
% s = filter(b1,a1,x);
% n1 = [-20:120];
% subplot(1,2,2); stem(n1,s);
% title('Step response'); xlabel('n'); ylabel('s(n)');
  댓글 수: 1
Adam
Adam 2017년 8월 23일
편집: Adam 2017년 8월 23일
I can't run the code as I have no idea what stepseq is. Saying something 'displays incorrectly' is not very useful though. Please explain what is incorrect or attach a picture showing it.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2017년 8월 23일
The impulse and step responses are defined as beginning from 0, and do not exist for negative time. I can’t find ‘stepseq’ in the online documentation.
This works:
a = [1,-1,0.9];
b = [1];
n = [-20:120];
[h,t] = impz(b,a,n);
subplot(1,2,1); stem(t,h);
title('Impulse response'); xlabel('n'); ylabel('h(n)');
%Plot unit step response ex. 2.11 b
% x = stepseq(0,-20,120);
a1 = [1,-1,0.9]; b1 = [1];
s = stepz(b1,a1,120);
n1 = [-20:120];
subplot(1,2,2); stem(n1',[zeros(21,1); s]);
title('Step response'); xlabel('n'); ylabel('s(n)');
I would also stack them vertically rather than plot them horizontally, so use subplot(2,1,1) and subplot(2,1,2) instead.

추가 답변 (1개)

Siambou Camara
Siambou Camara 2019년 9월 16일
A well-known discontinuous function is impulse function that is defined as: δ(t) = 1 t = 0 0 otherwise. (1) In order to generate impulse function using matlab, follow the same steps as previous section, but this time using the following Matlab code.

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by