Attempted to access delta(-2); index must be a positive integer or logical. Error in ==> ANC at 20 h(n)=delta​(n-3)-2.70​83*delta(n​-4)+4.1861​*delta(n-5​)-3.0451*d​elta(n-6)+​0.73071*de​lta(n-7);

조회 수: 1 (최근 30일)
Dear all,
I got this error. please help me. thank you.
Attempted to access delta(-2); index must be a positive integer or logical.
Error in ==> ANC at 20
h(n)=delta(n-3)-2.7083*delta(n-4)+4.1861*delta(n-5)-3.0451*delta(n-6)+0.73071*delta(n-7);

채택된 답변

Walter Roberson
Walter Roberson 2016년 1월 25일
편집: Walter Roberson 2016년 1월 25일
When n is 1, n-3 is -2
You loop over n is going to have trouble unless you start at n = 8
What you initialize h(1) through h(7) to is a good question.
By the way, consider conv() with fliplr([0, 0, 1, -2.7083, +4.1861, -3.0451, +0.73071])
  댓글 수: 2
Kuheli Mondal
Kuheli Mondal 2016년 1월 25일
편집: Walter Roberson 2016년 1월 25일
Thank you................but if i start n=8 I can't get any point, by the way I send you the full code............can you help me?
clear
close all
N=20; %order of the filter
mu=0.1; %step size
fs=100; %sampling frequency
fn=30; %noise signal frequency
T=1/fs;
size=4;
A=2;
n=0:1/fs:size;
w=zeros(N,1);
x=zeros(N,1);
h=zeros(1,N);
y=zeros(N,1);
for n=1:N
x(n)=A*sin(2*pi*fn*1/fs*n); %noise signal
end
delta(n==0)=1;
for n=1:N
h(n)=delta(n-3)-2.7083*delta(n-4)+4.1861*delta(n-5)-3.0451*delta(n-6)+0.73071*delta(n-7);
end
Walter Roberson
Walter Roberson 2016년 1월 25일
for n=1:N at the end should be replaced with for n=8:N
By the way, after your "for n=1:N", n is going to be left at its last value, N, so in the next line, n==0 is going to be false so no values in delta will be initialized. You do not otherwise initialize delta so your delta is going to be an empty array, which is a problem. You need your delta array to be at least N long.
Your code does not use x after you calculate it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by