need to create a loop with on this problem
Info
This question is closed. Reopen it to edit or answer.
Show older comments
i will put the data and then explain my problem
f=1:0.2:20 (matrix 1x96)
i=lenght(f)
ti= a matrix 82x1
yi= a matrix 82x1
the equations that are given to me to solve the problem are :
eq.1
T=(1/(4*pi*f))*(atan(sum(sin(4*pi*f*ti)))/(sum(cos(4*pi*f*ti))))
eq.2
P(f)=(((sum(yi*sin(2*pi*f*(ti-T)))).^2/(sum(sin(2*pi*f*(ti-T)).^2))+ ((sum(yi*cos(2*pi*f*(ti-T))).^2)/(sum(cos(2*pi*f*(ti-T)).^2))))*0.5;
so i need to calculate eq.1 (gives me the value of T, so i can do eq.2. i want the P(f), calculates for every value of f.
so in the end i can plot (f,p(f)) and get my periodrogram.
i have to adapt the equation so i can have the values that i need, because if i do the loop with the eq. that are given me it will give me the error" matrix dimensions are not the same"
I tried but the values that the eq.2 is giving me are wrong.
Answers (1)
Geoff Hayes
on 7 Nov 2015
Edited: Geoff Hayes
on 7 Nov 2015
João - are you looping over the values of f so that different values of T? If that is the case, then try the following
P = [];
k = 1;
for f=1:0.2:20
T=(1/(4*pi*f))*(atan(sum(sin(4*pi*f*ti)))/(sum(cos(4*pi*f*ti))));
P(f)=(((sum(yi*sin(2*pi*f*(ti-T)))).^2/(sum(sin(2*pi*f*(ti-T)).^2))+ ((sum(yi*cos(2*pi*f*(ti-T))).^2)/(sum(cos(2*pi*f*(ti-T)).^2))))*0.5;
k = k + 1;
end
The above may do what you expect, but there is a problem with your line of code for
P(f)=(((sum(yi*sin(2*pi*f*(ti-T)))).^2/(sum(sin(2*pi*f*(ti-T)).^2))+ ((sum(yi*cos(2*pi*f*(ti-T))).^2)/(sum(cos(2*pi*f*(ti-T)).^2))))*0.5;
There is a bracket mismatch, and (if that is resolved) there is an Inner matrix dimensions must agree. error with
(sum(yi*sin(2*pi*f*(ti-T))))
and
(sum(yi*cos(2*pi*f*(ti-T))).^2)
which you will need to resolve. You may also want to verify other parts of the equation too. For example, the above two lines are similar but the first may have more brackets than intended.
3 Comments
João Bernardo
on 7 Nov 2015
João Bernardo
on 7 Nov 2015
Edited: Geoff Hayes
on 7 Nov 2015
Geoff Hayes
on 7 Nov 2015
While that is different than what I showed, the result is the same: in either example, we iterate over the different values of f. What is the problem with the above? Have you fixed the unbalanced parenthesis?
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!