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

1 visualizzazione (ultimi 30 giorni)
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')

Risposte (1)

DGM
DGM il 2 Mag 2022
Modificato: DGM il 2 Mag 2022
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.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by