THE ANNUAL SYMPOSIUM OF THE INSTITUTE OF SOLID MECHANICS SISOM 22 BUCHAREST May 16-17 ---------------------------------------------------------------------------------------------------------------------------------------- FFT Spectrum Analyzer Authors: Eng. Mha Ncolae Newgate Desgn SRL Dr. Eng. Ioan Rugna Insttutute of Sold Mechancs; e-mal ncolaem@rol.ro; rugna@mecsol.ro Abstract The avalablty of low cost and powerful computers (such as IBM PC or compatble) has led to the development of economcal laboratory nstruments based around the PCs. Our am here s to combne the graphcs capablty of the IBM PC wth the hgh speed numercal processng power of the Texas Instruments TMS32C25 dgtal sgnal processor, to produce an economcal laboratory spectrum analyzer. The analyzer s requred to take an analogue nput, to dgtze and calculate ts spectrum usng FFT algorthm, and to dsplay the spectrum on the IBM PC montor. In future, t s ntended to develop the system further and use t as a general-purpose real-tme sgnal analyzer. 1. Introducton A conceptual block dagram of the spectrum analyzer s depcted n Fgure 1. The analyzer performs N-pont radx-2 FFTs on one of two nput data, calculates the power spectrum densty and transmts ths to the IBM PC through an RS232C lnk. A C language program on the PC receves and dsplays the spectrum. All the numercal computatons assocated wth spectrum estmatons are performed by the TMS32C25 processor. In the next few sectons, we wll descrbe the features of the analyzer, the spectrum estmaton technques used, and the analyzer hardware and software. 149
Analogue nput (ch1) Lowpass Flter ADC wth sample+ hold 12 N-pont FFT processor TMS32C25 Magntude squared Averagng To PC Analogue nput (ch2) Lowpass Flter ADC wth sample+ hold 12 Fg. 1. Conceptual block dagram of the FFT spectrum analyzer 2. Features of the Analyzer The FFT analyzer conssts of a TMS 32 C25-based board connected to an IBM PC or compatble, and a PC-resdent software package for dsplayng the sgnal spectrum. The man features of the analyzer are as follows: Dual analogue nput channels, each wth 12-bt ADC; Samplng rate per channel < 4kHz; Estmates power spectrum densty of sgnals n the frequency range -1 khz usng the FFT algorthm; Seral communcaton wth a host personal computer va an RS232 port; Dsplay of sgnal spectrum on a PC usng the host s graphcs facltes. Although not mplemented at the present, the analyzer can readly support multvarable analyss (for example cross-spectrum, cross-correlaton) and the dsplay of nput sgnals n tme. 3. Spectrum Estmaton n the Analyzer The spectrum analyzer uses radx-2 FFT algorthm to convert a tme doman data nto frequency. The FFT algorthm takes N data samples, x(n), n=,1,,n-1, and produces N-pont complex frequency samples, X(k), k=,1,,n-1. The raw power spectrum densty (PSD) s then obtaned as the scaled magntude squared of complex frequency samples: S(k) = (1/N) X(k) 2 = (1/N){Re[X(k) 2 ] + Im[X(k) 2 ]} k=,1,,n/2 (1) where N s a number of data ponts. 15
x(n) T 2 4 6 8 1 12 14 16 18 2 22 24 26 n (L-1) (2L-1) (3L-1) x1(n) x2(n) x3(n) x4(n) x5(n) x6(n) Fg. 2. An llustraton of sub sectonng of data wth 5% overlap and secton length, L=8. The PSD gves a measure of the dstrbuton of the average power of the sgnal over frequency. For random or nosy data, drect computaton of the power spectrum as n Equaton 1 may not yeld good spectrum estmates because of random errors. To obtan consstent estmates n the PSD some form of averagng s normally used at some stage n the estmaton process, for example correlaton or frequency averagng. In the analyzer, we employed a method due to Welch (1967). In the Welch method, the nput data sequence (x(n),n=,1,,n-1) whose spectrum s to be estmated s frst dvded nto K overlappng segments each of length L. For example, for a 5% overlap the data segments are (see Fgure 2) x (n) = x[n+l/2], n=,1,, L-1; =,1,,K-1 (2) The transform, X (k), and the raw power spectrum, S (k), of each data segment are then obtaned as L 1 n= X ( k) = w( n) x ( n) exp( j2π nk), k=,1,,l-1 (3) 151
1 S ( k) X ( k) LQ 2 =, k =,1,, L/2 (4) where w(n) are the values of a sutable wndow functon, for example the Hammng wndow, x (n) s the th data segment, and Q s the wndow energy defned as Q = 1 1 L N n= 2 w ( n) The average of the raw PSD estmates gves the desred smooth PSD estmate of the data sequence, x(n): K 1 K 1 1 1 2 S ( k) = S ( k) = X ( k), k=,1,2,,l/2 (6) K KLQ = = The values of X (k) n Equaton 3 are of course obtaned the FFT for effcency. To mprove the spectral clarty of S(k), the length, L, of each data segment may be extended, after wndowng, to say L+R by addng R zeros, and FFT of the zero padded sequences then obtaned. In the analyzer eght data segments were used. The segment length, L, was fxed at 128 data ponts (that s no zeros were added) and the overlap between segments was kept constant at half the segment length. The nput data sequence x(n) whose PSD s to be estmated s derved by samplng an analogue sgnal at a frequency, F s, consstent wth the samplng theorem F s >2f max ; F s =1/T, where T s the samplng nterval and f max the hghest frequency n the analogue sgnal. When we transform x(n) nto frequency as descrbed above, the frequency spacng, f, between the frequency components s gven by: f=1/lt (7) Ths s the effectve resoluton of the FFT. For the analyzer, L=128, and the maxmum samplng frequency, F s = 4 khz, gvng a resoluton < 312.5 Hz. (5) 4. Analyzer Hardware The block dagram of the system hardware s shown n Fgure 3. Ant-alasng flterng at the nput s achved usng a second-order Butterworth flter for smplcty. Usng ths low-order ant-alasng flter means that the samplng frequency should be suffcently hgh to keep the effects of alasng low. 152
Wat states and address decodng Program Program Data 8kx16 EPROM 8kx16 RAM 8kx16 RAM Seral port UART C25 ADC Antalasng buffer Gan control buffer A-A15 D-D15 Analogue nput Fg. 3. PC-based FFT spectrum analyzer hardware The program memory stores the FFT twddle factors, precomputed sne and cosne values, as well as the wndow coeffcents, w(n), n Equaton 3. The nput data samples, x(n), are stored frst n the external data memory, and each block of data to be transferred to the nternal memory and stored n a complex format (that s, as real and magnary); see the map for data storage n Fgure 4. The FFT s performed n place. The spectrum analyzer board passes the spectrum estmates to the IBM PC for dsplay through the seral port. The TMS32C25 target board meets all the analyzer hardware specfcatons and so was used to mplement the analyzer. 5. Analyzer Software The analyzer software conssts of a set of TMS32C25 assembly language programs for computng the PSD values and transferrng these to the PC, and a C language program resdent on the PC for dsplayng the power spectrum. 5.1 TMS32C25 programs The TMS32C25 programs carry out the followng operatons. 1. Collect N data ponts, x(n), from the ADC (at present, N=576) and save n the external data RAM. 2. Dvde the N data ponts nto eght overlappng segments, 128 data ponts each (Equaton 2) 3. For each data segment perform the followng operatons: Wndow the data usng a Hammng wndow x (n) = x (n)w(n), n=,1,,127 153
Transfer the wndowed data nto the nternal RAM block B1, and store as real and magnary; Perform a 128-pont, n-place FFT on the data segment; Compute the raw PSD (Equaton 4); Save raw PSD n external RAM. 4. Average the raw PSD for all segments (Equaton 6) 5. Transfer averaged PSD to the PC. B 512 x() x(1) x(2) x(3) B1 768 x() x(1) x(126) x(127) 639 x(127) 123 Real Complex Temporary data data storage Fg. 4. On-chp data storage for the analyzer The TMS32C25 code, wrtten for the Texas Instruments assembler, conssts of a man program, four subroutnes, and an nterrupt servce routne as follows: man routne, PSD ntalzaton, nterrupt servce routne, data collecton, PSD estmaton, data transfer. Some of the programs are descrbed brefly below. PSD ntalzaton The PSD ntalzaton routne supplements the system ntalzaton n the boot program. It s major role s to prepare the hardware for PSD computatons. It performs the followng operatons: confgure on-chp memory block B as RAM, ntalze nternal data memores blocks B, B1, and B2 wth zero, program the tmer for the correct samplng frequency, unmask tmer nterrupt, enable the tmer nterrupt. Programmng the tmer nvolves loadng the 16-bt perod regster (PRD), data memory locaton 3, wth an approprate value to set up the samplng frequency: F s =F clk /N, where F s s the samplng frequency, F clk s the TMS32C25 CLKOUT frequency, whch s 1MHz, and N s a 16-bt unsgned nteger loaded nto the PRD regster. To generate a 4 khz samplng frequency, the PRD s loaded wth 25. 154
Data collecton After PSD ntalzaton, the processor branches to the data collecton subroutne where t goes nto the dle state and wats untl the tmer nterrupt occurs. On nterrupt, the processor jumps to the nterrupt servce routne and ssues a start of converson (SOC) command to the ADC s by togglng the external flag, XF. The processor then returns to the data collecton subroutne and wats for the end of the converson (EOC) sgnal from the ADC s by testng for the BIO lne to go low. When the EOC s receved the data s read from the 12-bt ADC and stored n the external data RAM n Q15 format by left shftng the data four places before t s stored n external data memory (only the channel 1 ADC s used for the PSD estmaton). The processor returns to the man routne when 576 consecutve data samples have been collected. Power spectrum densty estmaton The FFT s the heart of the PSD estmaton. It s a radx-2, 128-pont, decmaton n frequency (DIF) algorthm based on the mplementaton n Texas Instruments (1986). For each data segment, the PSD routne ntalzes memory blocks B and B1 wth zero and then moves the data from the external memory to the nternal memory block B. The data s wndowed by multplyng each data sample by an approprate wndow coeffcent and then transferred to the on-chp memory, block B1, where t s strored n a complex form. The real data samples are stored n even addresses, startng at address 768. The odd address locatons, whch contan zeros, represent the magnary parts; see Fgure 4. The complex data s then FFTed, n place, and ts raw PSD computed. The raw PSDs for the segments are then averaged to obtan a smooth PSD. Data transfer The averaged PSD s transferred to the PC, va the seral nterface, wth each averaged PSD value represented as 2 bytes. 5.2 IBM PC dsplay software The smple C language program on the PC reads the averaged PSD values from the analyzer hardware and dsplays t on the screen. When the program s frst executed a menu s dsplayed requestng the user to select an opton: 1 - dsplay power spectrum densty; 2 - save and dsplay PSD; 3 - read PSD from dsk and dsplay; 4 - zoom; 5 ext. If opton 1 or 2 s selected, control s passed to the man program n the analyzer, whch computes the PSD and transfers t to the PC as descrbed above. For opton1, the PSD s dsplayed. For opton 2, the PSD values are frst saved on the dsk n a user-specfed fle, 155
before the PSD s dsplayed. For opton3, the C program frst reads the PSD from dsk and then dsplays t. For opton 4, the user s asked to specfy the frequency range of nterest, and the selected regon of the current dsplay s then expanded accordngly. Selectng opton 5 returns the user to the operatng system. 6. Usng the Analyzer Fgures 5.a and 5.b show examples of the PSD of, respectvely, 1 khz square wave and a 2 khz sne wave. At present the analyzer s used only for power estmaton. It can be extended to perform other sgnal analyss or used n other applcatons, for example frequency response estmaton, auto- and cross spectral analyss of nosy or random sgnals, convoluton or correlaton n the frequency doman, cross-spectral densty, magntude coherence and tme doman dsplay. The data from the analyzer hardware may also be sent to the PC n varous forms for further processng and/or dsplay, for example as : raw data, real and magnary, and magntude and phase. Magntude 21 189 168 147 126 15 15 84 63 42 21 (a) 1 2 3 4 5 6 7 8 91 11 khz Magntude 21 189 168 147 126 15 15 84 63 42 21 (b) 1 2 3 4 5 6 7 8 91 11 khz Fg. 5. (a) Frequency spectrum for 1 khz square wave sgnal. (b) Frequency spectrum for a 2kHz sne wave sgnal References 1. The Scentst and Engneer's Gude to Dgtal Sgnal Processng - Steven W. Smth 2. Dgtal Sgnal Processng A practcal Approach Emmanuel C. Ifeachor Addson- Wesley 156