- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Determine frequency
Determine frequency
Determine frequency
Dears,
I am trying to determine the frequency of v_signal (rotational vector) which is given by its alpha,beta components.
v_angle = atan2(v_beta, v_alpha);
der(v_freq) = v_angle;
Unfortunately atan2 returns the angle with discontinuity and following der() function can't determine frequency of v_signal.
I am looking for a solution in Modelica for this. Do you have any idea to solve this?
Thank you.
Best regards,
peb
Re: Determine frequency
Actually I am looking for "unwrap" Matlab-like function in Modelica scope
http://www.mathworks.com/help/matlab/ref/unwrap.html
...
v_angle = atan2(v_beta, v_alpha);
unwrapped_angle = unwrap(v_angle);
der(v_freq) = unwrapped_angle;
...
Re: Determine frequency
%Unwrap the signal xw(n)
xu = xw;
for i=2:length(xw)
difference = xw(i)-xw(i-1);
if difference > pi
xu(i:end) = xu(i:end) - 2*pi;
elseif difference < -pi
xu(i:end) = xu(i:end) + 2*pi;
end
end
I would prefer to do it "continually" but not on sampled signal batch as code snippet ...
Any idea how to do it under Modelica?
Thanks.
Re: Determine frequency
The only way you can access the previous value of something is by sampling/discrete events in Modelica.
I think you need to look for discontinuities in some way similar to:
Code:
algorithm
v_angle = atan2(v_beta, v_alpha);
if v_angle+n*pi > pi then
n := n - 1;
elsif v_angle+n*pi < -pi then
n := n + 1;
end when;
unwrapped_angle := v_angle - 2*n*pi;
der(v_freq) := unwrapped_angle;
I had another idea using a derivative that followed v_freq and tracked that instead, but I think the above is simpler. I didn't check if it is correct though.
- sjoelund.se
- 1700 Posts
Re: Determine frequency
They can only be applied to discrete signals.
- sjoelund.se
- 1700 Posts
Re: Determine frequency
Maybe delay() is the right function for you?
- ceraolo
- 147 Posts
Re: Determine frequency
Maybe delay() is the right function for you?
- ceraolo
- 147 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » Determine frequency