# EEVblog Electronics Community Forum

## Electronics => Beginners => Topic started by: ez24 on May 20, 2015, 12:36:37 am

Title: When does a square wave become a sine wave?
Post by: ez24 on May 20, 2015, 12:36:37 am
Hi

I have a Wavetek 145 and it puts out a nice square wave at 2 MHZ and a nice sine wave at 20 MHZ (but suppose to be square).

As I go up in freq from 2 to 20 I can see the square get worse and the sine get better.  So I was wondering what is the definition of a square wave.  ie at what freq can I say the wave is a sine wave

thanks
Title: Re: When does a square wave become a sine wave?
Post by: rs20 on May 20, 2015, 12:42:47 am
Square waves and sine waves are both ideal mathematical constructs. There's no established definition of how good a real life sine wave has to be to be called a sine wave, similar for square waves. Instead you specify the imperfections/differences from the ideal. For square waves, rise and fall time, ringing/settling time, etc. For sine waves, THD (total harmonic distortion), THD+N and so on.
Title: Re: When does a square wave become a sine wave?
Post by: Asmyldof on May 20, 2015, 12:53:18 am
Ah, I remember also answering a question like this one on Electronics Stack a while back.

In stead of looking it up and linking it, I shall just type a new answer, in the hope my sleep deprived brain will say it right and understandably.

The square wave is a sneaky one. Actually any wave that isn't a Sine Wave is sneaky, but they are all sneaky in different orders.

In spectrum speak a squarewave of 2MHz is basically applying a figure of speech, where you actually mean to say "A square wave with a dominant frequency of 2MHz" or "A square wave with a base frequency of 2MHz".
((EDIT: added "in spectrum speak", since a signal that repeats once every 0.5us of any shape is in general engineering speak correctly specified as being 2MHz))

You see, that nice sharp flank that is the edge of the square wave is, on paper, in fact "infinite frequency" (of course, that doesn't exist in the real world and as such nor does the true square wave, they're always a tiny bit not-square).
The funny thing is, that sharp flank implies a set of higher frequencies that we call overtones. Such that when you measure the frequency spectrum of a square wave, you can see 2MHz, but also many frequencies that are a multiple of that frequency, but less powerful.

Because I am not yet aware of nice drawing or simulating tools linked into here, I will link to the wikipedia animation here:
http://en.wikipedia.org/wiki/File:SquareWave.gif (http://en.wikipedia.org/wiki/File:SquareWave.gif)
Copied from: http://en.wikipedia.org/wiki/Square_wave (http://en.wikipedia.org/wiki/Square_wave)

The first frequency is the base frequency, 2MHz, the next frequency is the next odd overtone: 3 times as much, but 3 times as weak, so 6MHz at 1/3 the power. Then the next one is the next odd overtone, so 5 times as high, but 5 times as weak, so 10MHz at 1/5 the power, the next is the 7th, 9th, etc, etc, until some part of the circuitry can't process the overtones anymore and they start cutting out.

From your experiment, the generator apparently has a part of its circuitry cut off somewhere between 20MHz and its 3rd tone, 60Mhz, which is quite normal for analogue generators set at their maximum frequency. So you are only getting the base frequency with maybe some distortion and shift caused by the overtones in stages that actually can handle them, which is just the one sine wave.

EDIT2: See, I said it sort of wrong, I said Overtone, where more correctly it should be Harmonic. Insomnia, it's not fun.
Title: Re: When does a square wave become a sine wave?
Post by: Christe4nM on May 20, 2015, 01:06:42 am
To understand what happens you need to know that a square wave can be seen as constructed from many sine/consine waves. Each sine has a frequency that is a multiple of the fundamental frequency, i.e. an harmonic. In addition each sine has a certain amplitude. This idea is known as a Fourier series. And a Fourier transform is an algorithm that derives all those frequencies and amplitudes form a certain signal.

So a 2Mhz squareware can be seen as a 2Mhz sine + a 4Mhz sine + a 6MHz sine and so on to very high frequencies.

However, your signal generator and also your oscilloscoop have a limited bandwidth. Suppose your generator's bandwidth is 20Mhz. If you set it to generate a 10Mhz squarewave you are in for a surprise. Only the second harmonic at 20Mhz gets through, an maybe some signal at 30Mhz, but greatly reduced in amplitide. Those signals together are not near enough to form that square wave. So you get something that's more like a sine wave.

Now just to be clear, a signal generator is not using a lot of sines to create that squarewave. It's just a way to understand what is going on.
You could also view it as follows: the circuit that drives the output is not able to change te voltage fast enough to get a nice sharp edge on the square. Up to the point that the waveform is so fast changing with respect to what the circuit can handle that is falls hopelessly behind and there is no squarewave left.

edit: Asmyldof posted just while I was typing. He says the same.

edit 2: I know that a square wave actually only consists of odd harmonics, I used the even ones too to make the point.
Title: Re: When does a square wave become a sine wave?
Post by: w2aew on May 20, 2015, 01:11:59 am
As stated above, a square wave consists of energy at the fundamental frequency, and its odd harmonics.  The more harmonics, the faster the rising and falling edges.  If the signal generator output stage doesn't have enough BW to produce the higher harmonics, the square wave becomes more sinusoidal.  Maybe this video of mine will help:

Title: Re: When does a square wave become a sine wave?
Post by: hamster_nz on May 20, 2015, 01:30:10 am
What I find to be an interesting point to ponder on frequency domain vs time domain.

You can have a wave that has the same harmonic content as a square wave, sounds like a square wave (to the ear) but looks nothing like a square wave on your scope.

But you cannot have a wave that has the same harmonic content as a sine wave, that doesn't look like exactly like a sine wave (possibly with a bit of phase shift)

The spectrum doesn't uniquely identify the waveform, except for a sine wave.
Title: Re: When does a square wave become a sine wave?
Post by: rs20 on May 20, 2015, 02:01:29 am
(possibly with a bit of phase shift)
But therein lies the point: when there's only one fundamental frequency, you can phase shift that one frequency and you're "just moving it sideways". But when you phase shift a harmonic, the sine waves add up in a different way and it ends up "looking different", even though that one harmonic was just moved sideways just like before. So your point boils down to "the way of representing waves as sums of sine waves finds that a sine wave is just the sum of a single sine wave" -- mm, not so surprising perhaps.

Also, the transform (Fourier, of course) the transforms frequency to time is exactly the same as the transform from time to frequency (perhaps modulo a constant). The only apparent differences arrive from the material we often deal with: purely real time domain content, and frequency domain content that is therefore complex yet symmetrical about the vertical axis.
Title: Re: When does a square wave become a sine wave?
Post by: Asmyldof on May 20, 2015, 02:08:24 am
:blah: :blah: :blah:

I fundamentally disagree with you!

(Good) apples are obviously more tasty than oranges!

Now, you can go ahead and change your signature and make me look like a ranting lunatic. I'm that most days anyway, so all fair.
Title: Re: When does a square wave become a sine wave?
Post by: Skimask on May 20, 2015, 02:27:43 am
I don't have a proper method of measuring sine wave distortion, no test equipment capable of it, no nothing.

BUT...what I do have is a couple pieces of transparent plastic with a picture of a sine wave printed on it.
If I've got any doubts as to whether or not a sine wave is good or not, I lay the transparency on top of the screen of the 'scope, and adjust the time base and volts/div to match.
If it matches up, the sine wave being displayed is good, or at least good enough for me.
If not, there's too much distortion.
(Of course this method isn't going to win any awards for accuracy or producing any results of any significance, but it works for me and that's good enough)

In this case though, I have to wonder if the O/P actually means WHY does his output change from square to sine wave while increasing in frequency (eg. why are the edges rounding off)...
Title: Re: When does a square wave become a sine wave?
Post by: rs20 on May 20, 2015, 02:58:09 am
(Good) apples are obviously more tasty than oranges!

Now, you can go ahead and change your signature and make me look like a ranting lunatic. I'm that most days anyway, so all fair.

And here I was thinking your signature was a Vanilla Ice reference.
Title: Re: When does a square wave become a sine wave?
Post by: ez24 on May 20, 2015, 03:07:25 am
I have included 3 pics , the Wavetek is set for a square wave for all 3 pics, no changes made to the Wavetek other than changes to the freq.

At 2 MHz it looks like a square (to me) , at 10 MHz ?, and at 20 MHz it looks to me to be a sine wave (I assume the Wavetek is bad and will post a help post in the repair section)

So what is the 10 MHz wave - square or sine ??

thanks

Title: Re: When does a square wave become a sine wave?
Post by: rs20 on May 20, 2015, 03:12:14 am
So what is the 10 MHz wave - square or sine ??

Neither? Again, you're obsessed with this false dichotomy between square or sine, or the false idea that there's some well-defined definition delineating the two.

If you showed me that wave and just asked me to describe it, I'd say it's a lazy, rounded off cross between a square and a sawtooth wave.

EDIT: I notice that there's pretty significant overshoot in your 2 MHz square wave -- have you compensated your oscilloscope probes properly (hook up to test source on oscilloscope, twiddle screw in probe until overshoot is gone)? That might make your 10MHz wave look a lot better.
Title: Re: When does a square wave become a sine wave?
Post by: Fsck on May 20, 2015, 03:15:00 am
So what is the 10 MHz wave - square or sine ??

Neither? Again, you're obsessed with this false dichotomy between square or sine, or the false idea that there's some well-defined definition delineating the two.

If you showed me that wave and just asked me to describe it, I'd say it's a lazy, rounded off cross between a square and a sawtooth wave.

I'd go with neither as well.
Title: Re: When does a square wave become a sine wave?
Post by: ez24 on May 20, 2015, 03:18:24 am
ah I have to go and check the sawtooth  :)
but good to know that it is neither one (I would not have guessed this)
thanks
Title: Re: When does a square wave become a sine wave?
Post by: amyk on May 20, 2015, 04:21:14 am
Neither and both.

You can think of it as a sine with extra added harmonics, or a square wave that's been rounded off because its higher harmonics have been attenuated.
Title: Re: When does a square wave become a sine wave?
Post by: SL4P on May 20, 2015, 04:24:22 am
... and I thought this thread was going to head off into complex maths about dissipation of energy, capacitance, inductance, reactance, etc.
Title: Re: When does a square wave become a sine wave?
Post by: Paul Moir on May 20, 2015, 04:51:50 am
Have you hacked that 1054z for more bandwidth?
Are you using a probe in 1x mode?
Do you have the 'scope's bandwidth limiter on?

Title: Re: When does a square wave become a sine wave?
Post by: Skimask on May 20, 2015, 04:57:20 am
Is it terminated?

Probably not.
Title: Re: When does a square wave become a sine wave?
Post by: vaualbus on May 20, 2015, 05:16:05 am
Is it terminated?

Probably not.

Is it 50ohm probably not
Title: Re: When does a square wave become a sine wave?
Post by: miguelvp on May 20, 2015, 05:22:30 am
Is it terminated?

Probably not.

Is it 50ohm probably not

Seems to me the FG (wavetek 145) is 50 ohms:

Title: Re: When does a square wave become a sine wave?
Post by: rs20 on May 20, 2015, 06:45:12 am
And, is the probe compensated properly? Doesn't look it, judging from the 2 MHz wave.
Title: Re: When does a square wave become a sine wave?
Post by: miguelvp on May 20, 2015, 06:48:23 am
And, is the probe compensated properly? Doesn't look it, judging from the 2 MHz wave.

I think he used the scope's probe with the ground clip instead of using a spring ground and proper termination.
Title: Re: When does a square wave become a sine wave?
Post by: Zero999 on May 20, 2015, 01:28:47 pm
Have you hacked that 1054z for more bandwidth?
Are you using a probe in 1x mode?
Do you have the 'scope's bandwidth limiter on?
I agree. It's quite likely the oscilloscope or probe are filtering out the harmonics.
Title: Re: When does a square wave become a sine wave?
Post by: ez24 on May 21, 2015, 01:34:52 am
Have you hacked that 1054z for more bandwidth?  -->  No

Are you using a probe in 1x mode?  -->  Yes

Do you have the 'scope's bandwidth limiter on?  --> No

I ordered some 50 ohm gadgets and will test again when I get them

thanks
Title: Re: When does a square wave become a sine wave?
Post by: rs20 on May 21, 2015, 01:57:56 am
Are you using a probe in 1x mode?  -->  Yes

Woah, woah, woah... :

TLDR; Use your probe in 10x mode (unless you absolutely need extremely low vertical noise and and can tolerate very low bandwidth).
Title: Re: When does a square wave become a sine wave?
Post by: miguelvp on May 21, 2015, 02:16:27 am
Or use a coax cable with proper termination on the scope end, don't use the probes to measure the signal generator.
Title: Re: When does a square wave become a sine wave?
Post by: Paul Moir on May 21, 2015, 07:13:41 am
Also note that with an unhacked scope with 50MHz bandwidth, you'll not be able to see enough harmonics on the 20MHz square wave for it to look particularly square.  1st is 20MHz, 3rd is 60, 5th is 100MHz, etc.  So you'll only see the first, some of the 3rd and maybe a hint of the 5th.

But yeah I'll bet 1x probing is the biggest problem here.  1x sucks...
Title: Re: When does a square wave become a sine wave?
Post by: grumpydoc on May 21, 2015, 02:28:22 pm
Also note that with an unhacked scope with 50MHz bandwidth, you'll not be able to see enough harmonics on the 20MHz square wave for it to look particularly square.  1st is 20MHz, 3rd is 60, 5th is 100MHz, etc.  So you'll only see the first, some of the 3rd and maybe a hint of the 5th.

But yeah I'll bet 1x probing is the biggest problem here.  1x sucks...

Indeed.

There are two discussion threads on this.

As well as the measurement issues there is also the fact that the the Wavetek 145 has a rise time of ~20ns so it probably can't manage a very "square" 20MHz square wave
Title: Re: When does a square wave become a sine wave?
Post by: hamster_nz on May 21, 2015, 06:37:49 pm
I did some playing around last night with my 100 MHz scope, 150 MHz probes, along with 4 MHz, 20 MHz and 40 MHz square waves. And as expected at 40 MHz they didn't look like a square wave at all. But one big difference from the OP's screen-grabs was that it looked nothing like a pure sine.

So I guess that the making a 100 MHz scope hardware into a 50 MHz scope is achieved through a brick wall 50MHz DSP filter, hence the OP's 'pure' looking sine? If that is the case, then that is a reasonable explanation for his traces...

This could be verified by watching the waveform as the frequency is swept. Between 15 MHz and 18 MHz the waveform should change dramatically as the 3rd harmonic gets nuked by the filter, and between 9.5 MHz and 10.5 Mhz when the 5th harmonic gets cut.

Between 10.5MHz and 15MHz the waveform should stay pretty much the same shape.