Which harmonics are present in a square wave




















The fourth peak is at , not Hz. And if you look closely, the peak that should be at is actually at Hz. The problem is that when you evaluate the signal at discrete points in time, you lose information about what happened between samples. But if you sample a signal at Hz with 10, frames per second, you only have two samples per period.

I plotted the Signals with thin gray lines and the samples using vertical lines, to make it easier to compare the two Waves. The problem should be clear: even though the Signals are different, the Waves are identical! When we sample a Hz signal at 10, frames per second, the result is indistinguishable from a Hz signal.

For the same reason, a Hz signal is indistinguishable from Hz, and a Hz is indistinguishable from Hz. This effect is called aliasing because when the high frequency signal is sampled, it appears to be a low frequency signal.

In this example, the highest frequency we can measure is Hz, which is half the sampling rate. It is sometimes also called the Nyquist frequency. The folding pattern continues if the aliased frequency goes below zero. For example, the 5th harmonic of the Hz triangle wave is at 12, Hz. Folded at Hz, it would appear at Hz, but it gets folded again at 0 Hz, back to Hz.

In fact, you can see a small peak at Hz in Figure 2. The parameter self is a Wave object. The result of rfft , which I call hs , is a NumPy array of complex numbers that represents the amplitude and phase offset of each frequency component in the wave. The result of rfftfreq , which I call fs , is an array that contains frequencies corresponding to the hs. To understand the values in hs , consider these two ways to think about complex numbers:.

Each value in hs corresponds to a frequency component: its magnitude is proportional to the amplitude of the corresponding component; its angle is the phase offset. The Spectrum class provides two read-only properties, amps and angles , which return NumPy arrays representing the magnitudes and angles of the hs. When we plot a Spectrum object, we usually plot amps versus fs. Sometimes it is also useful to plot angles versus fs.

Although it might be tempting to look at the real and imaginary parts of hs , you will almost never need to. I encourage you to think of the DFT as a vector of amplitudes and phase offsets that happen to be encoded in the form of complex numbers. To modify a Spectrum, you can access the hs directly. For example:.

The first line multiples the elements of hs by 2, which doubles the amplitudes of all components. The second line sets to 0 only the elements of hs where the corresponding frequency exceeds some cutoff frequency. But Spectrum also provides methods to perform these operations:. At this point you should have a better idea of how the Signal, Wave, and Spectrum classes work, but I have not explained how the Fast Fourier Transform works.

That will take a few more chapters. Solutions to these exercises are in chap02soln. Write a class called SawtoothSignal that extends Signal and provides evaluate to evaluate a sawtooth signal.

Compute the spectrum of a sawtooth wave. How does the harmonic structure compare to triangle and square waves? Test your function using a square, triangle, or sawtooth wave. Hint: There are two ways you could approach this: you could construct the signal you want by adding up sinusoids, or you could start with a signal that is similar to what you want and modify it.

The version on the right cuts off the fundamental to show the harmonics more clearly. The view on the right is scaled to show the harmonics. The signals are different, but the samples are identical. Exercise 1 If you use Jupyter, load chap Exercise 2 A sawtooth signal has a waveform that ramps up linearly from -1 to 1, then drops to -1 and repeats.

Exercise 3 Make a square signal at Hz and make a wave that samples it at frames per second. If you plot the spectrum, you can see that most of the harmonics are aliased. When you listen to the wave, can you hear the aliased harmonics?

Exercise 4 If you have a spectrum object, spectrum , and print the first few values of spectrum. So spectrum. But what does that mean? Try this experiment: Make a triangle signal with frequency and make a Wave with duration 0. The reason because sinewaves have ideally only one harmonic is because the sine is the "smoothest" periodic signal that you can have, and it's therefore the "best" in term of continuity, derivability and so.

Just an example: why in the water you usually see curved waves? In some cases, like the Hammond organ , sinewaves are actually used to compose the signal, because with decomposition is possible to synthesize a lot of virtually all sounds. There is a beautiful animation by LucasVB explaining the Fourier decomposition of a square wave:. You can decompose any waveform into an infinite series of sine waves added together.

This is called Fourier analysis if the original waveform is repeating or Fourier transform for any waveform. In case of a repeating waveform like a square wave , when you do Fourier analysis you find that all the sines that compose the waveform have frequencies that are an integer multiple of the frequency of the original waveform. These are called "harmonics".

A sine wave will only have one harmonic - the fundamental well, it already is sine, so it is made up of one sine. Square wave will have an infinite series of odd harmonics that is, to make a square wave out of sines you need to add sines of every odd multiple of the fundamental frequency. The harmonics are generated by distorting the sine wave though you can generate them separately.

The derivative - rate of change - of a sinusoid is another sinusoid at the same frequency, but phase-shifted. Real components - wires, antennas, capacitors - can follow the changes of voltage, current, field-strength, etc. The rates of change of the signal, of the rate-of-change of the signal, of the rate-of-change of the rate-of-change of the signal, etc. The harmonics of a square wave exist because the rate of change first derivative of a square wave consists of very high, sudden peaks; infinitely high spikes, in the limit-case of a so-called perfect square wave.

Real physical systems can't follow such high rates, so the signals get distorted. Capacitance and inductance simply limit their ability to respond rapidly, so they ring. Just as a bell can neither be displace nor distorted at the speed with which it is struck, and so stores and releases energy by vibrating at slower rates, so a circuit doesn't respond at the rate with which it is struck by the spikes which are the edges of the square wave.

It too rings or oscillates as the energy is dissipated. One conceptual block may come from the concept of the harmonics being higher in frequency than the fundamental. What we call the frequency of the square wave is the number of transitions it makes per unit time. But go back to those derivatives - the rates of change the signal makes are huge compared to the rates of change in a sinusoid at that same frequency. Here is where we encounter the higher component frequencies: those high rates of change have the attributes of higher frequency sine waves.

The high frequencies are implied by the high rates of change in the square or other non-sinusoid signal. The fast rising edge is not typical of a sinusoid at frequency f , but of a much higher frequency sinusoid. The physical system follows it the best it can but being rate limited, responds much more to the lower frequency components than to the higher ones.

So we slow humans see the larger amplitude, lower frequency responses and call that f! In practical terms, the reason harmonics "appear" is that linear filtering circuits as well as many non-linear filtering circuits which are designed to detect certain frequencies will perceive certain lower-frequency waveforms as being the frequencies they're interested in.

To understand why, imagine a large spring with a very heavy weight which is attached to a handle via fairly loose spring. Pulling on the handle will not directly move the heavy weight very much, but the large spring and weight will have a certain resonant frequency, and if one moves the handle back and forth at that frequency, one can add energy to the large weight and spring, increasing the amplitude of oscillation until it's much larger than could be produced "directly" by pulling on the loose spring.

The most efficient way to transfer energy into the large spring is to pull in a smooth pattern corresponding to a sine wave--the same movement pattern as the large spring. Other movement patterns will work, however.

If one moves the handle in other patterns, some of the energy that gets put into the spring-weight assembly during parts of the cycle will be taken out during others. As a simple example, suppose one simply jams the handle to the extreme ends of travel at a rate corresponding to the resonant frequency equivalent to a square wave. Moving the handle from one end to the other just as the weight reaches end of travel will require a lot more work than would waiting for the weight to move back some first, but if one doesn't move the handle at that moment, the spring on the handle will be fighting the weight's attempt to return to center.

Nonetheless, clearly moving the handle from one extreme position to the other would nonetheless work. Suppose the weight takes one second to swing from left to right and another second to swing back. Now consider what happens if one moves the handle from one extreme of motion to the other has before, but lingers for three seconds on each side instead of one second.

Each time one moves the handle from one extreme to the other, the weight and spring will have essentially the same position and velocity as they had two seconds earlier. Consequently, they will have about as much energy added to them as they would have two seconds before.

On the other hand, the such additions of energy will only be happening a third as often as they would have when the "linger time" was only one second. Now suppose that instead of having the linger time be an odd-numbered multiple, one makes it an even-numbered multiple e. In that scenario, the position of the weight and spring for each left-to-right move will be the same as its position on the next right-to-left move. Consequently, if the handle adds any energy to the spring in the former, such energy will be essentially cancelled out by the latter.

Consequently, the spring won't move. If one moves the handle in a sine-wave pattern, but at a frequency substantially different from the resonant frequency of the system, the energy that one transfers into the system when pushing the "right" way will be pretty well balanced by the energy taken out of the system pushing the "wrong" way. Other motion patterns which aren't as extreme as the square wave will, at at least some frequencies, transfer more energy into the system than is taken out.

Usually we are interested in transmitting pulses in digital circuits so in most cases we don't take this wave phenomenology into consideration. In most cases it does not really matter the precise format of the square wave since it meets certain time specifications. But note that whether your square signal frequency rises up to a point where the wavelength is approximately in the order of magnitude of its transmission line may be a conductive track of a PCB , then you may take this wave phenomenology into consideration.

You still have a circuit in your hand but some wave phenomena may occur. So depending on your "line" impedance, some frequencies may have different propagation speed of other frequencies. Since the square wave is composed from many harmonics or ideally infinity you probably will have a distorted square wave in the end of your transmission line or conductive track because each harmonic will travel with different speed.

A good example where this may happen is when we use USB data transmission in a circuit. Note that the data rate is very high high frequency square waves so you must take the impedance of your transmission line into consideration. Otherwise you probably will have problems in the communication.

Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Learn more. What exactly are harmonics and how do they "appear"? Ask Question. Asked 9 years, 5 months ago. Active 5 years, 11 months ago. Viewed 71k times. John Quinn John Quinn 1 1 gold badge 3 3 silver badges 4 4 bronze badges.

Harmonics frequencies are tied into the definition of the Fourier series decomposition - so you will have harmonics if you decompose a square wave into sine waves. You could in theory use some other orthonormal basis - see supercat's comment below.

Add a comment. Active Oldest Votes. Making a signal instantly change from 0V to 5V takes an infinite amount of power, in reality there is some rise time to the square wave and this determines the amount of spectral content required. High speed digital signals can be the devil for unwanted radiated transmission if allowed because the fast rise time means you are driving some very high frequencies. The amount of which frequencies exist and most circuits can be looked at as affecting frequencies differently.



0コメント

  • 1000 / 1000