フィルターのクリア

For loop not working. Array indices must be positive integers or logical values.

1 回表示 (過去 30 日間)
matlabgod
matlabgod 2018 年 12 月 10 日
再開済み: Walter Roberson 2018 年 12 月 20 日
Im Trying to implement an FIR difference equation where the output y is the average sum of a set number of values(M) of the input(x).
f0=10;
fs= 2*50*f0;
ts=1/fs;
tw=2;
t=0:ts:tw;
x=1*square(2*pi*f0*t);
y = zeros(1,length(x));
k=6;
M=k;
for i=1:k
for j = 1:M
y(j) = y +(1/(M+1))*x(i-j);
end
end
figure, plot(t,y, 'k')
ylim([-1 1])

回答 (1 件)

James Tursa
James Tursa 2018 年 12 月 10 日
This line on the first iteration when i=1 and j=1:
y(j) = y +(1/(M+1))*x(i-j);
You are indexing x(0). Also, you are trying to assign a vector (y on the rhs) into an element y(j) which isn't going to work either. This needs to be fixed.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by