# Talk:Square wave

## What does

~What does f in

${\displaystyle x_{\mathrm {square} }(t)={\frac {4}{\pi }}\sum _{k=1}^{\infty }{\sin {\left((2k-1)2\pi ft\right)} \over (2k-1)}}$

stand for? It's just a typo, isn't it? Ocolon 17:37, 21 February 2007 (UTC)

I deleted the f after having a look at mathworld.wolfram.com —The preceding unsigned comment was added by Ocolon (talkcontribs) 08:02, 23 February 2007 (UTC).
Oops. f is the frequency here, isn't it? I undid my edit. Ocolon 08:05, 23 February 2007 (UTC)

Seems like there is still a factor of 2 missing in arguments on the main page - should be 2\pi f everywhere, not \pi f (but this discussion page has it right!) e.g. sin(2\pi ft) + 1/3 sin(3(2\pi ft))... would look prettier with \omegas Bdb112 (talk) 21:13, 27 July 2011 (UTC)

Hello, I'm wondering, Where did the animations showing the 25th harmonic of the square wave come from?

From the article:

An ideal square wave requires that the signal changes from the maximum to the minimum state instantaneously and cleanly, without any delay. Clearly, this is almost impossible to achieve. In practicle, actual square waves are only approximations, and have ringing artefacts in the transition. This is further clear from the Fourier series: note that this implies that a square wave contains infinitely many harmonic components. In practice, this cannot occur as this would require infinite energy.

Which is it? Almost impossible, or impossible? This paragraph is confused, and a clearer treatment is needed, if we are to state that square waves are unphysical. In particular, a simple square wave does not have infinite energy: it has the same energy as a DC signal of the same amplitude. What is infeasible is the infinite bandwidth. -- The Anome 08:51, 23 Sep 2003 (UTC)

Impossible, now you mention it; sorry my brain's been trying to get back into gear again :) Dysprosia

I added some other definitions. Someone should check that:

1. They are valid
2. They all equal the same waveform (ignoring the discontinutieis), with no scalings or time shifting or phase shifting or DC offsets, etc.

I guess these are technically "rectangular pulse trains"... - Omegatron July 2, 2005 02:53 (UTC)

## what's the use of a square wave?

what's the use of square wave?

Can you be more specific? - Omegatron 15:02, July 21, 2005 (UTC)
Hmmm, it's like asking, what is the use of green, or of freezing... A square wave is just a change of state between two levels that occurs almost instantaneously, it doesn't have a use, because it's just a description of something else. However, a square wave that occurs in a physical medium, such as a change of voltage in an electronic circuit, that has millions of uses. For example, the master oscillator inside the computer you are reading this with now generates a square wave, and that is used to clock all the circuitry in the computer in lock step, so things happen in a regular progression. Square waves are ubiquitous in all forms of electronics, but especially digital circuits, because it is like a binary stream 1,0,1,0,1,0,1,0... and that is very useful for measuring time, which turns out to be universally necessary. Graham 03:59, 22 July 2005 (UTC)

If the question was, "What is the use of square waves?," they can be used in beacon-type signals employed in radar and time domain reflectometry. In radar the pulses of known waveform are radiated and the characteristics of their reflections off target objects give much physical information of the objects. Used in TDR, the square wave is sent down one end of a transmission line or conductor(s). The observed, resultant waveforms will include reflections and divulge many details of the line and its termination. This may include the physical characteristics of the line and termination -- faults, anomalies, discontinuities, etc.

DonL (talk) 09:00, 23 April 2012 (UTC)

Square wave closeup

I made an image. I was just experimenting, trying some things based off of Image:Haar wavelet.png. Considering that a square wave can have any frequency, DC offset, amplitude, phase, and discontinuity value and still be considered a square wave, I don't know how useful it actually is, since it sort of implies that those things are fixed. - Omegatron 19:58, July 22, 2005 (UTC)

I could make a more generalized one very easily. - Omegatron 20:00, July 22, 2005 (UTC)

## square vs sine

"However, circuits using sine waves tend to consume more power, so square waves are used wherever possible."

Why? - Omegatron 20:24, July 22, 2005 (UTC)

My reasoning is that square wave clocks are generated by CMOS devices that are either fully on or fully off, so there is little power dissipation in the output transistors. Sine waves have to be generated and buffered by linear devices, which use more power. It's like the difference between Class A (linear) and Class D (PWM) audio amplifiers. I'm sure you know what I mean. However, I just looked at the specs of some square and sine wave clock oscillators, and to my surprise the sines were no more power-hungry than the squares. Perhaps my intuition was wrong. I'll have to look further into this. --Heron 21:44, 22 July 2005 (UTC)

Ah. Well my initial intuition was that a square wave carries more energy than a sine wave of the same amplitude. I'm sure it's more involved than either of us are thinking at first glance. I hear that computer clocks are at such high frequency they can't get anywhere near a square wave anyway, with all the parasitics and so on. - Omegatron 21:59, July 22, 2005 (UTC)

It looks as if there is no clear winner in the power stakes, so I removed the relevant sentence from the article. I was trying to explain why most circuits use square clocks and not sinusoidal ones, but I picked the wrong reason. The true reason is probably complexity: a square wave oscillator can be made of just a CMOS inverter and a crystal [1], and a clock buffer can be just a non-inverting logic gate; while sine wave clock oscillators are specialised devices, and I can't find any references to monolithic sine wave clock buffers. --Heron 12:08, 23 July 2005 (UTC)

Yeah, that's probably all it is. And the sinishness just comes about because of filtering from transmission line effects or whatever. - Omegatron 13:44, July 23, 2005 (UTC)

Oh no, I didn't mean that sine wave clocks are accidental. Some devices, like the ADCs I mentioned, explicitly support differential sine wave clocks, and you can buy sine wave clock generators to drive them. They are available from all good oscillator suppliers (like this one) and come in leaded and SMT packages that look like square-wave crystal oscillators. My point is that this is all too expensive for the average digital circuit, so designers stick to square waves where possible.

I notice we have an article on clock signals, so I'll put some information there once I get it sorted out in my mind. --Heron 14:07, 23 July 2005 (UTC)

Sine waves don't in general consume more power than square, but they can sometimes, depending on how they're generated. If you have a constant 5 Volt DC source, and want to output a 5 V square wave, you just put a switch that will be either off or on at any given time. The power consumed by a component is the product of the current passing through it and the voltage drop across it. The power consumed by the switch is ideally zero, because either it is on (no voltage across), or off (no current through), so the DC supply can be efficiently converted into a square wave with no waste. On the other hand, you can create a sine wave by putting a variable resistor in front of the DC source and turning the knob back and forth. However, this will waste a lot of power, because there will be current flowing through the resistor at the same time as there is a voltage drop across it. Many digital-to-analog conversion schemes work this way (with a computer adjusting a variable resistor to create an analog output), and so it isn't very power-efficient. But a sine wave can be efficiently created essentially by taking a square wave and filtering out high-frequency components. Ideal inductors and capacitors consume no power on average, and so a square wave passed through an LC filter will efficiently make a sine wave.

The catch is, if you want to create a square wave of any frequency, all you have to do is change the switching frequency. But if you wanted to use the efficient approach to a sine wave, you'd have to change the LC filter frequency, which is sometimes hard to do (at least over a wide range). So most of the time, when switching power signals, switching the signal fully on / fully off (as in a square wave, or PWM) will usually be more efficient than switching in an "analog" way (gradually off / gradually on). JB Gnome (talk) 23:58, 23 February 2013 (UTC)

## Video games

I heard this kind of wave was used a lot in old video game systems (Game boys). Should this be mentioned in the article?

Also, I'm looking for a sound editor that allows for easy editing of square waves to make a melody (like was in game boy games). Anybody know where I can find one, and should it be posted under External Links? 71.0.241.224 01:59, 15 March 2007 (UTC)

Audacity is a good free program. Don't know many others. 24.205.34.217 18:58, 21 April 2007 (UTC)

## alternate formula?

how about the x'th root of sin(x) where x is odd? I've fooled around with the trig functions before on my TI 84 and noticed that as x gets higher and higher, the graph looks more and more like a sine wave. VentusIgnis 20:31, 18 June 2007 (UTC)

## Sound example sounds terrible

When I listen to the two sound examples provided, I can't hear that the 3500 Hz tone has higher frequency than the 1000 Hz tone. It sounds the other way, but I know the actual frequencies are correct. Maybe this artifact is because the frequencies are rather high, and because they are compressed with ogg vorbis. (I assume it's vorbis, since the container format is ogg). Lossy compression formats are not optimized for square waves, but for speech and music. It would be better to (1) lower the frequency to, say, 440 Hz and 1320 Hz and (2) use a non-lossy format such as wav. The duration can be lowered, since 5 seconds of high amplitude square wave is quite annoying. HelgeStenstrom (talk) 15:53, 13 March 2010 (UTC)

Without actually trying the experiment, that's quite interesting. I don't think the compression algorithm is likely to screw up to that degree. Did you try a frequency analysis of the sound? I can take a punt at a reason, but I'd rather you did some investigation yourself. Greglocock (talk) 09:53, 14 March 2010 (UTC)
Incidentally, subjectively over my crap laptop speakers I don't agree, but I don't think humans are very good at determining the fundamental frequency of a square wave. Greglocock (talk) 09:59, 14 March 2010 (UTC)
It would be better with sound examples where the fundamental frequency is in the musically usable region, let's say about 200 to 800 Hz. A square wave of 3.5 kHz has only three audible harmonics: 3.5, 10.5 and 17.5 KHz, since only odd harmonics are present, and we cannot hear above 20 kHz. With a fundamental frequency of 400 Hz, many more harmonics would be heard, an the sound would more closely resemble an actual square wave. --HelgeStenstrom (talk) 11:40, 26 April 2010 (UTC)
I performed some analysis on the two tones, and as a result, I deleted the supposed 3500 Hz wave. That "higher frequency" square wave looked a lot more like a broad-spectrum crest wave, with many, many frequency spikes occurring regularly from low to high frequency. A 3500 Hz square wave would only have three primary frequency strengths: 3.5k, 10.5k, and 17.5k. This one was all over the map! The article does not need to have more than one square wave listening example, and the 1000 Hz wave sounds (and measures) good enough for me, even though it is OGG. Binksternet (talk) 15:22, 26 April 2010 (UTC)

## Image Incorrect

I don't really have the ability to fix the image, but hopefully someone who does will read this post. I'm pretty sure that the amplitudes of the frequencies in the frequency spectrum are incorrect. For a square wave with amplitude of 1, The amplitude of the fundamental should be 1.273 ( 4/π to be specific) — Preceding unsigned comment added by GuitarJoe48 (talkcontribs) 03:27, 28 January 2011 (UTC)

An easy fix would be to describe them as relative amplitude in the caption. However, what I'm puzzled by is the horizontal scale. I t seems to label the fundamental as 62 and the highest harmonic as 0.Chrsull (talk) 14:46, 24 May 2011 (UTC)

## Sine vs Cosine

You may want to mention that the Fourier series for a squarewave made with sine waves is as described (essentially 1 + 1/3 + 1/5 + 1/7 + 1/9 + 1/11...), but if the squarewave is made using cosines, the series is (essentially) 1 -1/3 + 1/5 -1/7 +1/9 -1/11..., alternating signs like this. 71.139.165.48 (talk) 06:16, 2 December 2012 (UTC)

## Please fix the following issues

Trying to use this page as a reference, I found the following issues :

1. In the Fourier transform and in the definition based on the sgn function (which should come first by the way), the discontinuities are localized at nT, but in some other defs, they are at nT+1/2.
2. In some defs, it goes from -1 to 1 and in some others it goes from 0 to 1.
3. The Fourier transform animated gif is strongly misleading. It is actually a Discrete Fourier transform, while periodical functions are better described by standard Fourier series. The DFT frequency spectrum has been shifted so that the lower frequencies are the farthest from zero. It has also been renormalized so that the amplitude of the first sine wave is 1 and not 4/π.

I do not have enough time to fix this myself, so if someone reads this, please make the surgery! Mathieu Perrin (talk) 09:24, 26 September 2014 (UTC)

would some one explain 4/π in the equation s(t) = (4/π) [ (sin(2πft) + (1/3) x sin(2π(3f)t)+.......]. Why 4/π does not change by adding more signals in the equation

## Lack of spectrum

Please add spectrum of square wave in frequency domain tooAt Last ... (talk) 10:17, 24 November 2016 (UTC)

Already there. Hyacinth (talk) 00:02, 4 May 2018 (UTC)

## Alternative definition with arctangent

Another definition of a square wave could be:

${\displaystyle y=\lim _{k\rightarrow \infty }{\frac {\tan ^{-1}(k\sin x)}{\tan ^{-1}k}}}$

where ${\displaystyle \tan ^{-1}}$ denotes the arctangent function. As ${\displaystyle k}$ grows larger, ${\displaystyle k\sin x}$ reaches farther out in the domain of ${\displaystyle \tan ^{-1}}$, and thus the transition from ${\displaystyle \tan ^{-1}k}$ to ${\displaystyle -\tan ^{-1}k}$ of the outer arctangent function becomes sharper and sharper (since ${\displaystyle \tan ^{-1}x}$ is bounded by the two horizontal asymptotes ${\displaystyle x=\pm 1}$). Dividing this by ${\displaystyle \tan ^{-1}k}$ normalizes the maximum and minimum values to ±1. Thus, it approximates the discontinuous jump between 1 and -1 in the square wave, and this approximation can be made arbitrarily close to the square wave by letting ${\displaystyle k\rightarrow \infty }$.

Not adding this to the article just yet because this probably falls under WP:OR.—Tetracube (talk) 17:33, 7 July 2017 (UTC)

A similar, faster-converging approximation:
${\displaystyle y=\lim _{k\rightarrow \infty }{\frac {\tanh(k\sin x)}{\tanh k}}}$
This one approaches the square wave exponentially, because of the exponential nature of the hyperbolic tangent.—Tetracube (talk) 17:54, 7 July 2017 (UTC)