LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a sin wave from a square wave

Solved!
Go to solution

I'm working on a project that involves creating synchronization waveforms to be used outside of an NI compact Rio. I can guarantee that my cRIO clock times are synchronized (using TSN/802.1AS in the cRIO 9035s). Based on an example I found, I have labview generating a square wave based on switching the signal every time period N (using the clock as the reference). However, I'm having trouble finding a way to convert this signal into a sin wave. What is the best way to convert my square wave of frequency F into a sin wave of frequency F? 

0 Kudos
Message 1 of 9
(5,169 Views)

Hi msmit,

 

when F is known you can use the sin generator in your FPGA…

 

Or use a good low-pass filter at the output of your square wave! 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(5,119 Views)

Another option would be to create a look up table with a (quarter of a) sin wave. Then use time as an index in the table. Calculate the proper index and negate the output if you stored a quarter of the sin wave to save FPGA memory. Very old school, but it still works!

Message 3 of 9
(5,113 Views)

just wire a VCO.vi and and PLL.vi   ...   with solder 😄

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 4 of 9
(5,083 Views)

Thanks all. I think I'll just end up using a low pass filter.

0 Kudos
Message 5 of 9
(5,078 Views)
Solution
Accepted by topic author msmit250

While I haven't bench-marked it, I suspect you have chosen the worst method to do this.  The fastest, certainly, is the simple look-up (or just compute using the Sin function from the Math Palette).  Direct, basically one operation per time point, no "approximation", etc.

 

Bob "IMHO" Schor

0 Kudos
Message 6 of 9
(5,069 Views)

@Bob_Schor wrote:

While I haven't bench-marked it, I suspect you have chosen the worst method to do this.  The fastest, certainly, is the simple look-up (or just compute using the Sin function from the Math Palette).  Direct, basically one operation per time point, no "approximation", etc.

 

Bob "IMHO" Schor


I don't have a FPGA at hand, but does the sine function work on FPGA? I'd think it doesn't, that's why I recommended a LUT.

 

Some sine wave approximation algorithm (google) might work too.

0 Kudos
Message 7 of 9
(5,038 Views)

wiebe@CARYA wrote:

@Bob_Schor I don't have a FPGA at hand, but does the sine function work on FPGA? I'd think it doesn't, that's why I recommended a LUT.

 

Some sine wave approximation algorithm (google) might work too.


Good call.  There is a Sin function on FPGA, but not on a RT Platform.  I agree that the LUT would be simple and fast -- I used it a few decades ago to generate a Sum-of-Sines "unpredictable" waveform on a PDP-11 ...

 

Bob Schor

0 Kudos
Message 8 of 9
(5,018 Views)

@Bob_Schor wrote:

wiebe@CARYA wrote:

@Bob_Schor I don't have a FPGA at hand, but does the sine function work on FPGA? I'd think it doesn't, that's why I recommended a LUT.

 

Some sine wave approximation algorithm (google) might work too.


Good call.  There is a Sin function on FPGA, but not on a RT Platform.  I agree that the LUT would be simple and fast -- I used it a few decades ago to generate a Sum-of-Sines "unpredictable" waveform on a PDP-11 ...

 

Bob Schor


I'd say on RT, you can use the normal Sine function(s) from Mathematics palette?

 

I used sine LUT's a lot back in the 90's to make C64 demo's\intros (this one is not mine, just the first I could find)! 

Message 9 of 9
(4,993 Views)