Measure phase difference between 2 signals

I am very new to labview. i m trying to use labview to measure phase between 2 signals from encoder. I also want to measure the state of 2 quadrature square signals. anyone has any idea how to do it?

Hi "rvn10",
Quadrature encoders do by nature have a phase difference of 90 degrees between channel A and B. This phase difference is required to know in which direction the shaft is rotating when a transition from one of the channels is received. Please see these two links for some useful information:
Encoders
Linear and Rotary Encoders
Quadrature Encoder / Position Measurement
If your goal is to measure the angular position using the two quadrature square signals, then your task is quite simple if you use one of our Counter/Timer cards. Check for example the shipping example called "Measure Angular Position.vi".
If you want to read more about our most affordable Counter/Timer product, then check this link:
NI PCI-6601
Please let us know if you are using different hardware to acquire the signals.
- Philip Courtois, Thinkbot Solutions

Similar Messages

  • How to find the phase difference between two signals using Hilbert transform

    hi, 
        I am new to LabView.... I am trying to find phase difference between two signals. I sucessfuly found out the phase difference between two predefined waves using single tone measurement. .... But I really want to know how can I measure phase difference between two signals( not predefined... ie we don't know the initial conditions) using hilbert transform or any transformation techniques (without using zero cross detection).. I tried by using hilbert transform based on algorithm... bt I am getting error.... plz help me
    Attachments:
    phase_differece.vi ‏66 KB

    you could try something similar to this, for each table pair that you want to compare:
    SELECT 'TABLE_A has these columns that are not in TABLE_B', DIFF.*
      FROM (
            SELECT  COLUMN_NAME, DATA_TYPE, DATA_LENGTH
              FROM all_tab_columns
             WHERE table_name = 'TABLE_A'
             MINUS
            SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
              FROM all_tab_columns
             WHERE table_name = 'TABLE_B'
          ) DIFF
    UNION
    SELECT 'TABLE_B has these columns that are not in TABLE_A', DIFF.*
      FROM (
            SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
              FROM all_tab_columns
             WHERE table_name = 'TABLE_B'
             MINUS
            SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH
              FROM all_tab_columns
             WHERE table_name = 'TABLE_A'
          ) DIFF;that's assuming, column_name, data_type and data_length are all you want to compare on.

  • Better estimation of phase difference between two signals with variable frequency!

    Hello LabView Gurus, 
    Being a power engineer and having just a little knowledge of signal processing and labview, I have been pulling my hair out for the last couple of days to get a better estimation of phase difference between two signals.
    We have two analog voltage signals; 1. sine wave (50Hz ± 1Hz) and 2. a square wave with exactly half of sine wave frequency at any time.
    At the starting point of operation (and simulation/acquisition) both signals will have no phase difference. However, the square wave's frequency changes unpredictably for a just a few millisecond but then it gets synchronized with sine wave's frequency again. This means that the square wave will be phased out from its original position. The task of the labview is to find the phase difference between the two signals continuously.
    My approach to determine the phase difference is to measure the time when sine wave crosses zero amplitude and the time when the very next square wave changes amplitude from zero volts to +ve voltage (I have a 0.5volts threshold just to avoid any dramas from small line noise). The difference between these times is then divided by the time period and multiplied by 360 to get this phase difference in angles. 
    As this part is just a small block of a big project, I can only allow 5000Hz sampling rate each for both signals. I read 500 samples (which means I read data from 5 cycles of sine wave and 2.5 cycles of square wave).
    Now the problem is, as long as the frequency of sine wave stays constant at exactly 50Hz, I get a good estimation of the phase difference but when the frequency changes even a little (and it will happen in the real scenario i.e 50Hz ± 1Hz  and the square wave's frequency is dependent of sine wave's frequency), the estimation error increases.
    I have attached my labview program. From front panel, you can set the phase of square wave (between -180 and 0) and you should see the labview's calculated phase in the indicator box named 'Phase'. Then you can press 'Real Frequency' switch that would cause the frequency to change like it would in real operation.
    You can observe that the estimation error increases after you push the button. 
    All I need to do is to reduce this estimation error and make it as close to the actual phase difference as possible. Any help would be greatly appreciated.
    I am using LabView 2009 for this task.
    The application is for electric machines and the stability/performance of machines under different faults.
    Thank you for reading this far!
    Regards,
    Awais
    Attachments:
    v603.png ‏320 KB
    v603.vi ‏186 KB

    Jeff Bohrer wrote:
    Basic math gives me a bit of pause on this approach.  You are sampling at 50 times the frequency of interest so you get 50 samples per cycle.  your phase resolution is 1/50th cycle or 7.2 degrees +/- noise.  You will need to samlpe faster to reduce phase resolution or average multiple readings (at a time cost that is signifigant)
    Jeff- (Hardly Working)
    I am sampling at 100 times the sine wave's frequency and 200 times the square wave's frequency.  Increasing the sampling rate completely solves my problem. But since I am acquiring several other inputs, I cannot afford a sampling rate higher than 5kHz.
    F. Schubert wrote:
    I'm not a signal processing expert, but here my basic understanding.
    If you simulate sampling with 5kHz and a frequency of 50 Hz (and both are 'sync' by design), you always get an exact 5 periods. Any variation of your signals frequency gives you a propability to get 4 or 6 'trigger' events. That's an up or down of 20%!
    The one measure to reduce such problems is using 'window functions'. They don't fit your current approach (counting instead of a DSP algorithm), so this needs to be reworked as well.
    My approach would be to use the concept of a Locki-In amplifier. You need to phaseshift your ref-signal by 90°. Then multiply your measurement signal with the ref signal and the phase shifted ref signal. The obtained values for x/y coordinates of a complex number. Calculate the theta of the complex number (with the LV prim). Feed this in a low pass filter.
    The trick on this is, that the square wave has harmonics in it, in this you are interested in the second harmonic which is the sine wave.
    To get rid of the effect that the sync between sampling rate and ref signal frequency gives an error, you then can use the window I mentioned above (place it before the lock-in).
    For a design that really plays well, use a producer-consumer design pattern to get the calculations done in parallel with the DAQ.
    I suggest you to check on wikipedia for some of the keywords I mentioned. Go also for the external links which lead to great tutorials and AppNotes on the signal processing basics.
    Sorry, it's not a simple solution I offer and we will have quite some conversation on this forum if you follow this path. Maybe someone else knows a simpler way.
    Felix
    www.aescusoft.de
    My latest community nugget on producer/consumer design
    My current blog: A journey through uml
    An interesting view. the sine wave can indeed be looked as a second harmonic of the square wave. I will implement your idea and get back to you as soon as I get some results. But since I have very limited knowledge of signal processing, it might take me a while to get my hear around the solution you mentioned.

  • Phase difference from 2 signals(HELP!)

     Hi! I'm having trouble finding accurate phase difference between two signals.. one signal is from the input serial communication arduino and the second signal is a simulated signal. I want to find the phase difference between these two. I've googled a lot and found many similar threads of phase difference measurements, but it won't work.
    The phase angle from the simulated signal is correct but the reading of the phase angle from the input signal keeps changing and I could not find an exact phase angle or phase difference.
    What do you think I should do?

    Doing phase difference measurements using two completely separate sets of hardware is in general a bad idea. You need to think carefully about how to synchronize the acquisition clocks of the computer vs. the Arduino. Better would be to measure your signal and generate your reference using one system, i.e. every time through the Arduino's outer loop, have it measure the voltage and also generate a reference level based on the internal clock, and transfer both to the computer.
    That said, unless you know the signal frequency very precisely a priori, the phase difference between a synthetic reference and a measured signal will inevitably drift with time, at a rate proportional to the difference between the nominal and actual frequencies of the sample signal. 

  • How to measure time difference between zero crossing of a sine wave and rise time of a pulse on a same graph?

    I have a 50Hz sine wave and a pulse signal on a same graph. The phase difference between two is between 0-90 degrees.
    Now I need to calculate the time difference between (when the sine wave crosses zero volts) and (when the pulse rises). The frequency will stay approximately same for both signals.
    The application is for a three phase generator. In simple words, when the time difference between the zero-crossing of sine wave and the pulse rises increases, that means that the load on the generator has increases.
    I am a beginner user of LabView (version 9, 2009), maybe it is a very simple problem but I've been pulling my hair out for the last few days and coudln't figure anything out. Any help would be greatly appreciated. I am using DAQ USB-6008 to measure these voltages and pulse from the generator and a sensor
    I have attached a jpg (a graph that i just made with excel to explain). The time 't' is what I am trying to measure
    Cheers
    Awais 
    Message Edited by awais.h on 03-30-2010 11:20 PM
    Message Edited by awais.h on 03-30-2010 11:21 PM
    Solved!
    Go to Solution.

    Hi
    Thanks for the code but I'm afraid it won't work. Like you said the probability of choosing a value that is on both graphs may not happen. This is something that I would like the code to do automatically.
    But I did use the previous code posted and made some modifications to it and it seems to work perfectly. Now the next thing is to be able to get just that one value that tells you the first time difference.
    Here is what I get using that code.
    As you can see from the t Values. I only need the one that is highlighted. If there is a way to filter out the rest it would be great.
    I was thinking of a while loop and as soon as the value is higher than 3E-5 it would store the number and stop the loop, but I'm not too familiar with arrays in labview.
    Here is the the code modified.
    As you can see, it wasn't that big of a modification and it still is your code.
    I will keep trying.
    Thanks for the help
    Attachments:
    FinalShockSpeed.vi ‏55 KB

  • Measuring Phase Difference of acquired sound input - How to set the reference

    I am trying to measure the phase difference between two audio inputs.(Left and Right Channel of my sound card)
    Both are free running 1kHz audio samples which come in and out of phase.
    When the samples are in phase everything seems to be working correctly and shows no phase difference.
    However once the signals start to go out of phase +-10deg the result keeps jumping around.
    It appears to be the fact that it is changing the reference to determine the phase.
    When I view the output phase of a channel it is a sawtooth waveform moving from 250deg and then wraps round to -110deg
    What I want is to fix one input at 0 degrees and see the others inputs phase difference against it. 
    Is there a way to set one signal as the reference or an alternative strategy?
    Thanks in advance for any assistance. 
    PLEASE NOTE THAT THE acquire.jpg IS ACTUALLY THE VI.
    It would not upload as the vi. Please rename extension to acquire.vi to view it. 
    Message Edited by EuanB on 05-15-2009 01:54 AM
    Message Edited by EuanB on 05-15-2009 01:55 AM
    Message Edited by EuanB on 05-15-2009 01:57 AM
    Message Edited by EuanB on 05-15-2009 01:57 AM
    Message Edited by EuanB on 05-15-2009 01:59 AM
    Solved!
    Go to Solution.
    Attachments:
    In Phase.jpg ‏835 KB
    Out of Phase.jpg ‏857 KB
    acquire.jpg ‏33 KB

    I did some modifications to my first vi. Now is the amplitude problem removed. At least in then I simulate. You may test in real world:smileytongue:
    Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
    (Sorry no Labview "brag list" so far)
    Attachments:
    demo_v2.vi ‏33 KB

  • How to calculate the phase difference between two square wave (acquired from two channel in one DAQ)

    Hello everyone ,
     I need a quickly help that as below :
    I am trying use PCI-6220 to acquired six signals from one rotation encoder (channel A, channel B,channel Z ,and their non-signals) .The encoder out signals will be square wave and 4000pulses per revolution. I set it rotation at 300rpm speed. I need show every square wave of six out channels in waveform and measure the A-B phase difference to check if the value is correct (designed value should be 90deg) .
    I have no idea how to measure or calculate the phase difference of two square wave base on synchronizate to acquire these two square wave from two channel on the PCI-6620....
    Anyone can give a idea how to calculate the phase difference with two square wave ?
    Thank a lot and Thanks again...
    Tim

    Tim,
    Here is a simple rising edge detector for one channel.
    Lynn
    Attachments:
    Rising edge.vi ‏15 KB

  • Comparison of Phase Difference between Zero Phase and FIR Filtering

    Hi,
    I have a comma-delimited text file containing a 2D array in frequency domain. I would like 2 do a phase difference comparison between the original signal, zero phase filter and FIR filter with a cut-off at 1550nm and sampling of 0.01nm. Ouput will be a graph. I've tried to model after the example in LabVIEW but I can't seem to get the graph to display. Is there an error in the block diagram?
    Also, is it possible to do the phase difference comparison via detection of central wavelength? If so, how can I go about it?
    Thanks.

    When you translate time domain to frequency domain, amplitude information is separated information.
    Therefore, there's no way to find phase information from frequency domain data.
    You must collect time domain data in order to perform this test.

  • How to write a VI to measure the difference between two analog inputs (voltage)

    I'd like to measure the difference voltage between two analog inputs.
    Could someone write me a VI for it, please?
    I'm new with Labview....
    Thanks a lot!!!

    On the numeric palette, there is a function called subtract. As the
    help for it says, it 'Computes the difference of the inputs.'.
     Since
    this is such a simple process, you need to provide some details on why
    you can't do this. You can wire just about any data type into the
    inputs. Post your code if you need further help.
    Message Edited by Dennis Knutson on 04-05-2009 08:23 AM
    Attachments:
    Subtract.PNG ‏1 KB

  • How to measure time difference between two continous encoder pulse (PULSE A & PULSE B)

    im trying to figure out the time difference between two square
    wave pulse (PULSE A and PULSE B) from an encoder. I tried to modify many code but fail to capture thephase difference  for each pulse. the
    pulse only rise to 5V and fall to 0V like normal square wave pulse
    can you and all of experts here help me out with this?
    my problem
    1) Encoder pulse are continous (pulse A and pulse B)
    2) Square wave pulse have "0V" and "5V" please rapidly
    if possible someone show me correct method , Im using LABVIEW 7.1 and Hardware NI SCOPE (PCI 5102)
    your advice are highly appreciated
    among my idea as in attachment , but I failed to get it
    Attachments:
    Need to Get this wave.JPG ‏34 KB

    Hi Amirul,
    Check the attached JPG file. i think this will be use full to you
    Regards,
    Santhosh M

  • Can counter measure pulse width difference between two signals

    I am interested in determining the high pulse width time that two signals have when they are in various phases between eachother.

    Why don't you try one of the pulse width examples. I don't know what ADE you are using, but you can search for examples (http://www.ni.com/devzone/dev_exchange/ex_search.htm) with the key words "+pulse +width" and find several examples in different languages. This will measure the pulse width of one signal, but you can program most of the counters to do multiple tasks at the same time. Just copy the code twice and change the counter number to program counter 2 as well. If you want the ORed pulse width time, I would recommend adding a OR gate to your circuit and then feeding that into a counter.
    I hope this helps.
    Joshua

  • Phase difference

    Hi,
    I'd like to plot phase difference between two signal(input-output), the method which I'm using currently, is taking "FFT" and (r-teta)....and subtracting the phases, but what I obtain isn't so desirable, Do you know anyother option or suggestion to make my results better?
    I've attached the plot and marked them, one of the is "Output FFT- magnitiude vs. Frequency" as you see it's acceptable, but another which is "phase difference vs. freq" isn't so good.
    Thanks
    Petar
    Solved!
    Go to Solution.
    Attachments:
    IMG_0440.JPG ‏140 KB

    Thanks for your replies, I've attached the acquired data..
    (notepad file).1 column: Frequency......2nd column (FRF of output- magnitude)...........3rd column(FRF phase difference(output-input)).
    In the figure: left column: input....FRF magnitude.................right column: output...phase frf....fft of output in every step.
    thanks
    Petar
    Attachments:
    Sweep-read-copy - Copy.vi ‏169 KB
    March30-Monday.docx ‏19 KB
    New Picture (49).jpg ‏571 KB

  • Labview, Change the phase between 2 signals dynamically

    Hello,
    I'm working on a big VI , and for testing my VI I have some controls.  A part of my VI is to generate 2 sine signals with the same amplitude and frequency and a phase difference between thoses 2 signals.
    My example is quite simple but very similar the one I use :
    - I can change frequency and amplitude while the VI is running.
    - I can't change the phase.
    Anyone have an idea ?
    thank in advance
    Solved!
    Go to Solution.
    Attachments:
    Generator.vi ‏77 KB

    Hi Danl_B,
    My VI run, but I haven't a sine at my output. if I use a graph chart I can see a sine (not really good in résolution, it's more like a triangle) .
    And if I set this signal for my DAQ analog Output and after that Acquiring with an other DAQ, it doesn't show me a sine but a square with strange change of amplitude.
    I hope you can understand what I mean, my english is poor..
    Max

  • Frequency response and phase difference

    Hi,
     I generate "Sine-Swept" with a function generator, which is the input of my device.
    Then, I measure the output(vibration) via a photodiod (which is as voltage).
    Now, I want to obtain FRF and Phase difference between these two wave (output and input).
    In most of the examples, the input and swept has been generated by the software itself, but if the input has been acquired externally and also the swept has been done via a function generator, how would be the FRF?
    I have installed "Sound and vibration toolkit", Could you please give me a heads up, that how can I do that?
    In advance, I really appreciate your help,
    Petar

    Hi,
    I attached the project which I've recorded the data from DUTs. Also, I attached 2 snap-shots of the project, in case of the project file couldn't be launched.
    I have connected the signal from a function generator to "ACH0" channel, and performed the swept-Freq in the output signal of function generator. (Red graph in 1st chart). Please note that the swept sine wave is generated via the function generator itself...NOT VI
    The generated signal by the function generator is the input, which derives the oscillation of a drop,
    A photodiode measures the oscillation of the drop via laser-scattering by drop vibration. SO....the signal generated by the photodiode is the "Response"....(white wave in 1st chart)(connected to "Ach1" channel.
    Now, I want to obtain FRF, which the input is the signal generated by the function generator, and Response is the output of the photodiod'
    As it's seen in the files...the FRF and phase difference is n't what is expected, also the coherence between in and output is zero!
    Please help me out with this problem...
    Thanks
    Petar
    Attachments:
    12.seproj ‏419 KB
    1.JPG ‏183 KB
    2.JPG ‏177 KB

  • Phase difference measuremen​t

    I need assistance measuring the phase difference between two digital signals (0 to 5 volts). The signals are angle outputs of a rotating torque sensor. All of this is for the purpose of tracking the angle of rotation as I measure torque. Normally, I would run first angle to a counter and the second angle through an up/down gate on the DAQ board, however my board has no such up/down gate. The two signals are supposed to be 90 degrees out of phase depending on the direction of rotation. As such, Labview should then differentiate when to count up or count down the degrees of rotation. If I had a way of mathematically determining the phase of the signals, I could write a Labview vi to change the counting from one way to the other. I have already spent hours researching phase difference methods on the forums, however I am using Labview 8 base package, and therefore do not have access to advanced functions such as Hilbert Transforms or AC/DC Estimators. Any ideas? There has to be a way to use trig identities or something and solve out phase difference.
    Matthew

    Search for "quadrature encoder" on ni.com. Here is an extract from this link.
    Quadrature Encoders
    The most common type of incremental encoder uses two output channels (A and B) to sense position. Using two code tracks with sectors positioned 90° out of phase, the two output channels of the quadrature encoder indicate both position and direction of rotation. If A leads B, for example, the disk is rotating in a clockwise direction. If B leads A, then the disk is rotating in a counter-clockwise direction. Therefore, by monitoring both the number of pulses and the relative phase of signals A and B, you can track both the position and direction of rotation.
    In addition, some quadrature detectors include a third output channel, called a zero or reference signal, which supplies a single pulse per revolution. This single pulse can be used for precise determination of a reference position.

Maybe you are looking for