Showing results for 
Search instead for 
Did you mean: 

Plot synchronous sine waves

Go to solution

Hallo, I've just started using Labview so I'm sorry if this is a question with simple answer I couldn't manage to find on my own.


I am using Labview FPGA to read a sine wave from a signal generator, of this sine wave I know phase, amplitude, offset and frequency (I know them from the settings of the signal generator but I also retrieve them using the Extract Single Tone from Programming/Waveform/Analog Waveform/Waveform Measurements). Using the Sine in the Signal Processing/Waveform Generation palette I wanted to create an identical sine wave so that if I subtract the two signals the result (let's say x) will be 0 at each instant (and the corresponding x^2 should be equal to 0 as well) but when I plot the two waves and x^2 this does not happen, the two waves do not constantly overlap, it's like one is moving faster than the other and only in some particular occasions they overlap, does anybody know why?

The final aim of the work is actually to create a phasor controller acting in feedback that, given the average of x^2 can adjust the phase of the sine in order to create a sine wave identical to the input signal (in the case we cannot retrieve its phase from the beginning) but I can't understand if my controller is working well because at the moment the input signal and the sine wave are not identical even if I take all the values needed from the input signal and feed them to the labview wave generator to create the perfectly matching sine wave.

I attach a picture of the block diagram and the plots I get.

Thanks in advance for any help/suggestions.


0 Kudos
Message 1 of 14

Looking at your "mismatch" figure, I see two sinusoids with similar amplitude and frequency, but different phase (which manifests itself as a shift along the Time axis).


While it is fine to submit pictures of data, please do not submit pictures of LabVIEW code -- it is very difficult to examine or test a picture (unless it is a Snippet, which you could look up (click on the Edit button on LabVIEW's Menu bar).


Bob Schor

0 Kudos
Message 2 of 14

Yes, I thought the problem was a mismatch in the phase but if I read the sinusoidal signal with FPGA, retrieve it's amplitude, frequency and phase using the Extract Tone and then pass these info as input to the Sine, shouldn't the created sine waveform be identical (even in phase) to the sinusoidal signal I am reading?


I'm sorry about the image, I didn't know about the snippet, which I attach now.

0 Kudos
Message 3 of 14

@Alefbb wrote:


I am using Labview FPGA to read a sine wave from a signal generator, of this sine wave I know phase, amplitude, offset and frequency (I know them from the settings of the signal generator but I also retrieve them using the Extract Single Tone from Programming/Waveform/Analog Waveform/Waveform Measurements).

Programming won't fixed your problem. Your external function generator has its own internal clock, your FPGA has its own internal clock. Both are making a sine wave with respect to this internal clock. Since these clocks are not the same you will have drift.


If your function generator has an 10MHz external output, you could input this to your FPGA, and use it to create your sine wave. You would count pulses in the 10MHz clock and output appropriately.




EDIT: If your function generator has a 10MHz input, you could make a 10MHz signal with your FPGA and use that to sync.

0 Kudos
Message 4 of 14

Best case: synchronize your function generator and FPGA acquisition by sharing a common clock as mcduff suggests.


Are you seeing this relative drift within 7500 samples? or does it take many blocks for the signals to show the phase offset and then realign?


Extract Single Tone should produce a best-estimate tone for the input time signal in. Can you share the time-domain data that produces the observed mismatch? Even with your code snippet, we don't have access to the shared variables. 

NI Sound and Vibration
0 Kudos
Message 5 of 14

To synchronize clocks I tried to put the Sine Wave Generator (palette: FPGA Math&Analysis/Generation) directly inside the FPGA while loop, giving as inputs for frequency and phase two User-Defined Variables whose values come from the RT VI. I would like to plot the sine like I do for the signals that are read by the sensors but this is not working, what am I doing wrong? Thank you very much for your help!


In the snippets there are two VIs: the FPGA one and the RT one that is divided into a first snippet ('RT block diagram') of the elements not in the while loop and 4 wires that enter the while loop (second snippet: 'RT while loop block diagram'). At the bottom of this second snippet there is my first attempt to generate the sine wave directly in the RT VI. 

0 Kudos
Message 6 of 14

In your previous post you said you have two instruments a function generator and a FPGA. Now I am not sure.


if you are doing both on the FPGA then both can be synchronized. Have the inputs and sine generation in the same loop, see this



0 Kudos
Message 7 of 14

Sorry I wasn't clear about the instruments. I have a function generator connected to a NI9205 Analog Input Module that is installed in a compactRIO 9049 which is then connected to the computer. The idea I would like to develop is: I read a sine signal generated by the function generator, that is connected to AI, with Labview FPGA module. I send it to to perform FFT and retrieve frequency and amplitude (this values I actually know already since I am setting them on the function generator but this project is just to correctly implement a phasor controller that will then be applied to a system creating sine waves of which I do not know frequency and amplitude). I then use Sine Wave Generator inside the to create another sine wave, set frequency and amplitude equal to the one of the sine wave generated by the function generator and use the controller to adjust the phase of this second sine wave in order to make it equal to the one generated by the function generator. In the end I want to have to perfectly matching sine waves and plot them both to check if they overlap.

I tried doing this by creating the second sine wave in using Sine Waveform but it did not work, the two sine waves were not synchronized even if I gave as input to the Programming/Waveform/Analog Wfm/Generation/Sine Wfm all the information needed, i.e. frequency, amplitude and phase which I extracted from the Extract Single Tone Information applied to the sine wave generated by the function generator. So I could basically see that even giving the correct inputs to the Sine Waveform this did not match in phase the sine wave generated by the function generator, so it wasn't a problem of the controller (which I did not use in this experiment) but it was a problem of synchronization and I thought that this was caused because and did not share the same clock.

So I tried to create the second waveform directly on using the Sine Wave Generator from the FPGA palette but now I am having problems in plotting this second waveform.

I hope I have been clear on the project setup and I would really appreciate any help cause I've been stuck with this problem for a while. Thank you for all your advices!

0 Kudos
Message 8 of 14

I'm sure it's obvious to you, but from that description your entire setup can be replaced by a wire, so what do you actually want to do besides output the input?

Is the goal logging the parameters you measure? Or modifying the output (e.g. scaling, offset)? Or something else?


If you're looking to output your input, you can probably do it entirely on the FPGA even if you pass the data also to RT for measurements, and even if there's some reason a wire isn't a suitable alternative!

Message 9 of 14

I'm not really sure what do you mean by 'your entire setup can be replaced by a wire'. At this stage of the project my aim is to get a sine wave created from a signal generator and create an identical sine wave using the functions in the FPGA palette and this is quite trivial since I am setting the signal generator and therefore I already know frequency, phase and amplitude of the generated sine but I am pretending I do not know its phase and I need to find it using the controller, so the inputs I give to the Sine Wave Generator from the FPGA palette are amplitude and frequency (known) and phase (determined through the controller) and I need to check if the controller is working well by seeing if the actual two sine waves coincide so I would like to plot them, which I don't think it can be done in the At the moment the output of my Sine Wave Generator from the FPGA palette is just 0 and I don't understand why. 


0 Kudos
Message 10 of 14