parse error at =... (need to get periodic function)

function [Y] = CircularConvolution(X,H)
a=0:1:50;
n1=length(X);
n2=length(H);
N=max(n1,n2);
X[n+a*N] = X[n]; %makes it periodic
H[n+a*N] = X[n]; %makes it periodic
Y=zeros(1,N);
N
for k=0:N-1
for q=0:N-1
F=mod((k-q),N);
Y(k+1)=Y(k+1)+X(q+1)*H(F+1);
end
end
end
I need to make it so it calculates the convolution of a period sequence of numbers that are user entered.
In order to make a sequence periodic, i tried to say X[n+a*N]=X[n] and H[n+a*N]=H[n] . However this comes up with a parsing error at the = sign. Matlab does not seem to like the brackets, however I dont know how else to make this periodic. Any Ideas?

 採用された回答

Image Analyst
Image Analyst 2014 年 11 月 23 日

0 投票

In that context you need to use round parentheses, not square brackets.

3 件のコメント

Ronald McDonald
Ronald McDonald 2014 年 11 月 23 日
That worked, however it says that n is an undefined variable.
Image Analyst
Image Analyst 2014 年 11 月 23 日
That's correct. What do you want n to be? You need to assign it. Since I solved the original question, could you mark the answer as accepted? I'll still help with your second question if you need it.
Ronald McDonald
Ronald McDonald 2014 年 11 月 23 日
function [Y] = myCONVCirc(X,H)
a=1:1:50;
n1=length(X);
n2=length(H);
N=max(n1,n2);
for n=1:1:N;
X(n+a*n1) = X(n); %makes it periodic
H(n+a*n2) = X(n); %makes it periodic
end
Y=zeros(1,N);
N
for k=0:N-1
for q=0:N-1
F=mod((k-q),N);
Y(k+1)=Y(k+1)+X(q+1)*H(F+1);
end
end
end
Changed it to this. It runs, does it work and make sense though? I dont have much experience with MatLab syntax. Thank You by the way.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by