LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sine Wave Frequency Issue

Hi everyone,

 

I am trying to generate sine waves using loop iteration counter and wait() function as shown in the attached figures. I thought if loop iteration counter is i and wait time is x milliseconds, and I make i divided by y and multiplied by 2*pi, then the sine wave period would be x times y milliseconds, right? So for the two pictures attached, I expect their frequency would be the same (1 Hz); but they are not the same. Can anyone let me know what went wrong?

 

Thanks!

Download All
0 Kudos
Message 1 of 5
(1,772 Views)

Are they in a loop?

 

You say they are not the same, but you haven't shown us anything as to why you think that, just a couple of pictures of code.  And you haven't told us anything about the hardware you are using.

 

My guess is that you are relying on software timing which is not reliable, particularly when you get down to millisecond values.

0 Kudos
Message 2 of 5
(1,760 Views)

Thank you for your reply.

 

Yes, each of them are in a while loop that runs continuously. I have attached the waveforms of the sine waves they generated: first one corresponds to 1 ms loop time, while the second one corresponds to 10 ms loop time. I would expect they are both 1 Hz (since 1000 iterations times 1 ms loop time and 100 iterations times 10 ms loop time will both give one cycle per second), but they are not.

 

I am running this on cRIO-9082 on the real-time target.

 

Please let me know your thoughts.

 

Thanks.

Download All
0 Kudos
Message 3 of 5
(1,731 Views)

Picture 1 looks like it takes 1000 samples to generate 1 cycle.  That is what I expect from 1.png in your first message.

 

(You really should give more descriptive names and make them different between the 2 messages since 1.png in message 1 is completely different than 1.png in message #3.)

 

Picture 2 looks like it take 1000 samples to generate 10 cycles.  That is what I expect from 2.png in your first message.

 

I bet you think that the X-axis is time, because that is what is says.  That is a label.  When you wire a scalar to the waveform chart, it just plots them in order.  So with picture #1, those samples are 1 msec apart.  1000 samples means 1 sec.  1 cycle in 1 second is 1 Hz.

 

In picture #2, those samples are 10 msec apart, so 1000 samples means 10 secocnds.  10 cycles in 10 secons is also 1 Hz.

 

You want to either send waveforms to your waveform chart, or set the properties of the x-axis so the scaling factor is .001 for the first VI and .01 for the second VI.  (dt=.001 seconds  for #1, dt=.01 seconds for #2).  That will make both X-axes show time in seconds, rather than "time" (a label) in samples.

 

0 Kudos
Message 4 of 5
(1,726 Views)

Thank you very much for your clarification! This is very helpful!

 

Yes, I apologize for the non-informative names...

0 Kudos
Message 5 of 5
(1,714 Views)