someone who can help me to correct my problem please????

조회 수: 1 (최근 30일)
Miguel Amor Rodriguez Avelino
Miguel Amor Rodriguez Avelino 2022년 5월 2일
편집: DGM 2022년 5월 2일
n = 0:10;
%% Impluse Response:
hn = -4*(1/3).^n; hn(1) = hn(1) + 6;
b = [2 -2];
a = [1 -1/3];
hnz = filter(b,a,[1,zeros(1,length(n)-1)]);
% Plot
subplot(211)
stem(n,hn,'fill')
ylabel('h[n]')
title('Impulse Response Expression Sequence')
subplot(212)
stem(n,hnz,'fill')
xlabel('n')
ylabel('h[n]')
title('Sequence Computed from z-transform')
%% Response y[n]:
yn = 8*(1/3).^n - 6*(1/2).^n;
b = [2 -2];
a = [1 -5/6 1/6];
ynz = filter(b,a,[1,zeros(1,length(n)-1)]);
% Plot
subplot(211)
stem(n,yn,'fill')
xlabel('n')
ylabel('y[n]')
title('Response Expression Sequence')
subplot(212)
stem(n,ynz,'fill')
xlabel('n')
ylabel('y[n]')
title('Sequence Computed from z-transform')

답변 (1개)

DGM
DGM 2022년 5월 2일
편집: DGM 2022년 5월 2일
Since n is defined, and you're using cell mode, then I have to assume the problem is that you're running the last code section by itself before the first section has a chance to run. If you use ctrl+enter or "Run Section" in the toolbar, only the current section is executed.
%% this is the first section
n = 0:10;
%% Impluse Response: <-- the second section
hn = -4*(1/3).^n; hn(1) = hn(1) + 6;
b = [2 -2];
a = [1 -1/3];
hnz = filter(b,a,[1,zeros(1,length(n)-1)]);
% Plot
subplot(211)
stem(n,hn,'fill')
ylabel('h[n]')
title('Impulse Response Expression Sequence')
subplot(212)
stem(n,hnz,'fill')
xlabel('n')
ylabel('h[n]')
title('Sequence Computed from z-transform')
%% Response y[n]: <-- the third section
yn = 8*(1/3).^n - 6*(1/2).^n;
b = [2 -2];
a = [1 -5/6 1/6];
ynz = filter(b,a,[1,zeros(1,length(n)-1)]);
% Plot
subplot(211)
stem(n,yn,'fill')
xlabel('n')
ylabel('y[n]')
title('Response Expression Sequence')
subplot(212)
stem(n,ynz,'fill')
xlabel('n')
ylabel('y[n]')
title('Sequence Computed from z-transform')
If you want to run them as independent sections, the easy solution is to define n within each section instead of in a section by itself. Otherwise, you'll have to remember to run the first section before the others.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by