LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

sine wave question (not really a LabVIEW question)

Now I've never given this any thought before but a colleague asked me this today.

 

So when we calculate single cycle of a sine wave on a graph, it always is missing the last data point.  This seemed okay to me because the first data point of the next cycle will start where the last data point would be, effectively completing the sine wave from the last cycle when it begins the sine wave for the next cycle.

 

But first of all, is this true?  If I then introduce a new waveform that starts at a different value than what should have been the last data point of the last cycle, it jumps from the last data point of the sine wave (remember it is missing the last data point to complete the sine wave) to the start of the new waveform. Is this right?  Instinct tells me that the graph can't display the last data point properly, but the timing is still correct because the second waveform is still starting on time.  To artificially add a data point to complete the sine wave and then start the next waveform seems like we are going to start the next waveform one sample too late.

 

I've always assumed this was right, but is it really?  He made me doubt what I have always assumed to be true.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 1 of 11
(1,147 Views)

The first question is of course how you are calculating a single cycle? 0 degrees and 360 degrees are the same thing.

 

If you would have a last datapoint at 360 and concatenate several cycles, you would have duplicate values at the joint, right?

Message 2 of 11
(1,143 Views)

@altenbach wrote:

The first question is of course how you are calculating a single cycle? 0 degrees and 360 degrees are the same thing.

 

If you would have a last datapoint at 360 and concatenate several cycles, you would have duplicate values at the joint, right?


That's what I think, because the next data point has to belong to the new waveform.  It can't be both.  (The fact that it generates true sine wave cycles when several cycles are concatenated is enough proof, I think.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 11
(1,138 Views)

Yeah, you've got it right, at least in principle.  But I can imagine cases of finite acquisition where one might want to append one extra point to establish a zero value after the task finishes.

 

(Also, keep in mind that the thought experiment is focused on a very special case where the sample rate is an exact integer multiple of the waveform frequency.  In the more typical case, the first sample of the next cycle wouldn't happen to land right on the 0 deg phase point to cause the apparent ambiguity.  If it landed at 2 deg phase for example, it'd seem a lot more obvious which cycle it belonged to.)

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 4 of 11
(1,072 Views)

Forget the Sine part.

If you want to plot all phases from 0 to 360 in 2 degree steps that gives 180 steps, not 181.

 

As others have said, 0 and 360 are equivalent, so if you include an extra point, you've got a duplicate

 

The function of Sine or Cosine or Tangent is irrelevant in this regard.

0 Kudos
Message 5 of 11
(1,058 Views)

Hi, Everyone:

 

Thanks for the discussion.  I was fairly certain I was correct, but when someone asks me a question like this, I have to explore the possibility that I was wrong.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 11
(1,051 Views)

Of course, you have to account for precision.  That means for any point on the function you need theta0 and delta theta (a function of sample rate and frequency. )  That's probably what bit your friend.

 

Let's take a look at few other cyclical measurements that you might find useful.  A day is 24 hours long.  That means approximately 86400 seconds from now it will be the same time tomorrow. Or, 86399.999999999999999999 seconds is just before this time tomorrow [+/-1^e-18Sec is how fine we can measure time]

 

Then add in that 360 degrees is a simplification.  Seriously!  What is the point of spinning Rho = NaN around Origin! It's not even a "point" and the origin simply "poofs" from the frame of reference. 

 

SO, WE ARE REALLY DEALING WITH 2*PI!  (can you give us an exact value for that? If you want to establish a mathematical relationship between an integer and pi, you are going to need other strange values like i and e)  And calculating some measure of a triangle whose hypotinuse is Rho for that rotation value of the cyclical function. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 7 of 11
(1,040 Views)

Interesting question that made me think.

 

Another way to look at it is to think in terms of Fourier Transforms.

 

Digital Fast Fourier Transforms (DFT) assume that the signal that is transformed is infinitely repeated. If you repeat your sine infinitely, does it produce an exact infinite sine wave? If you add the full 0-360 deg points, your sine wave will be completely off-phase after several cycles. The DFT would then be slightly different than a single peak (if there is enough resolution, or cycles).

 

This is partly the reason why windowing before DFT is important.

Marc Dubois
0 Kudos
Message 8 of 11
(1,031 Views)

@billko wrote:

So when we calculate single cycle of a sine wave on a graph, it always is missing the last data point.


Obviously, you are doing it wrong 😄

 

If you really want a "full cycle" (whatever that means, e.g. a full rotation in the complex plane), just do 361 points at 1 degree increments. Only if you do an infinite number of points per cycle, the last point is irrelevant. Else we are dealing with the typical off-by-one-error.

 

Curiously, some of the signal generating tools (look at the ramp pattern) do have an option to "exclude end?", probably to allow both possibilities. Yes, I've used both, depending on what I needed. 😄

0 Kudos
Message 9 of 11
(1,021 Views)

This is something of a "what's your definition of one cycle" problem. If the two sine waves are, say, tones emitted from a speaker, then that last sample point is whatever you WANT it to be- it represents what you'd like the speaker to do.

 

And I think Kevin's explanation is the most correct so far. To hopefully repeat what he said, if you think about a discretization of a sine wave, it's only a little complicated when you have an exact integer number of samples AND it starts at exactly the start of the waveform. Draw a continuous sine wave on a sheet of paper, then divide it into an even number of segments, NOT starting at precisely t=0. Those samples define that waveform just as well as the set of samples that DOES start at zero, and you can't have both ends included in that set.

 

Yet another way to think about it would be to compare the period of the sine wave to the period of the sampling frequency. If you have a 1 Hz sine (period = 1 second) and a 10 Hz discretization (period = 0.1 second), then you know that exactly 10 discretized points fit in the sine wave. It doesn't matter how you align those samples- you could align it with the first sample of the discretization matching the sine wave, or you could align it with the last sample, or anywhere in between. They're all valid representations, which leads me back to my first point- it is what you decide it to be. Remember that, in discretization land, a single sample represents not just one point in time but a whole window of time (the period of the sampling). Either you can define this such that the actual sample point is in the "middle" of this period, the "start" of the period, or the "end" of the period, and all are equally valid depending on context.

 

Thus, in the case where you align your sample period such that the first point is truly at t=0, then you're not stopping early, because the sample point at the end of your wave extends infinitely close to, but never touching, the first point of the next wave (which is what I'm pretty sure is what Jay was saying).

0 Kudos
Message 10 of 11
(1,011 Views)