LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sinusoid with random periods

By now, you've seen numerous ways to generate the kind of cycle (one period of a cosine where the rising phase takes 60% of the cycle and the falling phase takes 40%) you seem to need (for example, see Mateh's post just before this one).  However, your overall requirement, I think, is something like this --

  • At regular time intervals (such as 50 msec), generate the next point of a continuous process of waves, each wave being a 60/40 sinusoid whose period is governed by a separate Poisson process.

Mateh's algorithm gives you all of the points for a specific period.  You can, of course, call this algorithm with another Period that you get by running your Poisson process, but how do you write a VI that, say, "gives you the next point" (so that you can send it to your display, your stimulator, what have you)?

 

I'm going to describe a State Machine that can do this, not worrying about stopping the State Machine, but then I'll turn it into an Action Engine by removing the "Wait for Delta-t" step in "Generate Next Point" and having the (now Action Engine) exit, saving data in its Shift Registers for next time.

 

I'm going to simplify Mateh's algorithm a bit -- I'm saying this in Words rather than Pictures because I think there is a didactic value to taking concepts and turning them into code using LabVIEW (can you guess what kind of "industry" I'm in?).  So here's the State Machine:

  • Initialize State -- calls "Start Next Period" (from now on, I'll name States, but won't add "State" at the end)
  • Start Next Period -- generates Period according to Poisson Process, generates Ramp (an array of numbers) from -pi to 0 (rising angles for Cosine wave) consisting of 60% of Period /Delta-t and takes the Cosine of this Ramp to generate Rising Phase, generates Ramp from 0 to pi (falling angles for Cosine Wave) consisting of 40% of Period/Delta-t, takes Cosine of Ramp to generate Falling Phase, concatenate two arrays to get Period Waveform, put in Shift Register.  Call Next Point.
  • Next Point -- wait Delta-t and then call Output Point.
  • Output Point -- delete the first point from the Array, returning the remaining Array to the Shift Register and "using" the point that you just obtained.  This is one point of the current period.  If the Shift Register has an Empty Array, call Start Next Period (to generate the next period according to your Poisson Process), otherwise Call Next Point.

I think this will do it for you.  Note that the only State with any computation of significance is Start Next Period, which generates all of the points for one period that then get "played out" slowly by Next Point.  Note that as described, you don't really need Initialize (but I always like to have Initialize be my first State in a State Machine, with Finalize the last ...).  It shouldn't be too hard to convert this to an Action Engine with an "Initialize" Action that "forces" the initial Start Next Period and exits with the Output Point when Output Point is reached, with "Next Point" being the other "callable" action.  [You can probably see that since you will do the "waiting" in the caller, you can probably eliminate Next Point, as well, and go directly to Output Point].

 

Bob Schor 

0 Kudos
Message 11 of 12
(809 Views)

Hello everyone,

 

Thank you very much for your help !

 

Mateh, your solution works perfectly. You've totally unederstand what is my aim.

 

Thank you too Johnsold and Bob Shcor for your help and proposition. I need little more time to think about it. I will work on it, and I'll turn to you if i've any questions.

Because I'm agree with you Bob Schor, the didactic value is important, mainly in my case as a neophyte in LabVIEW (in addtion, I think Bob works as a reasearcher and teacher (Ph. D)... Smiley Wink ).

 

Thank you again !

 

 

0 Kudos
Message 12 of 12
(780 Views)