+ All Categories
Home > Documents > ApendiceA.PDF

ApendiceA.PDF

Date post: 04-Oct-2015
Category:
Upload: vinicius-bacon
View: 2 times
Download: 0 times
Share this document with a friend
Popular Tags:
24
APPENDIX A Spectral Estimation The purpose of this appendix is to demystify the procedure of analyzing LlL data using the Fast Fourier Transform (FFT) [1]. The FFT is widely used to estimate the power spectral density of LlL data, but is also sometimes abused in the process. When using the FFT to analyze L\:E data, the L\:E designer needs to be familiar with several important concepts, namely windowing, scaling, noise bandwidth and averaging. This appendix deals with each of these subjects in tum, applies them to an example, and concludes with a brief discussion of the mathematical back- ground. The FFT is a fast algorithm for computing the Fourier Transform N-I X(f) = L x(n) . e-j21tfn n=O (A.I) of a length-Ndiscrete-time sequence x(n) at the N frequency points, the FFT bins, f = 0, liN, 21N, ... , (N -l)/N. t t. Here, as earlier, the sampling rate is assumed to be 1 Hz. 365
Transcript
  • APPENDIX A Spectral Estimation

    The purpose of this appendix is to demystify the procedure of analyzing LlL datausing the Fast Fourier Transform (FFT) [1]. The FFT is widely used to estimate thepower spectral density of LlL data, but is also sometimes abused in the process.When using the FFT to analyze L\:E data, the L\:E designer needs to be familiar withseveral important concepts, namely windowing, scaling, noise bandwidth andaveraging. This appendix deals with each of these subjects in tum, applies them toan example, and concludes with a brief discussion of the mathematical back-ground.

    The FFT is a fast algorithm for computing the Fourier Transform

    N-I

    X(f) = L x(n) . e-j21tfnn=O

    (A.I)

    of a length-Ndiscrete-time sequence x(n) at the N frequency points, the FFT bins,f = 0, liN, 21N, ... , (N -l)/N. t

    t. Here, as earlier, the sampling rate is assumed to be 1 Hz.

    365

  • APPENDIXA Spectral Estimation

    A discrete-time signal with period N consists of a de term and harmonics of thefundamental frequency f 1 = 1IN. Since the amplitude of the ith harmonicf i = i/N for i:t 0 is given by 2IX(fi)II N, an FFT can easily be used to com-pute the power spectrum of a periodic signal. Unfortunately, since LU: data is typi-cally not periodic, a direct application of the FFT to LU: data is unwise at best.

    We shall consider the "noise" associated with LU: data to be like a random signal,for which a more technical term is stochastic process [2]. If the data comes frommeasurements, then it is bound to contain components which are true noise andour viewpoint is justified. For data obtained from simulation, the noise is the resultof a deterministic process, and so it is not strictly proper to describe this process asrandom. However, since the process is complex, non-linear and often chaotic, thefact that the process is actually deterministic has little practical impact.

    A.I Windowing

    Windowing is the act of multiplying the signal to be analyzed by a window func-tion w(n) before subjecting it to an FFT. At first glance, it would appear that thisoperation would alter the spectral content of the signal and therefore be undesir-able. Although it is true that windowing alters a signal's spectrum, some window-ing is inevitable because we can never obtain an infinite-length record ofmodulator data. The best we can do is operate on a finite record of length N. Sincea finite-length record can be thought of as the product of the infinite-duration mod-ulator output and a rectangular window

    () = { 1, O~n~N-lw rect n .'0, otherwise

    (A.I)

    the damage caused by windowing the data has already been done. Thus the ques-tion is not "Should I window my data?" but rather "How should I window mydata?"

    366

  • Windowing

    The answer to this question lies in the relationship between the spectrum of theoriginal data and that of the windowed data. Since multiplication In the timedomain corresponds to convolution in the frequency domain, the spectrum of awindowed signal is, loosely speaking, the spectrum of the unwindowed signal con-volved with the window's spectrum. In order to obtain an accurate spectrum, thedesigner must choose a window which introduces sufficiently low errors throughspectral convolution.

    Consider the three windowing functions illustrated in Fig. A.I. Table 1 lists theirdefinitions, and summarizes various parameters which will be discussed in thisAppendix. Since a rectangular window has discontinuities at its endpoints,whereas the Hann and Hann2 windows are continuous (up to the 2nd and 4th deriv-atives, respectively), we would expect the rectangular window to have a great dealmore high-frequency content than the other two windows. This suspicion in con-firmed in Fig. A.2, which plots the magnitudes of the Fourier transform

    N -1

    W(f) = L w(n) . e-j2rtfn, (A.2)11=0

    n

    Figure A.I: Three common windows (N =32).

    367

  • APPENDIX A Spectral Estimation

    normalized by the dc gain W(O), for each of these windows. N = 32 points wereused. As Fig. A.2 shows, the peaks of the high-frequency lobes in the spectrum ofthe rectangular window approach a constant value (which is proportional to 1/N),whereas the peaks of the high-frequency lobes of the Hann and Hann2 windows goto zero with -60 dB/decade and -100 dB/decade slopes, respectively. The high-

    Wind0\\' Rectangular Hann RanD2

    l-1:(n) , n = 0, I, ... ,N-I 21t1l [I -c:s2~'JI-cos-t N(w(n) = 0 otherwise) 2

    IIwlli N 3N/8 35N/128No of non-zero FFf bins I 3 5

    W(O) N N/2 3N/8

    NBW liN 1.51N 35/( 18N)

    Table A.I: Properties of the three windows illustrated in Fig. A.I.

    ".. .. ~ .. ... ~./ .. " .. ".",/' ... .. ... ,,

  • Windowing

    frequency behavior of a window's spectrum is of critical importance in determin-ing the magnitude of the error resulting from convolution.

    As a demonstration of the convolution problem, Fig. A.3 shows the spectrum ofsome noise-shaped data, the Fourier transform of a 256-point rectangular windowand the Fourier transform of the windowed data. As indicated in Fig. A.3, theskirts of the window convolve with the out-of-band noise, thereby filling in thenoise notch and dramatically reducing the apparent SNR.

    The ~L designer must ensure that this noise leakage is small compared to theactual in-band quantization noise density. In the context of a high-accuracy ~Lmodulator, the difference between the out-of-band noise density and the in-bandnoise density can be 80 dB or more. Fig. A.3 indicates that with N = 256, theobservable difference between the out-of-band and in-band noise densities is onlyabout 23 dB. Increasing N improves the situation, but only at the rate of 3 dB peroctave. According to this trend, a rectangular window would need to use more than108 points to reliably observe an 80 dB difference in noise densities!

    - .... Actual aI: spectrum

    - W(~f)/lflVfI2

    ---- Windowed spectrum

    40

    20

    0en"'0

    -20

    -40

    -600 0.25

    Normalized Frequency, fFigure A.3: A rectangular window obscures a noise null.

    0.5

    369

  • APPENDIXA Spectral Estimation

    The LU: designer is therefore compelled to use something other than a simple rect-angular window. Many different windows exist (for example, see [3] or [4]) but thefeature of greatest importance to the ~L designer is the amount of high-frequencyattenuation provided by the window. Windows which have finite high-frequencyattenuation, such as the Hamming window, are less desirable than windows whosehigh-frequency attenuation increases without bound. In particular, a Hann windowwith N = 512 is able to resolve an 80 dB difference in noise density, while aHann2 window does similarly well with N = 256. Since the number of datapoints needed to provide sufficient frequency resolution is usually on the order ofseveral thousands, a simple Hann window usually provides sufficient protectionagainst noise leakage.

    Another important consideration in the analysis of LU: data is signal leakage. It isconvenient, both in the lab and in simulation, to use sine-wave excitation. How-ever, the frequency of that sine wave must be located precisely in an FFT bin, oth-erwise signal power will bleed into all bins. Fig. A.4 illustrates this phenomenonwith severallength-512 FFTs of two sine waves. The first has a frequency which is

    0.5

    , .. ..': frequency" - ':' - " - .: frequency' - . : _. - .. - -:- - _.' --: =73/512 . - .. :. _.. , -: = 2/7 . - . ~ - - ... - -:- - - . - ..:~.. -: _._-: - ~._.-: -: .. _-_.-:._ .. _ ..

    . . ....... _ .... -.... _. - ... - ....... .

    .............. _ - - ., ............... _ ........ - .. _ .. - _ .. - .

    .20 . --... -:- -_ ~ .

    ............ -,- -., ..

    .o -- -_ p -............ -, ...

    0.25

    Normalized Frequency, f

    Figure A.4: FFTs of coherent and incoherent sine waves (N =512).

    -1 00 ~_---'--_-.L. J.a..-.-~-'-- ""'--_~a....----a-__~_--.L--_----Jo

    -60

    -80

    t- --40u..u...

    ...........CO -20"'0'--""

    370

  • Windowing

    located precisely in an FFT bin (specifically, bin 73, which is close to a frequencyof 1/7), while the second has a frequency of exactly 2/7 and so is not in an FFTbin. In the first case (the coherent case), the sine wave's power is concentrated in asmall number of FFf bins (1 for a rectangular windowing, 3 for Harm, and 5 forHann2). In the incoherent case, the sine wave's power is smeared over all FFf bins.The severity of the spreading is determined by how far away the sine wave is fromthe nearest bin frequency, and by the shape of window's skirts. As was the casewith noise leakage, the rectangular window exhibits the greatest signal leakagebecause its skirts are the most broad.

    In simulation, it is a simple matter to place the signal frequency in an FFf bin andthereby eliminate signal leakage entirely. In the lab, signal leakage can be mini-mized by phase-locking the generators, and by setting the signal frequency accu-rately. If it is not possible to place the signal frequency in an FFf bin, windowingcan be used to reduce spectral pollution. Alternatively, the signal's frequency andamplitude can be estimated, and the estimated signal can be subtracted from thedata record to leave only the noise.

    The final question regarding windowing which we will address is the length of thewindow required to obtain an accurate estimate of a modulator's SNR. The sim-plest way to estimate SNR is to compute the ratio of the power in the signal bins tothe power in the in-band noise bins. Since the signal is usually placed in-band, ittherefore occupies a few of the in-band bins. The number of bins occupied by thesignal should be a relatively small fraction (less than 20%) of the in-band bins inorder to have a small effect (less than 1 dB) on the SNR estimate. If we are using aHarm window, the signal will occupy 3 bins and thus we should have at least 15 in-band bins, which in tum requires N ~ (30 . OSR) bins in all, where OSR is theoversampling ratio.

    If the noise is assumed to be flat in-band, the rrussmg noise power can beaccounted for by multiplying the power in the noise bins by 1/( 1 - a) , where a isthe fraction of in-band bins occupied by the signal. Unfortunately, at least in simu-lation, the in-band quantization noise follows the NTF and so tends to be non-flat.Alternatively, the noise in the signal bins can be estimated by subtracting out theestimated signal component before or after performing the FFf.

    371

  • APPENDIX A Spectral Estimation

    Another consideration regarding the required length of the data record relates tothe repeatability of the SNR measurement. Since the FFT of a random signal isitself a random quantity, the in-band noise power computed from the FFT is also arandom quantity. Numerical experiments indicate that using N = 30 OSRresults in SNR estimates which have a standard deviation of about 1.4 dB. UsingN = 64 OSR results in a standard deviation of about 1.0 dB, whileN = 256 OSR is needed to reduce the standard deviation to 0.5 dB. This degreeof repeatability is usually not required on an individual measurement, since it iscommon for many measurements to be carried out, as would be the case during aninput amplitude sweep. The authors recommend using N = 64 OSR.

    A tertiary consideration regarding the required length of the data record relates tothe observable spurious-free dynamic range (SFDR). Using N = 64 OSR is usu-ally sufficient to reliably observe an SFDR which is about 10 dB greater than theSNR. In order to detect tones which are more than 10 dB below the total in-bandnoise, N needs to be increased. Specifically, doubling N increases the observableSFDR by 3 dB.

    A.2 Scaling and Noise Bandwidth

    The astute reader may have already observed that the spectral spike associatedwith a sine-wave component in the data record has a height (as in Fig. A.4) that isdependent on both the window type and the window length. Most windows havemaxtW(f)l = W(O) (i.e. the peak in the window's spectrum occurs at de), and sothe height of the peak corresponding to a sine wave is A . W(O)/2, where A is theamplitude of the sine wave.

    When displaying a spectral plot, it is customary to scale the FFT such that a full-scale sine wave yields a O-dB spectral peak. If we denote the full-scale range byFS, the amplitude of a full-scale sine wave is A = FS/2 and thus the scaled ver-sion of the FFT which we would present is

    372

  • Scaling and Noise Bandwidth

    Sx'(f)

    N -1 2

    L w(n) x(n) e- j 21t!n= n =0

    (FS/4)W(O)(A.3)

    Note that we have squared the magnitude in order to allow us to interpret Sx'(f) asa power spectral density (PSD). The power of a sine-wave signal relative to thepower of a full-scale sine-wave signal is therefore given by IOIogSx'(f) , where fis the frequency of the signal. The units of this quantity are often given as dBFS(dB relative to full-scale) in order to emphasize that the reference power is thepower of a full-scale sine wave, but we shall see shortly that these units omit animportant detail. The caret on the symbol Sx'(f) indicates that the above expres-sion is an estimate ofthe PSD, while the prime indicates that we have scaled theestimate so that sine-wave signals yield calibrated spike heights.

    Although the above scaling is convenient for analyzing a signal which consists ofsine waves, it is less convenient for analyzing a signal which contains noise.Fig. A.5 illustrates the problem by plotting Sx'(f) for a signal consisting of ao dBFS sine wave plus white noise having the same power as the sine wave, whendifferent-length rectangular windows are used. (A rectangular window is safe here,since we are not interested in observing notches in Sx'(f).) Although the signalspike has the same height in each case, the average "noise floor" of Sx'(f) dropsby 3 dB every time N doubles. Since the noise power is 'actually 0 dBFS in eachcase, the location of the "noise floor" is not the only piece of information that thereader needs.

    The problem with sine-wave scaling is that the noise power is, on average, evenlydistributed over all FFT bins, whereas the sine-wave power is concentrated in onlya few bins. With sine-wave scaling, the power of individual sine-wave componentscan be read directly from the spectral plot, but in order to determine the noisepower, the powers of all the noise bins must be added together.

    373

  • APPENDIX A Spectral Estimation

    An alternative method of scaling, which is common in signal-processing texts, is toscale the FFf such that it provides a calibrated noise density. The appropriate scalefactor in this case is l/llwlli,where

    N -1

    IIwlli = L Iw(n)/211=0

    (A.4)

    is the energy of the window. t When this scaling is used, the PSD estimate is

    . .o ..... 0 dBFS sine wave ~ - - - - - .. :-" " . - . - . - ; " - - - - - - . -: - " - - " . " . -:- - - - - .. -

    t I ,

    I

    - -- - ":- ""---... ~ --"-"--- ~. 0 dBFS noise . I

    N=26 -~: ~~r--..__--a---.......

    I I ........................... -- -_ -_ .. -_ .... . . .I , . . .

    I

    I

    I

    , , t ................................... _ -_ ...

    : : : N=212 ' IflIII'l............-..........,....

    ................ -1- -.- ..

    I I I

    I I I

    I I

    I I

    , ............................................................. - --, I I

    I I

    I , ,=- -10enu..CD:0'-' -20 .,...'-""__~ .-_~_.~~-.,.__,~ : :~ ~~....,.".~~~~ltW~-~-~."M"-- N- ~.21ifu- ~-~~-w-~--~~~~~~~..(~ -30

    I It'................................. 4 ..

    I . . ,I ,

    -40 ~_--..L.__--L-. ----'~ ---.J

    o 0.25 0.5Normalized Frequency, f

    Figure A.5: FFTs of a sine wave plus white noise; sine-wave scaling.

    (

    N -I ) IIp

    t. The notation IIwll 2 means Zmorm, a special case ofthe p-norm Ilwllp = n~olw(n)IP .

    374

  • Scaling and Noise Bandwidth

    Sx(f) =

    N -1 2

    L w(n) x(n) . e-j2rtfnn=O

    Ilwll~(A.5)

    and as a result unit-power white noise yields a unit (O-dB) density, regardless ofthe window type or length. Unfortunately, scaling for noise in this way makes theheight of a sine-wave spike dependent on both the window type and length.

    Our resolution of the scaling dilemma follows the solution adopted in laboratoryinstruments, specifically in spectrum analyzers. A spectrum analyzer must contendwith the problem of representing the spectrum of a periodic signal such as a sinewave on the same display as is used to represent the spectral density of a broad-band signal such as noise. In a spectrum analyzer, the signal can be thought of asbeing processed by a bank of filters possessing identical filtering characteristics(gain, bandwidth, etc.), albeit with different center frequencies. The instrumentmeasures the powers at the outputs of the filters and constructs a plot of power ver-sus center frequency.

    For a sine-wave input, the display shows a peak at the input frequency, the heightof which equals the input power. Thus, the spectrum displayed by a spectrum ana-lyzer is like an FFf with sine-wave scaling. For noise, the display indicates thepower of the noise that lies in each filter's bandwidth. In other words, for a noise-like signal, the display gives the product of the noise density and the noise band-width of the filters.

    For a filter with infinitely steep roll-off, the noise bandwidth (NBW) is equal to thefilter's bandwidth, while for a filter with a single-pole roll-off, NBW is n/2 timesthe 3-dB bandwidth. In general, a filter's NBW is the bandwidth of an ideal brick-wall filter which has the same output power given a white noise input and whichhas the same mid-band gain as the filter under consideration. A spectrum analyzersolves the scaling problem by providing NBW along with each spectrum, therebyproviding the designer with the information needed to convert the power shown onthe display into a power density. NBW depends on various analyzer settings,

    375

  • APPENDIX A Spectral Estimation

    including those that determine the frequency range and resolution for the spectralplot.

    The solution to the scaling problem in the case of a PSD obtained from a sine-wavescaled FFf is similarly simple. All we need do is provide the value of NBW.

    The value of NBW is listed in Table 1 for the three windows considered in thisappendix. For each window, NBW is inversely proportional to N, and thus doublingN decreases the apparent level of the noise in a sine-wave scaled PSD by 3 dB, asindicated in Fig. A.5. Let us now illustrate the use of NBW in the calculation of thetotal noise power. From the top curve in Fig. A.5, we observe a "noise floor" ofapproximately -15 dBFS, which is the amount of power in bandwidthNBW = liN = 2-6 . The total power in the entire Nyquist band [0,0.5] istherefore 0.51 NBW = 25 times (15 dB more than) the observed -15-dBFS value,or 0 dBFS, which is exactly the correct value.

    The NBW, or at least sufficient information for calculating it (namely N and thewindow type), should always be given for a sine-wave-scaled FFf. Furthermore, inorder to emphasize that such an FFT represents a power spectral density, the unitson the vertical axis should be shown as power per unit bandwidth. Since we reportpower in dBFS and since the unit of bandwidth is NBW, the vertical axis is usuallylabelled "dBFS/NBW."t

    A.3 Averaging

    Our final point of discussion regarding the use of FFfs for spectral analysis isaveraging. We noted earlier that the FFf of a random waveform is itself a randomquantity. This quantity is random in both magnitude and phase, but since we are

    t. Although in common usage, units such as dBFS/NBW or dBm/Hz are deceptive: a density ofI dBm/Hz does yield 1 dBm of power in a I-Hz bandwidth but not 2 dBm of power in a 2-Hzbandwidth! Doubling the bandwidth doubles the power (a 3-dB increase), yielding a 4 dBmpower in a 2-Hz bandwidth. The way out of this notational morass is to interpret "dBmlHz" tomean "dB with respect to a 1 mW per Hz density." Similarly,"dBFS/NBW" means "dB withrespect to a density equivalent to the power of a full-scale sine wave spread over a bandwidthNBW."

    376

  • Averaging

    concerned with power we will only consider the magnitude. The magnitude of aparticular frequency bin in an FFf of a random signal is a random value that hasboth a mean and a standard deviation. It turns out that the expected value t of theFFf magnitude equals the actual PSD (convolved with the window), as we wouldhope, but that the standard deviation of the magnitude is large. In fact the standarddeviation is equal to the expected value!

    The upshot of this property is that a single FFf results in a "noisy" spectra] esti-mate, as demonstrated in Fig. A.6, where three length-64 FFfs of O-dBFS whitenoise are shown. Each curve is expected to be a flat line at -15 dBFS, but this is notapparent in the Figure due to the large degree of variability in the individual binmagnitudes.

    " ) j(o .-.. v v -:. v . v , v ':'; v _ , v : v v v , , v:-.. v v. v v. v: . , ,. , _, ., v -: . , _ v.. v .:- v v v v . ,( .

    ., >

    ~ '" I< ." ;, ( , ,

    ~ -1 ,:, ,,~,:: :,~~ '::,"~::.:'1':' :::: 1,:'~~'en ~t. ~ II''I! \ + ,', ~, '~lll' \~'. .1\1"~ -}~: ''';''I~'o!.: .. '1' ," ""~~ii""IiI.\A.'.\' :", a'Ii'''' \t* '~l'r VA v',"0 a. 1It. --, , LA ,A ... 1 \ vr:'ir < I ~ , \ (, I'-' -20 :\t.;+~~1!lv.Ii.. v.vv ;Av"",,':v.v\/v,A~.v .v .

    S '" /., '~""~ ~!~""""~. ~ ..... :, ... , ...r: .... \. :\> /..W~,"... ~ 19 E!I: ,: : : : ~ d. \J : \ I!J v v .: vI .'.:' v v " v v .i . v.. , . v , .: v , v ~v. v , v. v ': v v " v:. v., ,. v ,

    \ I : : NBW=1/64-40 "'----"---.-.......-~--~--"-----"--"'--------"------"

    o 0.25 0.5Normalized Frequency, f

    Figure A.6: Three length-64 FFTs of O-dBFS white noise.

    t. Expected value is another term for mean, or average, value.

    377

  • APPENDIXA Spectral Estimation

    If one is computing a noise power (by summing the powers over a range of FFTbins), the variability of an individual bin magnitude is not problematic, provided asufficient number of bins are used. However, if one is trying to construct a cleargraph of a spectral density, the erratic nature of the bin magnitudes results in afuzzy plot such as that shown in Fig. A.7. Here, instead of a smooth curve, we seea broad black band spanning nearly 20 dB which obscures the true noise density.There are two solutions to this problem, namely averaging and integration. Averag-ing can be performed by either averaging many FFfs, or by averaging nearby binsin a single FFf.

    Averaging multiple FFfs requires the use of multiple data records. When a singlelarge data record is available, it can be partitioned into many ,(possibly overlap-ping) records which are individually windowed and transformed with an FFf.Averaging the squared magnitudes of these FfTs reduces the standard deviationand so improves the legibility of the spectral plot. (At this point, we owe the readera confession: the spectra shown in Figs. A.3 and A.5 were averaged in this way forthe sake of clarity.) Similarly, averaging the powers in adjacent bins will also

    . , ,.......... -t- - -.- 1_ - _.4O""" _I. _ _

    I

    I I I

    '_ __ too .. or" _ .. l .. __ _' J I '_ _ _

    t I I . . .. ., I I I .... - .. _ -_ - _ .. - _ _ _ - ..I I I

    , . . . .................... ' _' L '_ .1_ _I '_ ..

    I f

    I I

    , f t , I ................................................ - _ ... t t ., ,

    -,"

    I

    " -- -- - .: ---_.. -: -- ---_.. ~ -- --- -- -:- - - -- -- - ~ -- -- ---" :-NBW =9.2x10-

    0

    ...-... -20~coZ-...... -40(J)LLco~ -60~

  • An Example

    smooth the FFf, effectively by "filtering" it. We present an example of this form ofaveraging in the next section.

    The second method for increasing the legibility of a spectrum is to plot its accumu-lated value, scaled by l/(N NBW). The resulting plot shows the amount ofpower contained in the band from de up to the current frequency, and so saves thereader the effort of performing an integration to obtain a noise power. Of course,the designer is obliged to empty the signal bins before performing the integration,and the method must be changed when dealing with bandpass noise-shaping.Fig. A.8 illustrates the effectiveness of the technique in smoothing out the FFf ofFig. A.7. (Some might argue that the technique is too effective, since it hides high-frequency tones that are readily apparent in the original FFf.)

    A.4 An Example

    We have now covered the essential topics regarding the use of the FFf to calculatea sine-wave scaled PSD, and so are ready to demonstrate them with an example.Fig. A.9 shows some example MATLAB code for producing a record of ~L dataand analyzing it according to the above procedures.

    Or----.,...----.,.---~--r----.,...--~--_r__-____,

    I ........ T"'''' - - -,- 1- _ , .... . . .. . . .

    -80 ----'-__--'--___"____r.....--_--'-__---"---__...&..-_---'o 0.25 0.5

    Normalized Frequency, f

    Figure A.8: Integrated version of the noise spectrum in Fig. A.7.

    (j)LLa:l -20 ---. -...:.--- - -- ~ ------. '.-.. -.. -- ~ ---. -.. -: - . ------ ~ ---. --. -: ----. -. -~ ::::::

    __ J _,_ __ .1_ _ ' J _ '_ _ I

    I I

    ~ -40 --------: -- .. --:--------:.-.-----:--------:--------:-- .. ----:-- -- .. -? I~ ..: ~ : ~ : ; : .

  • APPENDIX A Spectral Estimation

    The first block of code synthesizes a 5th-order NTF, creates the binary L\~ data,estimates the quantizer gain and computes the actual NTF (see Eq. (4.17) onpage 100). The second block of code computes the scaled and windowed FFf, aswell as NBW. The last two code blocks compute the SNR and create the plotsshown in Fig. A.IO.

    The NTF is 5th-order, with zeros optimized for an oversampling ratio OSR = 32.The number of FFf points is set to N = 64 OSR = 2048, as advocated inSection A.I. Note that the half-scale input signal is placed precisely in an FFT bin(specifically, bin 11). Many practitioners use an odd FFT bin to ensure that theinput data contains no repeated segments, but this is not strictly necessary. In a

    % compute modulator output and actual NTFOSR = 32;ntfO = synthesIzeNTF(5,OSR,1);N = 64*OSR;fbin = 11;u = 1/2*sin(2*pI*fbin/N*[O:N-l]);[v tmpl tmp2 y] = slmulateDSM(u,ntfO);k = mean(abs(y)/mean(y.A2ntf = ntfO 1 (k + (l-k)*ntfO);% compute windowed FFT and NBWW = hann(N); % or ones(l,N) or hann(N) .A2nb = 3; % 1 for Rect; 5 for Hann A2wl = norm(w,l);w2 = norm(w,2);NBW = (w2/wl)A2V = fft(w.*v)/(wl/2);% Compute SNRsignal_bins = fbIn + [-(nb-l)/2: (nb-l)/2J;lnband_blns = O:N/(2*OSR);nOlse_blns = setdlff(inband_blns,signal_blns);snr = dbp( sum(abs(V(slgnal_bins+l .A2) / sum(abs(V(noise_bins+l .A2)% Make plotsfigure(l)i clfisemilogx([1:N/2]/N,dbv(V(2:N/2+1, 'b', 'Llnewldth' ,1);hold oni[f p] = logsmooth(V,fbin,2,nb);plot(f,p, Iml, 'Linewidth' ,1.5)Sq ~ 4/3 * evalTF(ntf,exp(21*Pl*f .~2;plot(f,dbp(Sq*NBW), 'k--', 'Llnewldth',l)f i gureMag1c ( [liN O. 5) , [J , [J, r-140 0], 10 , 2 ) ;

    Figure A.9: Example MATLAB code for performing spectral analysis.

    380

  • An Example

    Nyquist converter, it is wise to use an input which contains no repeated segmentsin order to exercise as many codes as possible, but in a ~I converter the internalstate of the converter typically ensures that the output data is not periodic.

    As indicated in the second code block, different windows can be tried. The Hannwindow is used here. The number of non-zero signal bins for the Hann window isnb = 3. NBW is calculated directly for the window, using an expression which willbe justified in the Section A.5. As indicated in Table I the result for the Hann win-dowisNBW = 1.51N = 7.3xIO-

    4. The last line of the second code block calcu-

    lates the FFT, and scales it by half the de gain of the window to perform sine-wavescaling.

    In the third code block, the SNR is calculated as the ratio of the total power in thesignal bins to the total power in the noise bins, and the result for this simulation isSNR = 81 dB. If a rectangular window were used instead, the poor high-fre-quency roll-off of the window would corrupt the in-band portion of the spectrum

    I. '"......................................................

    . . . . ,. .. , . . . . ... . . ............................................................................................................................................................... . ... ... . ... .... . . ... ...-20

    ~ , ., ,

    ~ .:_ ; .:.: . . - - - 0 _: 00 0 _: 00; _, _ _:_; ~ _: _ ____ 0 ~ _,( ~ _0; 0 0: _ ; _:_ ; ~ ~ __0 _0 . ; _0 _ ~ _ _; _, ,. '1'" I , , I

    41H( )21tf)12 0: 0- ~ -:-; :-;;.: - - - - -", o. ~ - : - .: - ~ -:- ; ~ -: - - - - - - ~ - - - ~ - - ; -e NBW'" .".. , I I. '" 3M2 -; 0": -:0: ;0:: 0: - . - . - ~: - - -: - 0 : - 0: - ~ -:- ; ~ -: - - - - - - ~ 0- - ~ 0 - ; -

    ~ .:. :~ ~ .... --~ --> ~ .-: -: -: :-: ~ ~ .. _. .~ - - - Theoretical spectrum -:.~: ::._.. -,;.:.-1.,.. ~ : :.: :;,~ .:. -- Hann-windowed FFT~-~.;.~..~-:':-- - ~o.~ -:.~-, .~,. - -~- -- Smoothed FFT.".,.. " . . . . .

    -120 ,- ; -: .: ------ ~ -0 - -; - 0 ~ - -;. ~ -;- ~, : - - - - : : : : : : : : :::I ",.

    ~ -t-; -, -, - - - - - - o.- - - -, - - : - -:": -:- :: -: 00 - - -: 00 - -:. -:. -: -: -:- : NBW=7.3x10~10-3 fa 10-1

    Normalized Frequency, f

    -140

    ..-...~m --40Z---......~ -60co'"C"-' -80oen0... -100

    Figure A.tO: Example PSDs produced by the code of Fig. A.9.

    381

  • APPENDIX A Spectral Estimation

    and yield a lower SNR. For this particular example, the shortfall was a disastrous23 dB.

    In the fourth and final code block, the raw and smoothed PSD estimates are com-pared graphically with the theoretical PSD. As expected, the raw FFT produces anerratic graph from which it would be difficult to tell if the observed PSD followsthe expected PSD or not. Smoothing is performed with the ~L Toolbox functionlogsrnooth. This function averages the power across a number of bins in order toreduce the variance of the PSD, and also subsamples the result to yield pointswhich are spaced fairly evenly on a logarithmic axis. This nearly-even spacing isachieved by using a number of bins which increases geometrically beyond a user-specified frequency (which defaults to the third harmonic of the input). See the"help" information associated with logsmooth for further details. With this func-tion, it is feasible to present the results of a multi-million point simulation withouthaving to plot millions of points in the spectrum. As Fig. A.IO shows, the agree-ment between the expected and observed PSDs is quite good. The justification ofthe formula used to calculate the expected PSD is also relegated to Section A.5.

    As a final demonstration, we will use the PSD plot of FIg. A.IO to manually esu-mate the SNR. The signal power is read directly from the graph: -6 dBFS. Thenoise power is computed by multiplying the noise density by the bandwidth, or inlogarithmic terms, by adding 101og(BW /_l:f.BW) to the noise density in d~. ForOSR = 32, BW = O.5/0SR = 1.6xlO ,and since NBW = 7.3x10 theconversion factor from average noise density to total noise power is10log (B W / NB W) = 13 dB . Since the average noise density in the passband is-IOOdBFS/NBW, theestimatedSNRis -6-(-100+ 13) = 81 dB.

    A.5 Mathematical Background

    Until now, the emphasis in this Appendix has been on using the FFf to performspectral estimation for the signals in a ~L modulator, while keeping the mathemat-ics to a minimum. The mathematical theory associated with spectral estimationinvolves a number of concepts from stochastic processes which are worthy ofchapters in themselves. We cannot do justice to such concepts in a subsection of an

    382

  • Mathematical Background

    Appendix, so we content ourselves to list the key results and to use these as justifi-cation for a number of formulae which appeared earlier in the Appendix withoutjustification. See [2] for background.

    The autocorrelation function of a discrete-time stationary random processt x isdefined as

    rx(k) = E[x(n)x(n + k)],

    where E[ ] denotes expectation ("average"). The Z-transform of rx is

    00

    (A.6)

    R (z) =x11 = -00

    and the PSD SxC!) of x is defined as

    r (n)z-nx (A.7)

    S .(f) = R (e J2nf).x x (A.8)

    In other words, the PSD is defined as the Fourier transform of the autocorrelationfunction. The link between this definition and the more intuitive definition thatSx(f) is amount of power between frequencies f and f + df divided by df isestablished by the following two properties of S x :

    1. ", = J~ S/f)df , where Px = E( Ix(n)1 2 ] is the power of x.

    2. If the output of a linear system having a transfer function H(z) is ywhen the input x, then Sif) = IH(e j 21t! )12 s / f) .

    The first property says that integrating the power spectrum over all frequenciesyields the power in the signal. The second says that filtering the signal multipliesits power spectrum by the squared magnitude of the filter's transfer function. The

    t A stationary random process IS a random process whosestatistical properties (mean, variance,etc.) do not vary with time.

    383

  • APPENDIXA Spectral Estimation

    intuitive definition of Sx(f) results from considering an ideal filter H having abandwidth df about a frequencyf

    Note that the first property required Sx to be integrated over the range [0, 11.Since real signals have symmetric spectra, it is common in practice to use therange [0, 0.51 and double the density

    P =J0.5 25 (f)dl.x 0 x (A.9)

    Since the range [0.5, 1J is equivalent to the range [-0.5, 0J, this convention issimilar to the conventional use of single-sidedspectral densities when dealing withcontinuous-time signals.

    Next, we consider the estimate of Sx (repeatedfrom (A.5

    (A.IO)Ibvll~

    N-l 2L w(n) x(n) e-j21tfn11=0Sx(f) =-------

    (We can obtain Sx(fi) for I, = ifN from a length-N FFf of x windowed by w.)

    The properties of this estimate arc

    1.Sw(f)

    E[Sx(f)] - S (f)*-- x Ilwll~'

    where Su,(f) = IW(f)12 and * denotes circular convolution.

    2. E[~l Si~N)] = r;1=0

    384

  • Mathematical Background

    3. Var[Sx(f)] "" [S/f)]2, where Varly] denotes the variance of a statis-

    tical quantity y.

    The first property states that Sif) is a biased estimator of SxCf), i.e. that theexpected value of Sx(f) is not equal to the true value of Sx(f) . For example, if arectangular window is used, then the expected value of the estimated PSD is equalto the actual PSD convolved with

    Sw(f) = 1.(Sin(N1Cf)2IlwilI N sin (nf)

    (A.]l)

    The second property effectively states that summing the values of Sx(!) con-~ l

    tained in the FFI', and dividing by N, (effectively, integrating Sx(fi) over [0, 1])yields an unbiased estimate of the power in x. This property justifies summing thepowers in the in-band bins of an FFT to produce an estimate of the in-band noisepower.

    The third property states that the PSD estimate is very "noisy," in that the standarddeviation of the estimate is as large as the quantity being estimated. This propertynecessitates the use of averaging, as discussed in Section A.3.

    We are now in the position to calculate the NBW of a sine-wave-scaled FFTemploying a window 1V. We assume that IW(f)1 has a peak at f = 0 and that thefull-scale range is [-1, 1] . The sine-wave-scaled PSD estimate is, from (A.3),

    N-l 2

    L w(n) . x(n) e-j2njnSx'(f) = .n__=_O

    W(O)/2

    Thus, Sx' is related to Sx (as given in Eq. (A.lO)) by

    (A.l2)

    385

  • APPENDIX A Spectral Estimation

    ~ Sx(f)lb vI1 22S '(f) =x fW(O)/2f2

    (A.I3)

    Since we want the integral of Sx'(f) to yield the power in x relative to the power ina full-scale sine wave, which is 0.5, we need to find the value of NBW whichmakes the following equation true

    E[fo.5Sx'(f) dfJ = px.o NBW 0.5

    Since EU~.5 2Sx(f)df J= Px 'Ilwlli

    NBW =-IW(O)1 2

    (A.14)

    (A.IS)

    This expression was used to tabulate NBW for the three windows in Table A.I. Ifwe assume that w(n) 2 0 , then 1W(o)1 = IIl-vlll and we arrive at the compact result

    (II \11"1 2)

    2

    NBW = "will (A.16)

    which was used in the code of Fig. A.9. Since the full-scale range affects both thedefinition of s.i and the reference power of 0.5 proportionally, NBW is inde-pendent of the full-scale range.

    The final formula which requires explanation is the formula for the expected PSDof the shaped quantization noise of a ~L modulator, which was also used In thecode of Fig. A.9. Since the power of quantization noise is ~2 /12, where ~ is thestep size, the power of the quantization noise for an M-step quantizer with a stepsize ~ = 2, relative to the power M2/2 of a full-scale sine wave is 2/(3M2).Assuming the quantization noise is white, its one-sided PSD is twice this amount,or 4/(3M2 ) . Thus the PSD of the shaped quantization noise is

    386

  • Mathematical Background

    (A.17)

    For consistency with a plot of Sx'(f), Sq(f) must be multiplied by NBW.

    387

  • APPENDIXA Spectral Estimation

    References

    [1] O. Brigham, The Fast Fourier Transform and Its Applications, Prentice-Hall, EnglewoodCliffs, New Jersey, 1988.

    [2] A. Papoulis, Probability, Random Variables and Stochastic Processes, McGraw-Hill, NewYork, NY, 1984.

    [3] A. V. Oppenheim and R. W. Schafer, Digital Signal Processing, Prentice-Hall, EnglewoodCliffs, New Jersey, 1989.

    [4] f. j. hanis, "On the use of windows for harmonic analysis with the discrete Fouriertransform," Proceedings ofthe IEEE, vol. 66, no. I, pp. 51-83, Jan. 1978.

    388