楚狂人 发表于 2010-9-8 17:02:29

Square wave signals

It has been found that any repeating, non-sinusoidalwaveform can be equated to a combination of DC voltage, sine waves,and/or cosine waves (sine waves with a 90 degree phase shift) atvarious amplitudes and frequencies. This is true no matter how strangeor convoluted the waveform in question may be. So long as it repeatsitself regularly over time, it is reducible to this series ofsinusoidal waves. In particular, it has been found that square wavesare mathematically equivalent to the sum of a sine wave at that samefrequency, plus an infinite series of odd-multiple frequency sine wavesat diminishing amplitude:

http://sub.allaboutcircuits.com/images/12093.png
This truth about waveforms at first may seem too strange to believe.However, if a square wave is actually an infinite series of sine waveharmonics added together, it stands to reason that we should be able toprove this by adding together several sine wave harmonics to produce aclose approximation of a square wave. This reasoning is not only sound,but easily demonstrated with SPICE.
The circuit we'll be simulating is nothing more than several sinewave AC voltage sources of the proper amplitudes and frequenciesconnected together in series. We'll use SPICE to plot the voltagewaveforms across successive additions of voltage sources, like this:(Figure below)
http://sub.allaboutcircuits.com/images/02110.png
A square wave is approximated by the sum of harmonics.
In this particular SPICE simulation, I've summed the 1st, 3rd, 5th,7th, and 9th harmonic voltage sources in series for a total of five ACvoltage sources. The fundamental frequency is 50 Hz and each harmonicis, of course, an integer multiple of that frequency. The amplitude(voltage) figures are not random numbers; rather, they have beenarrived at through the equations shown in the frequency series (thefraction 4/π multiplied by 1, 1/3, 1/5, 1/7, etc. for each of theincreasing odd harmonics). building a squarewave
v1 1 0 sin (0 1.27324 50 0 0)       1st harmonic (50 Hz)
v3 2 1 sin (0 424.413m 150 0 0)   3rd harmonic
v5 3 2 sin (0 254.648m 250 0 0)   5th harmonic
v7 4 3 sin (0 181.891m 350 0 0)   7th harmonic
v9 5 4 sin (0 141.471m 450 0 0)   9th harmonic
r1 5 0 10k      
.tran 1m 20m   
.plot tran v(1,0)    Plot 1st harmonic   
.plot tran v(2,0)    Plot 1st + 3rd harmonics
.plot tran v(3,0)    Plot 1st + 3rd + 5th harmonics
.plot tran v(4,0)    Plot 1st + 3rd + 5th + 7th harmonics
.plot tran v(5,0)    Plot 1st + . . . + 9th harmonics
.end

I'll narrate the analysis step by step from here, explaining what it iswe're looking at. In this first plot, we see the fundamental-frequencysine-wave of 50 Hz by itself. It is nothing but a pure sine shape, withno additional harmonic content. This is the kind of waveform producedby an ideal AC power source: (Figure below)   
http://sub.allaboutcircuits.com/images/22013.png
Pure 50 Hz sinewave.
Next, we see what happens when this clean and simple waveform iscombined with the third harmonic (three times 50 Hz, or 150 Hz).Suddenly, it doesn't look like a clean sine wave any more: (Figure below)   
http://sub.allaboutcircuits.com/images/22014.png
Sum of 1st (50 Hz) and 3rd (150 Hz) harmonics approximates a 50 Hz square wave.
The rise and fall times between positive and negative cycles are muchsteeper now, and the crests of the wave are closer to becoming flatlike a squarewave. Watch what happens as we add the next odd harmonicfrequency: (Figure below)         
http://sub.allaboutcircuits.com/images/22015.png
Sum of 1st, 3rd and 5th harmonics approximates square wave.
The most noticeable change here is how the crests of the wave haveflattened even more. There are more several dips and crests at each endof the wave, but those dips and crests are smaller in amplitude thanthey were before. Watch again as we add the next odd harmonic waveformto the mix: (Figure below)   
http://sub.allaboutcircuits.com/images/22016.png
Sum of 1st, 3rd, 5th, and 7th harmonics approximates square wave.
Here we can see the wave becoming flatter at each peak. Finally, addingthe 9th harmonic, the fifth sine wave voltage source in our circuit, weobtain this result: (Figure below)   
http://sub.allaboutcircuits.com/images/22017.png
Sum of 1st, 3rd, 5th, 7th and 9th harmonics approximates square wave.
The end result of adding the first five odd harmonic waveforms together(all at the proper amplitudes, of course) is a close approximation of asquare wave. The point in doing this is to illustrate how we can builda square wave up from multiple sine waves at different frequencies, toprove that a pure square wave is actually equivalent to a seriesof sine waves. When a square wave AC voltage is applied to a circuitwith reactive components (capacitors and inductors), those componentsreact as if they were being exposed to several sine wave voltages ofdifferent frequencies, which in fact they are.
The fact that repeating, non-sinusoidal waves are equivalent to adefinite series of additive DC voltage, sine waves, and/or cosine wavesis a consequence of how waves work: a fundamental property of allwave-related phenomena, electrical or otherwise. The mathematicalprocess of reducing a non-sinusoidal wave into these constituentfrequencies is called Fourier analysis,the details of which are well beyond the scope of this text. However,computer algorithms have been created to perform this analysis at highspeeds on real waveforms, and its application in AC power quality andsignal analysis is widespread.
SPICE has the ability to sample a waveform and reduce it into its constituent sine wave harmonics by way of a Fourier Transformalgorithm, outputting the frequency analysis as a table of numbers.Let's try this on a square wave, which we already know is composed ofodd-harmonic sine waves:squarewave analysis netlist
v1 1 0 pulse (-1 1 0 .1m .1m 10m 20m)   
r1 1 0 10k      
.tran 1m 40m   
.plot tran v(1,0)      
.four 50 v(1,0)
.end   

The pulse option in the netlist line describing voltage source v1instructs SPICE to simulate a square-shaped “pulse” waveform, in thiscase one that is symmetrical (equal time for each half-cycle) and has apeak amplitude of 1 volt. First we'll plot the square wave to beanalyzed: (Figure below)
http://sub.allaboutcircuits.com/images/22018.png
Squarewave for SPICE Fourier analysis
Next, we'll print the Fourier analysis generated by SPICE for this square wave:fourier components of transient response v(1)   
dc component =-2.439E-02
harmonicfrequency   fourier   normalized   phase   normalized
no          (hz)   component    component    (deg)   phase (deg)
1         5.000E+01   1.274E+00   1.000000    -2.195       0.000
2         1.000E+02   4.892E-02   0.038415   -94.390   -92.195
3         1.500E+02   4.253E-01   0.333987    -6.585      -4.390
4         2.000E+02   4.936E-02   0.038757   -98.780   -96.585
5         2.500E+02   2.562E-01   0.201179   -10.976      -8.780
6         3.000E+02   5.010E-02   0.039337-103.171    -100.976
7         3.500E+02   1.841E-01   0.144549   -15.366   -13.171
8         4.000E+02   5.116E-02   0.040175-107.561    -105.366
9         4.500E+02   1.443E-01   0.113316   -19.756   -17.561
total harmonic distortion =   43.805747percent

http://sub.allaboutcircuits.com/images/22019.png
Plot of Fourier analysis esults.
Here, (Figure above)SPICE has broken the waveform down into a spectrum of sinusoidalfrequencies up to the ninth harmonic, plus a small DC voltage labelled DC component.I had to inform SPICE of the fundamental frequency (for a square wavewith a 20 millisecond period, this frequency is 50 Hz), so it knew howto classify the harmonics. Note how small the figures are for all theeven harmonics (2nd, 4th, 6th, 8th), and how the amplitudes of the oddharmonics diminish (1st is largest, 9th is smallest).
This same technique of “Fourier Transformation” is often used incomputerized power instrumentation, sampling the AC waveform(s) anddetermining the harmonic content thereof. A common computer algorithm(sequence of program steps to perform a task) for this is the Fast Fourier Transform or FFTfunction. You need not be concerned with exactly how these computerroutines work, but be aware of their existence and application.
This same mathematical technique used in SPICE to analyze theharmonic content of waves can be applied to the technical analysis ofmusic: breaking up any particular sound into its constituent sine-wavefrequencies. In fact, you may have already seen a device designed to dojust that without realizing what it was! A graphic equalizeris a piece of high-fidelity stereo equipment that controls (andsometimes displays) the nature of music's harmonic content. Equippedwith several knobs or slide levers, the equalizer is able toselectively attenuate (reduce) the amplitude of certain frequenciespresent in music, to “customize” the sound for the listener's benefit.Typically, there will be a “bar graph” display next to each controllever, displaying the amplitude of each particular frequency. (Figure below)
http://sub.allaboutcircuits.com/images/02264.png
Hi-Fi audiographic equalizer.
A device built strictly to display -- not control -- the amplitudes ofeach frequency range for a mixed-frequency signal is typically called aspectrum analyzer.The design of spectrum analyzers may be as simple as a set of “filter”circuits (see the next chapter for details) designed to separate thedifferent frequencies from each other, or as complex as aspecial-purpose digital computer running an FFT algorithm tomathematically split the signal into its harmonic components. Spectrumanalyzers are often designed to analyze extremely high-frequencysignals, such as those produced by radio transmitters and computernetwork hardware. In that form, they often have an appearance like thatof an oscilloscope: (Figure below)
http://sub.allaboutcircuits.com/images/02265.png
Spectrum analyzer shows amplitude as a function of frequency.
Like an oscilloscope, the spectrum analyzer uses a CRT (or a computerdisplay mimicking a CRT) to display a plot of the signal. Unlike anoscilloscope, this plot is amplitude over frequency rather than amplitude over time.In essence, a frequency analyzer gives the operator a Bode plot of the signal: something an engineer might call a frequency-domain rather than a time-domain analysis.
The term “domain” is mathematical: a sophisticated word to describe thehorizontal axis of a graph. Thus, an oscilloscope's plot of amplitude(vertical) over time (horizontal) is a “time-domain” analysis, whereasa spectrum analyzer's plot of amplitude (vertical) over frequency(horizontal) is a “frequency-domain” analysis. When we use SPICE toplot signal amplitude (either voltage or current amplitude) over arange of frequencies, we are performing frequency-domain analysis.
Please take note of how the Fourier analysis from the last SPICEsimulation isn't “perfect.” Ideally, the amplitudes of all the evenharmonics should be absolutely zero, and so should the DC component.Again, this is not so much a quirk of SPICE as it is a property ofwaveforms in general. A waveform of infinite duration (infinite numberof cycles) can be analyzed with absolute precision, but the less cyclesavailable to the computer for analysis, the less precise the analysis.It is only when we have an equation describing a waveform in itsentirety that Fourier analysis can reduce it to a definite series ofsinusoidal waveforms. The fewer times that a wave cycles, the lesscertain its frequency is. Taking this concept to its logical extreme, ashort pulse -- a waveform that doesn't even complete a cycle --actually has no frequency, but rather acts as an infinite range of frequencies.This principle is common to all wave-based phenomena, not just AC voltages and currents.
Suffice it to say that the number of cycles and the certainty of awaveform's frequency component(s) are directly related. We couldimprove the precision of our analysis here by letting the waveoscillate on and on for many cycles, and the result would be a spectrumanalysis more consistent with the ideal. In the following analysis,I've omitted the waveform plot for brevity's sake -- its just a reallylong square wave:squarewave
v1 1 0 pulse (-1 1 0 .1m .1m 10m 20m)   
r1 1 0 10k      
.option limpts=1001   
.tran 1m 1      
.plot tran v(1,0)      
.four 50 v(1,0)
.end   
fourier components of transient response v(1)   
dc component =   9.999E-03
harmonicfrequency    fourier    normalized   phase   normalized
no         (hz)   component   component    (deg)   phase (deg)
1         5.000E+01   1.273E+00   1.000000    -1.800       0.000
2         1.000E+02   1.999E-02   0.015704    86.382      88.182
3         1.500E+02   4.238E-01   0.332897    -5.400      -3.600
4         2.000E+02   1.997E-02   0.015688    82.764      84.564
5         2.500E+02   2.536E-01   0.199215    -9.000      -7.200
6         3.000E+02   1.994E-02   0.015663    79.146      80.946
7         3.500E+02   1.804E-01   0.141737   -12.600   -10.800
8         4.000E+02   1.989E-02   0.015627    75.529      77.329
9         4.500E+02   1.396E-01   0.109662   -16.199   -14.399

http://sub.allaboutcircuits.com/images/22020.png
Improved fourier analysis.
Notice how this analysis (Figure above)shows less of a DC component voltage and lower amplitudes for each ofthe even harmonic frequency sine waves, all because we let the computersample more cycles of the wave. Again, the imprecision of the firstanalysis is not so much a flaw in SPICE as it is a fundamental propertyof waves and of signal analysis.[*]REVIEW:[*]Square waves are equivalent to a sine wave at the same(fundamental) frequency added to an infinite series of odd-multiplesine-wave harmonics at decreasing amplitudes.[*]Computer algorithms exist which are able to sample waveshapes and determine their constituent sinusoidal components.The Fourier Transform algorithm (particularly the Fast Fourier Transform, or FFT)is commonly used in computer circuit simulation programs such as SPICEand in electronic metering equipment for determining power quality.
页: [1]
查看完整版本: Square wave signals