Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

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.

Re: Determine frequency

Would be possible to use Modelica "previous()"  or "pre()" function. It seems those are related to discrete domain. Do they work on continuous domain as well?

Re: Determine frequency

They can only be applied to discrete signals.

Re: Determine frequency

Maybe delay() is the right function for you?

Re: Determine frequency

Maybe delay() is the right function for you?

There are 0 guests and 0 other users also viewing this topic