Analysis of Signal Resolution of A/D Converters in Digital Meter Applications

advertisement
Analysis of Signal Resolution of A/D Converters in
Digital Meter Applications
Samuel Kim
Numerical Analysis for Engineering Project
Professor Ernesto Gutierrez-Miravete
April 10, 2001
Table of Contents
SECTION
PAGE NO.
1. List of Symbols
-
-
-
-
-
-
-
3
2. Abstract
-
-
-
-
-
-
-
4
-
-
-
-
-
-
-
4
-
-
-
-
-
5
3. Introduction
-
4. Problem Description and Formulation
4.1. Signal Background -
-
-
-
-
-
-
5
4.2. Mathematical Formulation
-
-
-
-
-
-
5
4.3. A/D Converter Background -
-
-
-
-
-
6
4.4. Mathematical Formulation (Continued)
-
-
-
-
7
5. Numerical Approach
-
5.1. Fast Fourier Transforms
-
-
-
-
-
-
8
-
-
-
-
-
-
8
-
-
-
9
6. Results and Discussion (Error Analysis / Validation)
6.1. Error Analysis / Validation
7. Conclusion
-
-
-
-
-
-
11
-
-
-
-
-
-
-
-
12
8. Bibliography -
-
-
-
-
-
-
-
13
9. Appendix
-
-
-
-
-
-
-
14
-
2
1. List of Symbols
xa(t)
Voltage, analog signal as a function of time [volts]
A
Amplitude [volts]

Frequency [radians/sec]
t
Time [seconds]

Phase shift [radians]
F
Frequency [Hertz]
x(n)
Voltage, discrete time sinusoidal signal [volts]

Frequency [radians/sample]
n
Sample number or index
f
Frequency [cycles/sample]
xq(n)
Voltage, quantized signal [volts]
xa(nT)
Voltage, discrete time signal [volts]
Fs
Sampling frequency [radians/sec]
T
Sampling period [second]

Quantizer resolution
eq(n)
Quantization error
L
Quantization level
b
Number of bits
xmax
Maximum input range [volts]
xmin
Minimum input range [volts]
3
2. Abstract
This report will be a technical write-up analyzing the sensitivity and accuracy in numerical computations
involved in digital systems, specifically for applications in digital electricity meters. The paper will first
give general background on digital systems and the classifications of the different types of signals in a
system. There will be a discussion on scalar versus multichannel signals, singledimensional versus
multidimensional signals, deterministic versus random signals, and continuous time, continuous valued
signals versus discrete time, discrete valued signals. The paper will continue with a discussion on specific
components of the digital electricity meter, focusing on the Analog to Digital Converter in the system. The
approximation theory of the Fast Fourier Transform Method will be discussed and applied to this
application.
3. Introduction
Many of the products that surround us are becoming increasingly digital. Examples of digital systems
today include compact disk players and clearer cellular phones with digital technology, and some day
digital televisions. In the electrical distribution and control industry, more and more digital systems are
incorporated into its products, including digital meters, protective relays, and electronic trip units for circuit
breakers. There are advantages and disadvantages in these systems, and the understanding of these
processes for specifying and designing systems with appropriate performance at minimum cost are very
important. Some of the primary advantages of digital systems in signal processing are high performance,
robust design, adaptivity, and small size and low power requirements. The performance of a digital system
is not susceptible to the effects of environment, humidity, temperature, etc., aging, and wear as an analog
system is prone to be. Digital systems can be designed to provide flexibility through modification of
software rather than modification of analog hardware. They may also be designed to allow user input to
optimize performance. The disadvantages are speed limitations and finite word lengths. Systems are quite
costly to design for extremely high speed ranges, or may not be available at all. This is a primary reason
behind the lag of digital television compared to digital audio. Digital TV currently requires extremely fast
and expensive digital systems to process the high bandwidth image signal, where digital audio requires
relatively slower digital systems designs. To achieve very high accuracy for critical signal processing
systems, the quantization process must have extremely fine resolution. This again drives up the cost of a
digital system or may make such a system unrealizable. In these extremely high speed / high accuracy
applications and in the markets where traditional signal processing methods may be considered safer or
more reliable than digital systems, analog systems are still the industrial standard, but improving
technology is overcoming more and more of these obstacles. Digital systems in the application of
electricity meters shall be the focus of this paper. The signal in question for the digital electricity meter is
voltage [volts] with respect to time.
4
4. Problem Description and Formulation
4.1. Signal Background
There are several common classifications of signals. The signal in question, voltage, may be considered a
scalar signal, which can be described at any time by a single number, complex or real. Voltage measured
in a residential outlet may also be considered a multidimensional signal since the signal may be a function
of time and load. The signal is also deterministic, as opposed to random, because voltage can be uniquely
described by an explicit mathematical expression. Yet another classification of signals is continuous time
signals or analog signals. Voltage is defined at every interval of time within a continuous time interval.
Voltage can also be classified as a discrete valued signal when it is defined at integer values of n over a
finite or infinite range. The actual time between each defined value of the discrete time signal is generally
a constant and is defined as the period. A discrete time signal arises in the situation of sampling of a
continuous time signal at discrete time moments. A digital measurement device will take a reading of a
continuous time signal, called a sample. Another term for discrete time signal is digital signal. The process
of converting a continuous or analog signal to a digital signal is called quantization. It involves rounding or
truncating the continuous valued signal to an allowable value. Another obviously important signal
classification is the sinusoidal signal. Sinusoidal signals are used to transmit energy in power distribution
systems.
4.2. Mathematical Formulation
For simplicity, voltage can be described mathematically as a perfectly sinusoidal continuous time signal
represented by,
x a (t )  A cos(t   ),
where A is the amplitude (in volts),  is the frequency (in radians/sec) and  is the phase shift (in radians).
Frequency is rarely discussed in radians per second, but rather in Hertz, and since
  2F
where F is frequency in terms of Hertz. The equation above becomes,
x a (t )  A cos( 2Ft   )
Furthermore, discrete time sinusoidal signals are represented with an expression similar to the continuous
time sinusoidal signal,
5
x(n)  A cos(n   )
where n is an integer variable called the sample number or index, and  is frequency (in radians/sample).
All references to time are now replaced by references to samples. The frequency variable, f (units
cycles/samples, not Hz) can be defined as,
  2f
4.3. A/D Converter Background
To process an analog signal by digital means, it is first necessary to convert the analog signal into digital
form. This process is commonly called analog to digital conversion or A/D conversion. As discussed
above, a digital signal is defined only at discrete points in time (equally spaced in general) with numbers
having finite precision. In order to perform A/D conversion, one can conceptually use the following three
step process. See Figure 1.
Analog to Digital Converter
xa(t)
x(n)
Sampler
Analog Signal
xq(n)
Coder
Quantizer
DiscreteTime Signal
10110
Quantized
Signal
Digital Signal
Figure 1
First, the Sampler converts the continuous time signal, xa(t), into a discrete time signal, x(n). Then the
Quantizer converts the discrete time signal into a discrete valued signal, xq(n). And finally, the coder
converts the quantized value into a B-bit binary sequence, usually called a byte or word. This is the digital
signal. The number of bits B-bit binary sequence is directly related to the resolution of the quantizer and
thus the accuracy of the digital signal.
In general, an A/D converter will exhibit superior performance as the sampling frequency increases and the
quantizer resolution becomes finer. The tradeoff for this increased performance is cost. The key to
6
designing an A/D system is to determine the performance requirements and then to design the minimum
cost system meeting these requirements. For example, the digital signal on a compact disk is recorded at a
44.1 kHz sampling rate. There would be no noticeable improvement of the sound quality of compact disks
if they were recorded at 10 times this sampling rate, but the cost of a compact disk player would be
significantly higher.
4.4. Mathematical Formulation (Continued)
In the discussions of sampling, an assumption will be made of uniform sampling, or sampling with a
constant time period between successive samples of an analog signal (voltage in our case). This leads to
the following relation,
x(n)  x a (nT )
where x(n) is the discrete time signal (not yet the digital signal since x(n) is still a continuous valued signal)
and T is the constant sampling period. The discrete time signal is obtained by taking samples of the analog
input signal at times t=T, t=2T, t=3T, and so on. The sampling frequency is defined by
Fs 
1
T
Therefore,
t  nT 
n
Fs
We can use this to develop the important relationship between discrete time and continuous time frequency
variables. We can now analyze a typical voltage sinusoidal signal, expressed mathematically as,
x a (t )  A cos(2Ft   )
and uniformly sampled with period T (and sampling frequency F s), yielding
x a (nT )  x(n)  A cos( 2FnT   )
 A cos( 2F
n
)
Fs
 A cos( 2fn   )
7
One can note that the quantization error, eq(n), is bounded for a rounding quantizer by the following
relation



 e q ( n) 
2
2
and for a truncating quantizer by
0  e q ( n)  
where  is the resolution of the quantizer. Quantizer resolution is determined in real world systems by the
number of bits available to represent the sample. Common A/D systems use 8, 12, 14, and 16 bit word
lengths to represent samples. The number of discrete quantization levels is determined by the relation
L  2b
where b is the number of bits used to quantize a sample (thus an 8 bit system will have 256 discrete
quantization levels). These systems will have a specified input range of x min and xmax from which the
quantizer resolution can be determined by the relation

x max  x min
L 1
The quantization error is also commonly called the quantization noise and is used to describe the quality of
the quantization process.
5. Numerical Approach
5.1. Fast Fourier Transforms
In the topic of approximation theory, the Fast Fourier Transform has served as a bridge between the time
domain and the frequency domain. It is possible to go back and forth between waveform and spectrum
with enough speed and economy to create a whole new range of applications in digital processing. This
computational tool to facilitate signal analysis was developed by Cooley and Tukey and is known as the
Cooley-Tukey algorithm or the fast Fourier transform (FFT) algorithm.
8
The interpolatory trigonometric polynomial is described as
S m ( x) 
a0  am cos mx m1
  ak cos kx  bk sin kx)
2
k 1
where
ak 
1 2 m1
 y j cos kx j
m j 0
for each k = 0, 1, … , m
and
bk 
1 2 m1
 y j sin kx j
m j 0
for each k = 1, 2, … , m-1.
6. Results and Discussion
Values of ak and bk can be calculated per the FORTRAN code, algorithm 8.3 in the Burden/Faires text. The
complete FORTRAN code is in the appendix. The function in question, voltage in meter application, is as
follows,
x a (t )  cos(120t )
which is a typical mathematical description of a single phase 60 Hz voltage signal, assuming unity
amplitude.
The following are tables of the calculated ak and bk values which in turn are used to formulate Sm(x).
For m=4
k
ak
bk
0 1.70E-02 0.00E+00
1 9.96E-01 7.42E-06
2 -6.89E-03 1.10E-05
3 3.45E-03 -2.30E-05
9
4 -2.82E-03 9.87E-10
5 3.45E-03 2.30E-05
6 -6.89E-03 -1.10E-05
7 9.96E-01 -8.82E-06
For m=16
k
"
ak
bk
0 -2.12E-03 0.00E+00
1 2.18E-03 1.53E-05
2 -2.35E-03 3.06E-06
3 2.68E-03 -4.06E-06
4 -3.32E-03 -7.39E-06
"
"
25 1.00E+00 -5.68E-06
26 -9.04E-03 -3.21E-06
27 4.74E-03 2.43E-06
28 -3.32E-03 7.41E-06
29 2.68E-03 3.95E-06
30 -2.35E-03 -3.06E-06
31 2.18E-03 -1.54E-05
For m=256
k
ak
bk
0 -9.85E-05 0.00E+00
1 9.95E-05 -5.53E-08
2 -9.79E-05 3.29E-07
3 9.93E-05 -3.12E-07
4 -1.01E-04 6.66E-07
"
"
"
502 -1.00E-04 4.50E-07
503 1.02E-04 5.45E-07
504 -1.01E-04 -2.17E-06
505 9.87E-05 -3.09E-07
506 -1.03E-04 1.04E-06
507 1.00E-04 -3.37E-09
508 -1.01E-04 -6.63E-07
509 9.93E-05 3.26E-07
510 -9.79E-05 -3.26E-07
511 9.94E-05 9.40E-08
Excel was used to formulate values of Sm(x) and compared to xa(t). The errors, |xa(t) – sm(x)|, were
calculated per each m = 4, 16, and 256.
t
xa(t)
0
1
s4(x)
Error
s16(x)
error
s256(x)
error
0.9756 2.44E-02 1.00E+00 7.94E-04 1.00E+00 1.38E-07
10
0.001
0.002
0.003
0.004
0.005
0.006
0.007
0.008
0.009
0.01
0.011
0.012
0.013
0.014
0.015
0.016
0.929776
0.728969
0.425779
0.062791
-0.30902
-0.63742
-0.87631
-0.99211
-0.96858
-0.80902
-0.53583
-0.18738
0.187381
0.535827
0.809017
0.968583
0.935536
0.732249
0.429109
0.060671
-0.30668
-0.63228
-0.85361
-0.99539
-0.97191
-0.8069
-0.53349
-0.19252
0.210081
0.530207
0.817487
0.943763
error avg.
5.76E-03
3.28E-03
3.33E-03
2.12E-03
2.34E-03
5.14E-03
2.27E-02
3.28E-03
3.33E-03
2.12E-03
2.34E-03
5.14E-03
2.27E-02
5.62E-03
8.47E-03
2.48E-02
8.64E-03
9.30E-01
7.29E-01
4.26E-01
6.28E-02
-3.09E-01
-6.37E-01
-8.76E-01
-9.92E-01
-9.69E-01
-8.09E-01
-5.36E-01
-1.87E-01
1.88E-01
5.36E-01
8.09E-01
9.68E-01
2.38E-04
1.74E-04
3.18E-05
5.79E-06
1.97E-04
7.33E-04
5.11E-04
1.74E-04
3.18E-05
1.17E-04
7.37E-05
4.62E-04
4.49E-04
7.50E-05
4.30E-04
5.63E-04
2.98E-04
9.30E-01 7.58E-09
7.29E-01 1.01E-09
4.26E-01 6.27E-09
6.28E-02 4.24E-09
-3.09E-01 1.01E-07
-6.37E-01 1.27E-07
-8.76E-01 1.63E-08
-9.92E-01 2.04E-08
-9.69E-01 2.35E-09
-8.09E-01 5.42E-08
-5.36E-01 3.31E-08
-1.87E-01 3.47E-08
1.87E-01 1.93E-07
5.36E-01 4.22E-08
8.09E-01 6.37E-08
9.69E-01 0.00E+00
4.97E-08
6.1. Error Analysis / Validation
The average error decreases for greater m values. The value m=256 results in the most accuracy
calculation of an average error of 4.97x10 -8. The errors calculated from the fast Fourier transform method
can be compared to the calculations of quantization of the voltage signal in meter application.
For a given single phase 60 Hz voltage signal equation
x a (t )  cos(120t )
the following assumption can be made:
Metering typically has a sampling frequency of Fs = 480 Hz. Therefore,
T
1
1

Fs 480 Hz
and
x a (nT )  x(n)  cos(120nT )  cos
120n
n
 cos
Fs
4
where n = 0, 1, 2, … , 999.
11
The x(n) signal was calculated and plotted on excel. Xq(n) was calculated using the M-Round function of
MS Excel. Furthermore, eq(n) was calculated, assuming the following,
xmax = 1
xmin = -1
b = 4, 8, 12, 16
L = 2b
 = xmax – xmin / L-1
The following is a table of the results.
xmin
xmax
b
L
delta
-1
1
4
16
0.13333
-1
1
8
256
0.00784
-1
1
12
4096
0.00049
-1
1
16
65536
0.00003
Finally, the error eq(n) was calculated using the following equation,
e q ( n)  x q ( n)  x ( n)
The following is a table of the errors for b = 4, 8, 12, 16 with its respective number of levels of
quantization, L = 16, 256, 4096, 65536
n
x(n)
x4(n)
x8(n)
x12(n)
0 1.00000 1.00000 1.00000 1.00000
1 0.70711 0.73333 0.70980 0.70696
2 0.00000 0.06667 0.00392 0.00024
3 -0.70711 -0.73333 -0.70980 -0.70696
4 -1.00000 -1.00000 -1.00000 -1.00000
5 -0.70711 -0.73333 -0.70980 -0.70696
6 0.00000 -0.06667 -0.00392 -0.00024
7 0.70711 0.73333 0.70980 0.70696
8 1.00000 1.00000 1.00000 1.00000
x16(n)
1.00000
0.70712
0.00002
-0.70712
-1.00000
-0.70712
-0.00002
0.70712
1.00000
error avg
e4(n)
0.00000
0.02623
0.06667
0.02623
0.00000
0.02623
0.06667
0.02623
0.00000
0.02647
e8(n)
0.00000
0.00270
0.00392
0.00270
0.00000
0.00270
0.00392
0.00270
0.00000
0.00207
e12(n)
0.00000
0.00015
0.00024
0.00015
0.00000
0.00015
0.00024
0.00015
0.00000
0.00012
e16(n)
0.00000
0.00001
0.00002
0.00001
0.00000
0.00001
0.00002
0.00001
0.00000
0.00001
The higher the level of quantization, the more accurate the calculation. A 16 bit quantization gives an
average error of 0.00001. These calculations correlates to the calculations of the fast Fourier transform
method.
7. Conclusion
12
The numerical analysis of metering and specifically on the analog input of voltage shows that using the
computational tool of fast Fourier transform gives an accuracy that is many factors better than the accuracy
level in the industry today. A typical meter A/D converter has a quantization resolution of about 16 bits
(256 samples or levels) or an average accuracy of about 1x10 -5. Comparably, m=256 in the fast Fourier
transform algorithm gives an error of about 5x10 -8. There are advantages and disadvantages in attaining
these accuracies and understanding these processes for specifying and designing systems with appropriate
performance at minimum cost is the tradeoff.
8. Bibliography
Burden, R., and Faires, J.D., Numerical Analysis, Sixth Edition, Brooks/Cole Publishing Company, 1997.
Johnson, D., Hilburn, J., and Johnson, J., Basic Electric Circuit Analysis, 3rd Ed., Prentice Hall, 1986.
Lathi, B.P., Signals, Systems and Communication, John Wiley & Sons, Inc., 1965.
Proakis, J., and Manolakis, D., Digital Signal Processing, Macmillan, 1992.
Rabiner, L., and Rader, C., Digital Signal Processing, IEEE Press, 1972.
Stevenson, W., Elements of Power System Analysis, 3rd Ed., McGraw Hill.
Taub, H. and Schilling, D., Digital Integrated Electronics, McGraw Hill, 1977.
13
9. Appendix
Below is the complete FORTRAN code for Algorithm 8.3, Fast Fourier Transform Method.
C***********************************************************************
C
*
C
FAST FOURIER TRANSFORM ALGORITHM 8.3
*
C
*
C***********************************************************************
C
C
C
C TO COMPUTE THE COEFFICEINTS IN THE DISCRETE APPROXIMATION
C F(X) FOR THE DATA (X(J),Y(J)), 0<=J<=2M-1 WHERE M=2**P AND
C X(J) = -PI + J*PI/M FOR 0 <= J <= 2M-1.
C
C INPUT: M; Y(0),Y(1),...,Y(2M-1).
C
C OUTPUT: COMPLEX NUMBERS C(0),...,C(2M-1); REAL NUMBERS
C
A(0), ..., A(M); B(1), ..., B(M-1)
C NOTE: THE MULTIPLICATION BY EXP(-K*PI*I) IS DONE WITHIN THE
C
THE PROGRAM.
C
COMPLEX C(1000), W(1000), WW, T1, T3
REAL Y(1000)
real aaa(1000),bbb(1000)
CHARACTER NAME*30,NAME1*30,AA*1
INTEGER INP,OUP,FLAG
LOGICAL OK
C Change F if the program is to calculate Y
c
F(V) = ((V-3)*V+2)*V*V-SIN(V*(V-2))/COS(V*(V-2))
c
F(V) = V*COS(V*V) + (EXP(V))*COS(EXP(V))
F(V) = COS(120*PI*V)
PI = 4.0*ATAN(1.0)
c
OPEN(UNIT=5,FILE='CON',ACCESS='SEQUENTIAL')
c
OPEN(UNIT=6,FILE='CON',ACCESS='SEQUENTIAL')
WRITE(6,*) 'This is the Fast Fourier Transform.'
WRITE(6,*) ' '
WRITE(6,*) 'The user must make provisions if the'
WRITE(6,*) 'interval is not [-pi,pi].'
WRITE(6,*) 'The example illustrates the required'
WRITE(6,*) 'provisions under input method 3.'
OK = .FALSE.
11 IF ( .NOT. OK) THEN
WRITE(6,*) 'Choice of input method: '
WRITE(6,*) '1. Input entry by entry from keyboard '
WRITE(6,*) '2. Input data from a text file '
WRITE(6,*) '3. Generate data using a function F'
WRITE(6,*) 'Choose 1, 2, or 3 please '
WRITE(6,*) ' '
READ(5,*) FLAG
IF( ( FLAG .GE. 1 ) .AND. ( FLAG .LE. 3 )) OK = .TRUE.
14
GOTO 11
ENDIF
IF (FLAG .EQ. 1) THEN
OK = .FALSE.
21
IF (.NOT. OK ) THEN
WRITE(6,*) 'Input number m '
WRITE(6,*) ' '
READ(5,*) M
IF (M .GT. 0 ) THEN
OK = .TRUE.
N=2*M
DO 31 I = 1, N
J=I-1
WRITE(6,*) 'Input Y(',J,') '
WRITE(6,*) ' '
READ(5,*) Y(I)
31
CONTINUE
ELSE
WRITE(6,*) 'Number must be a positive integer '
ENDIF
GOTO 21
ENDIF
ENDIF
IF (FLAG .EQ. 2) THEN
WRITE(6,*) 'Has a text file been created with the data'
WRITE(6,*) 'y(0), ..., y(2m-1) separated by blanks? '
WRITE(6,*) 'Enter Y or N - letter within quotes '
WRITE(6,*) ' '
READ(5,*) AA
IF (( AA .EQ. 'Y' ) .OR.( AA .EQ. 'y' )) THEN
WRITE(6,*) 'Input the file name in the form - '
WRITE(6,*) 'drive:name.ext contained in quotes'
WRITE(6,*) 'as example: ''A:DATA.DTA'' '
WRITE(6,*) ' '
READ(5,*) NAME
INP = 4
OPEN(UNIT=INP,FILE=NAME,ACCESS='SEQUENTIAL')
OK = .FALSE.
41
IF (.NOT. OK) THEN
WRITE(6,*) 'Input number m '
WRITE(6,*) ' '
READ(5,*) M
IF ( M .GT. 0) THEN
OK = .TRUE.
N=2*M
READ(4,*) (Y(I),I=1,N)
CLOSE(UNIT=4)
ELSE
WRITE(6,*) 'Number must be a positive integer '
ENDIF
GOTO 41
ENDIF
ELSE
WRITE(6,*) 'The program will end so the input file can '
WRITE(6,*) 'be created. '
OK = .FALSE.
15
ENDIF
ENDIF
IF (FLAG .EQ. 3) THEN
WRITE(6,*) 'Has the function F been created in the program '
WRITE(6,*) 'Enter Y or N - letter within quotes'
WRITE(6,*) ' '
READ(5,*) AA
IF (( AA .EQ. 'Y' ) .OR. ( AA .EQ. 'y' )) THEN
OK = .FALSE.
61
IF (.NOT. OK) THEN
WRITE(6,*) 'Input number m '
WRITE(6,*) ' '
READ(5,*) M
IF ( M .GT. 0 ) THEN
OK = .TRUE.
N=2*M
DO 71 I = 1, N
c
XX=(I-1.0)/M
c
Z = PI*(XX-1)
c
Y(I) = F(1+Z/PI)
XX=-PI+(I-1.0)*PI/M
Z = XX
Y(I) = F(Z)
71
CONTINUE
ELSE
WRITE(6,*) 'Number must be a positive integer '
ENDIF
GOTO 61
ENDIF
ELSE
WRITE(6,*) 'The program will end so that the function F '
WRITE(6,*) 'can be created '
OK = .FALSE.
ENDIF
ENDIF
IF (.NOT. OK) GOTO 500
WRITE(6,*) 'Select output destinations: '
WRITE(6,*) '1. Screen '
WRITE(6,*) '2. Text file '
WRITE(6,*) 'Enter 1 or 2 '
WRITE(6,*) ' '
READ(5,*) FLAG
IF ( FLAG .EQ. 2 ) THEN
WRITE(6,*) 'Input the file name in the form - '
WRITE(6,*) 'drive:name.ext'
WRITE(6,*) 'with the name contained within quotes'
WRITE(6,*) 'as example: ''A:OUTPUT.DTA'' '
WRITE(6,*) ' '
READ(5,*) NAME1
OUP = 3
OPEN(UNIT=OUP,FILE=NAME1,STATUS='NEW')
ELSE
OUP = 6
ENDIF
WRITE(OUP,*) 'FAST FOURIER TRANSFORM'
C STEP 1
16
C
USE N2 FOR M, NG FOR P, NU1 FOR Q, WW FOR ZETA
N2 = N/2
NG = ALOG(FLOAT(N))/ALOG(FLOAT(2)) + .5
NU1 = NG - 1
WW = CEXP ( CMPLX( 0.0 , 2*PI/N))
C STEP 2
C SUBSCRIPTS ARE SHIFTED TO AVOID ZERO SUBSCRIPTS
DO 50 I=1,N
50
C(I) = CMPLX( Y(I), 0.0)
C STEP 3
DO 40 I=1,N2
W(I)=WW**I
40
W(N2+I)=-W(I)
C STEP 4
K=0
C STEP 5
DO 20 L=1,NG
C
STEP 6
100
IF (K .GE. N-1) GOTO 200
C
STEP 7
DO 30 I=1,N2
C
STEP 8
M1=K/2**NU1
C
THE SUBPROGRAM IBR DOES THE BIT REVERSAL
NP=IBR(M1,NG)
C
T1 IS THE SAME AS ETA
T1=C(K+N2+1)
C
STEP 9
IF(NP.NE.0) T1=T1*W(NP)
C(K+N2+1)=C(K+1)-T1
C(K+1)=C(K+1)+T1
C
STEP 10
30
K=K+1
C
STEP 11
K=K+N2
GOTO 100
C
STEP 12
200
K=0
N2=N2/2
20
NU1=NU1-1
C STEP 13
300 IF (K .GE. N-1) GOTO 400
C
STEP 14
I=IBR(K,NG)
C
STEP 15
IF(I.GT.K) THEN
T3=C(K+1)
C(K+1)=C(I+1)
C(I+1)=T3
END IF
C
STEP 16
K=K+1
GOTO 300
C STEP 17 AND 18
400 DO 60 I=1,N
C(I)=CEXP(CMPLX(0.0,-(I-1)*PI))*C(I)/(FLOAT(N)/2)
17
60
WRITE(OUP,2) I-1,C(I)
500 CLOSE(UNIT=5)
CLOSE(UNIT=OUP)
IF(OUP.NE.6) CLOSE(UNIT=6)
2
STOP
FORMAT(1X,I4,2(2X,E15.8))
END
C
70
FUNCTION IBR(J,NU)
J1=J
K=0
DO 70 I=1,NU
J2=J1/2
K=K*2+(J1-2*J2)
J1=J2
IBR=K
RETURN
END
Below is the FORTRAN output of Algorithm 8.3.
This is the Fast Fourier Transform.
The user must make provisions if the
interval is not [-pi,pi].
The example illustrates the required
provisions under input method 3.
Choice of input method:
1. Input entry by entry from keyboard
2. Input data from a text file
3. Generate data using a function F
Choose 1, 2, or 3 please
3
Has the function F been created in the program
Enter Y or N - letter within quotes
y
Input number m
4
Select output destinations:
1. Screen
2. Text file
Enter 1 or 2
1
FAST FOURIER TRANSFORM
0 0.16992625E-01 0.00000000E+00
1 0.99635613E+00 0.74152667E-05
18
2
3
4
5
6
7
-0.68906364E-02 0.11013162E-04
0.34494102E-02 -0.23012493E-04
-0.28224322E-02 0.98697939E-09
0.34494102E-02 0.23010081E-04
-0.68906364E-02 -0.11011629E-04
0.99635613E+00 -0.88247498E-05
19
Download