フィルターのクリア

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

2 ビュー (過去 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 Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by