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);

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);

 Accepted Answer

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 Comments

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
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.

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!