From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract the fundamental from a single cycle of a square wave?

Hi, I want to extract the fundamental waveform from a single cycle of a square waveform. But using square waveform VI I am not getting the correct fundamental waveform. 

Screenshot_9.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I thought maybe because since the waveform is not completing a full cycle at t=10 by jumping back to 1. So I had increased the no. of samples by 1 to make the waveform complete, but I am still not getting correct results.

 

1 Square Wave cycle with an additional Sample1 Square Wave cycle with an additional Sample

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Please help with this problem.

Square Wave.png

0 Kudos
Message 1 of 8
(3,734 Views)

What do you expect the answer to be?

 

I think you are confused about what a frequency of square wave is and what a fundamental frequency is.  A square wave does not consist of one frequency.  It is a sum of multiple frequencies that goes on infinitely.  Do an FFT on your square wave and you'll see what I mean.  You are using single tone extraction which is returning the strongest frequency of all of those individual sine waves.

 

If you want the frequency of a square wave, you need to take the period of the square wave signal and then the inverse of that.

0 Kudos
Message 2 of 8
(3,720 Views)

You are correct that the single tone extraction fails in this edge case and gives you the first harmonic instead. This is most likely due to limitations of the algorithm, after all, it applies a window function before doing the FFT. (The extract single tone is a VI, so you can see how it does it :D). It does work correctly of you have two or more periods.

0 Kudos
Message 3 of 8
(3,708 Views)

To paraphrase RavensFan's (correct) response to your question. using some wisdom I learned as a Freshman in College, "Answer Analysis reveals that the Question is Wrong".

 

You have a single cycle of a Square Wave (which one assumes will continue squarely-oscillating "forever").  If you have any kind of signal and repeat it cyclically at a certain frequency, you should expect that the dominant frequency of the spectrum should be ... the repetition frequency = the reciprocal of the signal's Period (here 10 seconds, for a frequency of 0.1 Hz).

 

Your "Extract Single Tone Information" function (whose behavior I haven't studied, don't know its algorithm, so can't comment on whether it is just flat-out wrong, which I hope is not the case, or whether you are mis-using it somehow) is returning an estimate of the "Single Tone" that is twice the fundamental.  If you know anything about signal theory, you'll know that a Square Wave consists of odd multiples of the Fundamental, with all the even harmonics being 0, so if there were a "second harmonic", it would have a magnitude of 0, hence would not be the "Single Tone" present in the signal.

 

Have you tried running this algorithm where the input signal is not a single cycle, but (say) 10-100 cycles of something, even a square wave?  Do you still get the same (obviously-wrong) result?  [I could do the experiment myself, but I'm not really interested in the answer to this question -- I am, however, interested in your learning something about Signals, LabVIEW, and learning how to "explore on your own" to figure things out, which is what Engineers are supposed to do ....].

 

Bob Schor

0 Kudos
Message 4 of 8
(3,700 Views)

I have noticed the following things after analyzing the working of extract tone VI:

  • It is working perfectly when the number of cycles of the input waveform is an integer. Error in both amplitude and frequency are zero.
  • When the number of cycles of the input waveform is not an integer, the error becomes nearly zero after 2 or more cycles. The following graph shows the percentage error graph of amplitude and frequency.
  • Screenshot_12.png
  • Screenshot_11.png
    • Square Wave2.png

I think the extract tone VI need at least 2 cycles of the waveform to calculate the correct values. But in my program, I need to calculate the fundamental only with a single cycle of the square waveform. Is it possible?

0 Kudos
Message 5 of 8
(3,682 Views)

Try using the pulse measurements VI. You should be able to detect your pulse time and therefore be able to detect the frequency.

0 Kudos
Message 6 of 8
(3,679 Views)

If you know it is a exactly a single cycle, there is nothing more to measure. The answer is already there, given the time axis.

 

AsI said, "extract single tone" applies a window function because it cannot assume that you have an integer number of cycles. You use of it is not as intended.

 

Can you give some background on the purpose of all this?

0 Kudos
Message 7 of 8
(3,671 Views)

Yes with the only single cycle I can calculate the fundamental frequency which is obviously the signal frequency itself and there is no need of 'extract tone VI'. But here I want to measure amplitude as well.

 

My application is related to MMF waveform of a distributed winding of an electrical machine.

When the number of poles in the machine is two, I need to generate a single cycle of the square wave.

When many such square waves are displaced from one other with some angle then the resultant waveform resembles a sinusoidal wave with very fewer harmonics. For making a reference sinusoidal wave, I need to extract the fundamental from the resultant and then plot it.

Screenshot_14.png

0 Kudos
Message 8 of 8
(3,651 Views)