SINE, COSINE, AND θ 31 cos −cos j cos −j cos sin −sin j sin ( h ) (g) (f ) (e) (d ) (c) − j sin (a) (b) RealImaginary Figure 2-2 Phasor polarity and type for all possible sine–cosine waves. Solid lines: real; dashed lines: imaginary. amplitude 8. The spectrum is positive-sided at 2 and 6. x(n) = 5cos 2π n N 2 − j 8cos 2π n N 6 (2-1) 32 DISCRETE-SIGNAL ANALYSIS AND DESIGN In Fig. 2-3 the (n) step size 0.1 from 0 to N −1 provides smooth curves in the real and imaginary x(n) graphs. Figure 2-3 shows the following: • The real cosine spectrum at k =2 and 14, amplitude 2.5 +2.5 = +5.0 (see Fig. 2-2a). • The −j cosine spectrum at k =6 and 10, amplitude −4 −4 =−8 (see Fig. 2-2f). • The phase at k =2 and 14 ( =0 ◦ ). • The phase at k =6 and 10 ( =−90 ◦ ). Observe that Mathcad provides the correct two-sided phasors (Fig. 2-2) that the subsequent two-sided IDFT restores to the input x(n). If x (n)is viewed from 0 to N −1, the positive frequencies 2 and 6 (number of cycles per record length) are visible. In more complicated situations it is a good idea to avoid possible con- fusion by making sure that all of the Re[X (k)] and Im[X (k )] phasor pairs are combined into the correct one-sided real and imaginary sine and cosine positive-frequency constituents, as deÞned in Fig. 2-2. For the example in Fig. 2-3, the one-sided output is +5 cosine at f =2at0 ◦ and −j 8 cosine at f =6at−90 ◦ . Note the use of the Mathcad function [atan2 (Re(x), Im(x))]·180/π ◦ , which covers the range ±180 ◦ , as compared with atan(x) · 180/π ◦ , which only covers ±90 ◦ . There are some possibilities for “de-cluttering” the results: • If Im(X (k )) < 0.0001, set φ(k ) =0 to avoid clutter in the phase data. • If Re(X (k)) < 0.0001, set Re(X (k)) =0.0001. • If j Im(X(k )) > j 1000, set j Im(X (k)) =j 1000. • If j Im(X(k )) < −j 1000, set j Im(X (k)) =−j 1000. • Scale the problem to avoid values of X (k) < 0.001 or > 1000. In the next example we use just the cosine wave with a phase advance of +60 ◦ =(π/3 radians): X(k) = 1 N N−1 n=0 7cos 2π n N 4 + 60 · π 180 exp − j2π n N k (2-2) SINE, COSINE, AND θ 33 −10 10 −5 0 5 −5 5 k 180 π 24 8 1214 610 0 0 n 24 8 12146100 2 0 if ⏐Im(X(k))⏐ < .0001 atan2 [Re(X(k)), Im((X(k)))] 48 6 10 12 14 −90 −60 −30 30 60 90 φ(k) k φ(k) := ⋅ Re(X(k)) Im(X(k)) Re(x(n)) Im(x(n)) 1 N ∑ X(k) := x(n) := N−1 n = 0 5⋅cos ⋅exp− j⋅8⋅cos2⋅π⋅ ⋅2 n N ⎛ ⎛ ⎛ ⎛ ⎛ ⎛ ⎛ ⎛ ⎛ ⎛ ⎛ ⎛ 2⋅π⋅ ⋅6 n N ⎛ ⎛ ⎛ ⎛ −j⋅2⋅π⋅ ⋅k n N 5⋅cos − j⋅8⋅cos2⋅π⋅ ⋅2 n N ⎛ ⎛ ⎛ ⎛ 2⋅π⋅ ⋅6 n N ⎛ ⎛ ⎛ ⎛ ⋅ N := 16 k := 0, 1 N − 1 n := 0, 0.1 N − 1 Figure 2-3 Example of two-tone signal and its spectrum components and phase (deg). Figure 2-4 shows that a +60 ◦ component has been added to the cosine component, as Fig. 2-2d conÞrms. The amplitude of the cosine seg- ment is 1.75 +1.75 =3.5V. The amplitude of the −sin θ component is 3.03 +3.03 =6.06V. The phase is shown as +60 ◦ . In these two examples we started with the equations for the signal, then by examining the phasors in Fig. 2-2 we veriÞed that they coincided with 34 DISCRETE-SIGNAL ANALYSIS AND DESIGN x(n) := 7⋅cos 2⋅π⋅ ⋅4 + 60⋅ n N π 180 N := 16 n := 0,.01 N − 1 k := 0, 1 N − 1 −10 0 10 n 24 8 12146100 −1 1 2 0 −5 5 0 k 24 8 12146100 k 24 8 12146100 −100 100 50 −50 0 k 24 8 1214166100 Im(x(n)) Im(X(k)) Re(x(n)) Re(X(k)) 1 N X(k) : = ⋅ x(n)⋅exp −j⋅2⋅π⋅ n N ⋅k 180 π 0 if ⏐Im(X(k))⏐< .001 atan2 (Re(X( k)), Im((X(k))) θ(k) := θ(k) ⋅ ∑ N−1 n = 0 Figure 2-4 Sine wave with 60 phase advance. SINE, COSINE, AND θ 35 the given signal. In practice we might not know the waveform ahead of time and we would be asked to examine the phasor amplitudes and phases and use Fig. 2-2 to determine the signal. We will Þnd uses for the positive-side techniques described in this chapter and others. Because of the simplicity and the familiarity with positive-domain frequency usage in many practical engineering situations, the sine–cosine–θ approach described here is encouraged. When setting up a problem to get the line spectrum, be sure that (k ), the frequency index, is deÞned as an integer array. In Mathcad the assig- ment statement k : =0, 1 N −1 works. Otherwise, the DFT generates a lot of complex answers for noninteger values of k and the spectrum becomes “smeared,” which obscures the desired line spectrum answers. This general rule is a good idea in discrete wave analysis problems. Oper- ate at integral values of (n) (time domain) and (k) (frequency domain) if possible. Procedures for dealing with noninteger values will be covered in later chapters, especially Chapters 3 and 4. The calculations in Example 2-1 demonstrate how the two-sided DFT X (k ) of the two-sided x (n), converted to positive-frequency X (k) only, can be an excellent spectrum amplitude and phase analyzer for a nonlinear device, circuit, or system in the real-world positive frequency domain. Adjustments to signal level(s) of two or more signals and device biasing parameters can very quickly present a picture of the spectrum response of the circuit. This is an almost-free Spectrum Analyzer that can be very accurate and versatile over a very wide frequency range if (a big “if”) the nonlinear devices used are deÞned correctly. The main requirement is that we have either an equation or an example data Þle for the device. One interesting experiment is to look at nonlinear reactions to a two- tone signal, then vary the amplitude of a strong third signal that is on a third out-of-band frequency to see the degradation of the in-band two-tone signal. This can be very illuminating and very practical. Example 2-1: Nonlinear AmpliÞer Distortion and Square Law Modulator To get some hands-on experience, this example will look at the intermodu- lation (mixing) products of an ampliÞer circuit that is not perfectly linear. We will use the DFT [Eq. (1-2)] to get the spectrum and IDFT (Eq. 1-8) . at 2 and 6. x(n) = 5cos 2π n N 2 − j 8cos 2π n N 6 (2-1) 32 DISCRETE-SIGNAL ANALYSIS AND DESIGN In Fig. 2-3 the (n) step size 0.1 from 0 to N −1 provides smooth curves in the real and. =2 and 14, amplitude 2.5 +2.5 = +5.0 (see Fig. 2-2a). • The −j cosine spectrum at k =6 and 10, amplitude −4 −4 =−8 (see Fig. 2-2f). • The phase at k =2 and 14 ( =0 ◦ ). • The phase at k =6 and. advance. SINE, COSINE, AND θ 35 the given signal. In practice we might not know the waveform ahead of time and we would be asked to examine the phasor amplitudes and phases and use Fig. 2-2 to determine