FIR Filter 10th order with a for loop

조회 수: 7 (최근 30일)
Abd Alsalam Al Saell
Abd Alsalam Al Saell 2021년 5월 2일
댓글: David Fletcher 2021년 5월 3일
i'm trying to filter a signal with a 10th order differential equation and for loop, with the following code, but i'm keep getting this error
Array indices must be positive integers or logical values.
Error in EOG (line 106)
new_data = data_h(k:-1:k-10);
can you please help me fix it , and tell me if it's a code or just syntax error?
TimeStamp = 0:T:59.99;
N = 10;
Fg = 1;
Wn = Fg/2;
aTP = fir1(N,Wn);
for k = 1:numel(data_h)
new_data = data_h(k:-1:k-10);
Y(k) = aTP.*new_data;
end
plot(TimeStamp,data_h,TimeStamp,Y)
legend("data_h","Y")

채택된 답변

David Fletcher
David Fletcher 2021년 5월 2일
On the first iteration of your loop the indexing expression will expand to
new_data = data_h([1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9])
As the error says: you can't index with zero or negative values
  댓글 수: 2
Abd Alsalam Al Saell
Abd Alsalam Al Saell 2021년 5월 3일
first of all thanks!
but one more error -_-
--> Unable to perform assignment because the indices on the left side are not compatible with the
size of the right side.
Error in EOG (line 108)
Y(k) = aTP.*new_data';
.
.
.
n = 0;
for k = 1:numel(data_h)
n = n+11;
new_data = data_h(k:n);
Y(k) = aTP.*new_data';
end
.
.
.
David Fletcher
David Fletcher 2021년 5월 3일
In this case the error is that you are trying to cram a vector into a single column. If you want to save the data from each iteration use:
Y(k,:) = aTP.*new_data';

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by