Improving the code to change the dimension of the variable.(about the autocorrelation and autocorr)
1 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194769/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194771/image.png)
I have to write the code like the question said,and here is my code
N=16;
fD_Ts=0.001;
for n = 1:1:100
theta_n(n)=0+(2*pi)*rand(1,1);
phi_n(n)=0+(2*pi)*rand(1,1);
a_n=( (2*pi*n+theta_n)./N )
for m=1:1:1000
h_c=(1/N)*cumsum(cos(2*pi*m*fD_Ts*cos(a_n))+phi_n);
h_s=(1/N)*cumsum(sin(2*pi*m*fD_Ts*cos(a_n))+phi_n);
h_total=h_c+1i*h_s;
answer=autocorr(h_total);
end
end
Before looking the code,we know if we want to plot the (n,autocorrelation),n and autocorrelation have to be the same dimension,that is,1 by 100 matrix.However,i found that the dimension of answer is just 1*21 double,why?how should i improve my code to let the dimension of answer become from 1*21 to 1*100 ?
I don't know how to write the autocorrelation like the formula,if writing that formula is the only way,can anyone teach me how to write that code?Thanks a lot
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!