LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sinusoid with random periods

Hello,

 

 

I'm just begin with LabVIEW, and I have some difficulties.

 

I would like to make a sinusoid (a graph) with random periods (or frequencies...) according to the Poisson distributiion.

But I would like too these random periods are "real time".

 

For exemple, if my poisson distribution generates 3, I want 3 secondes....

 

My first VI is not totally operational (cf. attachment).

 

 

N;B : derivative and condition structure are here for doesn't make a "symetric" sinusoid. It's an important point for my work.

 

Thank you in advance for your help.

0 Kudos
Message 1 of 12
(5,529 Views)

@LaClau wrote:

 

 

I would like to make a sinusoid (a graph) with random periods (or frequencies...) according to the Poisson distributiion.

But I would like too these random periods are "real time".

 


Either you don't understand what you are saying or I don't understand what you want to do.  What do you mean by a "sinusoid with a random period"?  If I write down the equation for a sinusoid, f(t) = A sin (w*t + phi), this is a (fixed) function of time, t.  When you say "random frequencies", you are talking about making w (omega -- frequency in radians) a "random" quantity, I presume.  But since you are dealing with a time-series, I'm guessing you mean "randomly changing with time".

 

You are using an Express VI to generate the waveform.  This generally takes fixed (not random) values of A, w, and phi, and then generates that waveform for the length of time (or number of points) you specify.  Is that what you want to do, a few seconds at one frequency followed by a few seconds at another frequency?

 

Your task seems to me to be not well designed or thought out.  What is it that you are trying to do?  Never mind telling us how you will do it (because what you say makes little sense to me), but what are you trying to accomplish?  [Whatever it is, an Express VI to generate sinusoids should probably not be part of the design ...)

 

Bob Schor

0 Kudos
Message 2 of 12
(5,487 Views)

Hi LaClau,

 

First, consider how the Simulate Signal express VI is configured: It is set to output 100 samples at a simulated 1000 Hz sample rate. This means it will output only part of a sinewave representing 100 milliseconds in time with each iteration of the loop, regardless of what frequency you want the sinewave to be, or how long you program the loop to wait. Because you request a different frequency with each loop iteration, that is why you see the sinewave changing frequency several times within one period of the sinewave.

 

I don't completely understand what your goal is. Do you want to change the frequency at each zero crossing? It seems like it would be more ideal to change it at a maximum or minimum point instead.

 

EDIT: Bob, you are too quick... had this whole thing typed out and everything 😉

0 Kudos
Message 3 of 12
(5,475 Views)

First of all, I would like to thank you for your answers.

 

 

Sorry,  must begin again from the beginning. I would like to do :

 

 

-A  sinusoid which will serve as a  "respiration guide" for participant.  When curve increases, participant go inspire, and expire when courb decreases.

 

-For each periods of this sinusoid : the inspiration must last 3/5 of period and expiration must last 2/5.

 

-Periods (so also frequencies) must be random according to Poisson distribution (between 2s and 10s).

 

 

Bob_Schor

 

"I'm guessing you mean "randomly changing with time".
In fact, i would like to have, when my Poisson distribution generates 3, a sinusoid with a period which last 3seconds.

 

"Is that what you want to do, a few seconds at one frequency followed by a few seconds at another frequency?

Utterly ! Of course, with seconds which will depend of number generates by Poisson distribution.

 

Mateh

 

"Do you want to change the frequency at each zero crossing?

Yes.Smiley Wink

 

It seems like it would be more ideal to change it at a maximum or minimum point instead

How can I do this ?

 

 

 

Whatever the case, I have to change my Express VI... But what can I use instead ?

 

0 Kudos
Message 4 of 12
(5,433 Views)

Your latest description is much more clear.

 

I do not have time to try anything now but I would use the Sine Pattern.vi from the Signal Processing >> Signal Generation palette. Set it to generate one cycle each time you call it. Calculate the number of samples required for 3/5 and 2/5 of the period from your random period generator. Call Sine Pattern.vi twice, once for the inpiration segment and once for the expiration segment. Append the two arrays.  You may need to select the sample rate to get integer numbers of samples for every period over the possible range.  Even small errors may result in significant "glitches" at the transitions between segments.

 

Repeat for the next period.

 

Since you are talking about respiration, the times involved are quite long compared to the time it will take the comuter to do these calculations. So, you can either doe the entire set of calculations in advance and store the data for the entire experiment, or calculate the next period while the current period is running.

 

Lynn

0 Kudos
Message 5 of 12
(5,398 Views)

I agree, that description helps a lot.

 

You could also plot discrete points in "real time" by using a basic trig function in a For Loop. In this example, the first loop creates an array of points between 0 to pi (rising edge of -cosine), the second loop creates an array of points between pi and 2*pi (falling edge of -cosine). As you can see, the ratio of points in each of these arrays is determined by the duty cycle control, and the total number of points is determined by the requested period divided by the update rate of the graph. The rising and falling edge are concatenated together, and all of the points are sent to the Cosine function. Instead of using the control to set the total period, you could wire the output of your poisson function into it.

 

cosine with duty cycle.png

 

 

Message 6 of 12
(5,376 Views)

Hi !

 

Thank you ! If I've understood, my VI should look like this :

 

02.png

 

 

But, some questions remain :

 

- It should be a duty cycle control for each for loop  ?

 

- Why 0.05 for update period ?

 

- Sine wave's rate is too fast. How can I set it ?

 

0 Kudos
Message 7 of 12
(5,343 Views)

Lynn, I think your idea is the same...

 

But how can i do this, whereas my period are totally random ?

"Set it to generate one cycle each time you call it. Calculate the number of samples required for 3/5 and 2/5 of the period from your random period generator."

 

 

0 Kudos
Message 8 of 12
(5,338 Views)

Hi LaClau,

 

Open and run the VI that I've attached. The default value of the Total Period control is 3 seconds, the duty cycle is set to 60 percent, and the update rate is 50 milliseconds. That means the graph will plot a rising edge that is 1.8 seconds long (60% * 3 seconds), then a falling edge that is 1.2 seconds long (40% * 3 seconds), and it will take 3 seconds to plot the entire waveform in real time.

 

The 50 millisecond update rate means there will be 50 milliseconds between each point in the waveform. You can change these values to whatever you want. If this isn't what you're trying to do, then I'm afraid I've misunderstood your goal.

Message 9 of 12
(5,321 Views)

Here is an example of what I had in mind.

 

1. Calculate the least common multiple of the periods and multiply that by 5. The multiplication is to account for the 2/5 and 3/5 fractions of duty cycle for rising and falling segments.

2. Generate an approximate Poisson distribution of periods. When you cap the maximum value (at 10 for example), the distribution will no longer be purely Poisson.

3. Calculate the number of samples per period by dividing LCM*5 by the periods.

4. Calculate the number of samples for the rising and falling segments.

5. Generate sine patterns for rising and falling segments.

6. Concatenate outputs.

 

Note that the LCM and histogram calculations are included in the VI so that other values of minimum and maximum period can be used. The outputs of LCM and LCM*5 are not wired to the sinusoid generation.

 

Lynn

0 Kudos
Message 10 of 12
(5,312 Views)