Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
·Ii
SIGNALS: Interactive Software for One-Dimensional Signal Processing ROGER L. EASTON, Jr. Chester F. Carlson Center for Imaging Science, Rochester Institute of Technology, 54 Lomb Memorial Drive, Rochester, NY 14623-5604
ABSTRACT
This article describes the features of a DOS program that was written for interactive demonstrations of one-dimensional II-D) signal processing concepts in a classroom environment. It also is used to illustrate aspects of linear systems, physical optics, and complex numbers. The program is menu-driven, and experience has proven that it is easy to learn and use. Complex-valued functions are loaded from a sizeable menu of options and may be processed in a variety of ways and plotted in several formats. Data files may be input from or output to other applications, e.g. spreadsheets. ~ 1994 John Wiley & Sons, Inc.
INTRODUCTION
The RIT academic program in Imaging Science includes aspects of a variety of disciplines, including linear systems, optics, holography, diagnostic medical imaging, and digital image processing/ compression. In a classroom environment, the ability to demonstrate these diverse concepts interactively significantly enhances the learning process. Graphical representations of the input, output, and system functions drawn by hand in real time usually are poor substitutes for accurate plotting. Although graphical transparencies may be created beforehand, the ability to manipulate examples in response to student questions is quite valuable. Available commercial packages (e.g., MathCAD ™ and
Computer Applications in Engineering Education, Vol. 1(6) 489-501 (1993)
C 1994 John Wiley & Sons, Inc. CCC 1061-3773/94/060489-13
Mathematica TM) are suitable for addressing many of these topics, but generally require powerful computing hardware and a high-quality display device (e.g., a high-resolution large-screen monitor or color projection pad) for effective use. The expense for the necessary hardware and software may make these options less feasible for lecture use, and the packages often are not easily executed in a classroom environment in "real time." Of course, it also is beneficial for students to replicate and modify examples on their own computers. Although the prices of hardware and educational software have declined substantially, there still is a need for inexpensive and easily learned scientific software that runs on lower-end machines.
DESCRIPTION OF THE PROGRAM
SIGNALS is intended to illustrate principles of linear systems and signal processing without expensive
489
490 EASTON
hardware, a high-quality color graphics display, or significant learning time. Written in Microsoft QuickBASIC, SIGNALS supports all common DOS graphics formats, including CGA, EGA, and VGA in both monochrome and color, and monochrome Hercules graphics. The program runs in a DOS window under Microsoft WINDOWS 3.0 or 3.1 , and the graphics screens may be copied to the WINDOWS clipboard for insertion into documents. It also runs in a DOS window under OS / 2 2.1. The program is available as "sgnls30.zip" via anonymous ftp from "oak.oakland.edu" in the directory "pub/ msdos/math" and mirror sites.
Functions and operations are selected from menus by keystroke rather than by pointing device; this decision was dictated both by the environment in which the program is used and by the nature of the required inputs. For example, entry of numerical parameters of a function (e.g., amplitude, width) by pointing device is not convenient. In a lecture environment, it is generally easier to select options and enter numerical data using only the keyboard. Selections from menus are made by single mnemonic keystrokes. The number of possible selections in a particular menu is limited to the keyboard character set and the number of selections with convenient mnemonics is even more limited. All numerical selections have default values, which enables rapid demonstrations of many operations.
SIGNALS has five menus: MAIN, FUNCTION, OPERATIONS, "ARITHMETIC" (so called because it combines values ofthe two arrays, e.g., sum or convolution), and PLOT. Menus other than MAIN are selected from other menus by typing the appropriate first letter. Options within these menus will be described individually, and the complete list is presented in the Appendix. The user is prompted for any required numerical parameters, with the default value indicated.
After an information page, the first screen that appears in SIGNALS is the MAIN menu; it may also be called from other menus by the ESCAPE key. Options in the MAIN menu allow users to specify global parameters of the program, such as the conventions for indexing the arrays and for normalizing the FFT, and the number of samples N in the arrays. Although N is limited to 8,192 samples per array by the size of the DOS data segment, this is more than sufficient for classroom use. N is restricted to powers of two by the recursive fast Fourier transform algorithm, but this also is not a significant handicap. Other options in the MAIN menu allow data arrays to be loaded from or saved to disk files in two formats; a three-column tab-delimited file
suitable for spreadsheets, and a simple column of data. The user may also shell to DOS temporarily.
Two complex-valued data arrays (f.(n) and f2 ( n» are available to the user and are loaded in the FUNCTIONS menu. The available functions are listed in the Appendix. Among the choices are numerical constants (including fractions, 7r, and e), the rectangle, triangle, sinc, Gaussian, sinusoidal, discrete delta, and comb functions. A number of noise distributions are included: uniform, Gaussian, Poisson, Boltzmann, Cauchy, and shot noise. Among the less-common functions that are useful for specific applications are the quadratic-phase function (chirp), Fresnel zone plate, Bessel function of the first kind, and the profile of the besinc function (sometimes called the sombrero function). The FUNCTIONS menu also includes a set ofinterpolation functions for simulating reconstruction of continuous functions from samples and some data windows (e.g., Hanning, Hamming).
The complex arrays are loaded in a specific order. The real part is loaded first, and mUltiple selections are added together. Next, the user may load a modulation function for the real part, if desired. The imaginary part and its modulation function are loaded next. Alternatively, complex arrays may be loaded as magnitude and phase, but such arrays must be converted to real/imaginary parts in the OPERATIONS menu before subsequent processing.
Selections in the OPERATIONS menu include quantization, thresholding, clipping, and normalization of the arrays, raising the amplitude to a power, and computing the reciprocal, complex logarithm, or complex exponential. The discrete derivative, discrete integral, autocorrelation, and convolution with a user-selected small kernel may be computed. The OPERATIONS menu also includes data transformations: the discrete Fourier transform (DFT), fast Fourier transform (FFT), discrete Hartley transform, and Walsh-Hadamard transform. The computation times of the transformations are displayed for comparing the computational intensity of the transforms. The data arrays are considered to be pure numbers, i.e., the domain is not specified. For example, this allows consecutive forward FFTs to be computed, which is useful for applications such as modeling cascaded optical systems.
Selections in the ARITHMETIC menu compute combinations of the two arrays, including sum, difference, product, ratio, convolution, and correlation. Also, one array may be used as a lookup table for the other array. The result of each selection is stored in array f. and the samples in f2 are set to zero.
..
Several graphing formats for complex arrays are available in the PLOT menu, including as real/ imaginary parts, magnitude / phase, squared magnitude (power), 10gIO of the power (in decibels), and as an Argand diagram or Lissajous figure (real part plotted on x-axis and imaginary part on y-axis). This last option may be used to make scatter plots, e.g., of noisy data. Arrays may be plotted as data points, as points connected by line segments, or as a "discrete" plot that resembles a bar graph. All options in the ARITHMETIC menu except convolution and correlation are available in the PLOT menu for display only, i.e., the result of the operation is not retained. Numerical values of the real and imaginary parts, magnitude and phase, and so forth may be read with the VALVES option. The real and imaginary arrays are plotted with a cursor for selecting the sample value to be read. This option is also useful for comparing two real-valued arrays by loading one in the "real part" and the other in the "imaginary part." An option to "zoom" the VALVES display by factors of powers of two improves readability if the arrays are large. Other options in the PLOT menu include computation of the histogram: The user selects the range of amplitudes and number of bins, and a graph of the number of samples in each bin is displayed. The data statistics (mean, variance, standard deviation, and entropy) may also be computed.
USE OF THE PROGRAM IN LECTURES
Among the concepts that SIGNALS was written to illustrate are equivalent representations of complex functions as real/imaginary parts and as magnitude/ phase, representations of complex-valued signals in the space and spatial frequency domains, and the principles of the discrete and fast Fourier transform algorithms. In actual use, the flexibility of the program makes it possible to illustrate more advanced concepts in digital signal processing (e.g., sampling, aliasing, optimum linear filtering, nonlinear filtering, noise analysis, data compression), and in optics (e.g., Fresnel diffraction and the Cornu spiral, optical interference and holography, and stellar speckle imaging). Some examples will be described to illustrate the use of the program. Readers desiring more thorough derivations should consult the references [1-6]. Further suggestions for use of the program are available from the author.
SIGNALS INTERACTIVE SOFTWARE 491
Example 1: Representation of Complex Functions
Complex functions may be entered and displayed in SIGNALS as real/imaginary parts or as magnitude and phase:
f( x) = .9l e { f( x)} + e"J m { f( x) } ( I ) = If(x)le'4>(f(x»)
These are related by the transformation from Cartesian to polar coordinates:
If(x) 1 == V(.9le {f(x)})2 + (Jm{f(x)})2 (2a)
cJ? { f( x)} == TAN - I { J m { f( x) } )} ( 2b ) .9le {f(x)}
.9le{f(x)} = If(x)ICOS{cJ?{f(x)} (2c)
Jm{f(x)} = If(x )J SIN{cJ?{f(x)} (2d)
To illustrate, the steps for loading a complex function will be detailed. The function is:
This is most easily entered by computing the reciprocal of I - 211"e"x, which is loaded via the "constant" and "line segment" functions. For convenience, it is suggested to use the convention that there are iN samples per unit length. For N = 256, the line segment for the imaginary part is loaded with amplitudes of[2· 8, 2· -8] = [+ 16, -16] at the default endpoints. The amplitudes are modulated by a constant of value 11" (type "pi" at the prompt). The reciprocal of the array is computed via the "inverse" option in the operations array. The result is viewed by using the options in the "PLOT" menu; option "R" displays the real and imaginary parts (Fig. 1) and option "M" displays the magnitude and phase (Fig. 2). Note that the real part is a Lorentzian and the phase is an arctangent function. The Argand diagram is obtained via the "N" option in the display menu, and is a circle of radius 0.5 centered at [0.5, 0] (Fig. 3).
Example 2: Sampling and Interpolation of Continuous Functions
SIGNALS may be used to simulate processing of functions with infinite support by densely sampling suitable periodic functions. For example, it can be used to demonstrate digitization (sampling and
•
492 EASTON
quantization) of a continuous function and interpolation from a sampled to a continuous function. Although this example will illustrate sampling only, a signal may be quantized via the threshold or quantization options in the OPERATIONS menu. The process of sampling is illustrated by generating an "approximately" continuous periodic function and multiplying by a coarse COMB function (e.g., with elements separated by Ll x = YN). The original "continuous" function is estimated by interpolating the amplitudes between the samples. In imaging, the interpolation function is determined by the display device, e.g., the scanning spot of a video monitor. A set of interpolation functions is available (option "-" in the FUNCTIONS menu), which are classified by the number of samples weighted in the interpolation. "Nearest-neighbor interpolation" assigns the amplitude of the nearest sample to any coordinate; the corresponding interpolation func-
tion is RECT(: x), The "linear interpolator"
computes a linearly weighted combination of the two nearest samples and is described by
TRI(:x)' The quadratic and cubic interpolators
compute weighted combinations of the nearest three and four samples respectively. Ideal interpolation is
described by SINC( : x) , which has infinite support
and thus weights all samples. For example, with N = 1024, load array f1 with
a biased real-valued cosine with a period of 128
samples ( e.g., f1 (x) = ( 2 + COS(~;;)) ) . This is
sampled by mUltiplying with a COMB function with an integer number of elements in N samples, e.g., Llx = YN = 32 samples. This can be done either by loading the sampling function into f2 and mUltiplying ("x" option in ARITHMETIC menu), or directly by loading the sampling function in the MODULATION menu for the real part of fl. In this example, there will be four samples per period of the original cosine (Fig. 4).
To simulate recovery of a continuous function from its samples, the sampled function is loaded into one array and one of the interpolators is loaded into the real part of the other. The interpolated function is computed by copying the interpolation function at each sample with the appropriate amplitude and summing the ensemble of amplitudes at each coordinate. This operation is the "convolution" of the sampled function and interpolator; the process of convolution is de-
..
+Ir----------------.--------------~
-I · 8 x • 0 +8
~~_J } J - }r,,;x
+1
~ 0
~ -I
-8 x • 0 +8
g~_J } J - 2tr.x
Figure 1 Real and imaginary parts of 1 1 - 21rl x
scribed in greater detail in the next section, and is computed via option "." in the ARITHMETIC menu. The character of the function recovered from the samples is determined by the interpolation function. For example, the result of nearest-neighbor interpolation resembles a "barchart" (Fig. 5). Linear interpolation yields an estimate analogous to a child's "connect-thedots" picture (Fig. 6). It is possible to demonstrate the derivation of the simple interpolators by multiple convolutions of RECT functions to obtain the linear, quadratic, and cubic interpolators.
Although the infinite support of the SINC ensures that the interpolation process cannot be modeled without error, the approximation is quite good in this example (Fig. 7). By using this procedure of sampling and ideal interpolation of sinusoids with higher spatial frequencies, the effects of "aliasing" can be demonstrated where the frequency of the recovered function differs from that of the original continuous function.
,/~--------------~---------------'
o~======~----+----=~~====~
·/L-~~~~~~~-L~~~~~~~~ .,
.. .. 11
o
'012
'0 .,
x • 0
If J
x • 0
Figure 2 Magnitude and phase of 1 2 . . - 1re X
.. SIGNALS INTERACTIVE SOFTWARE 493
J
1 . . . . • . • . . . . . . .
oL-------~------~------~------~ ·512 x • 0 5U
Figure 4 2 + cose;;) sampled by COMB (3X2) .
Example 3: Linear Shift-Invariant Imaging Systems and Convolution
A primary reason for developing SIGNALS was to model the action of imaging systems. In the most general case, the action of an imaging system on an input function f(x) yields an output image g(x):
(o{f(x)} := g(x) (4)
where the operator (0 may modify the function f(x) arbitrarily to generate g(x). For example, the amplitude of the signal may be relocated in any manner and redefined by some linear or nonlinear mapping, i.e., lookup table. Imaging problems may be grouped into three classes:
,/ ~----------------r-----------------.
/ g",,{J{x)J • 0 I-----------------~--------------__i
\ ..
. / L-________________ L-______________ ~
-/ flt.lI(x)J • 0 ,I
. 1 Figure 3 Argand dIagram of 2"
1 - 1reX
..
494 EASTON
+1
+1
o~------~------~------~------~ -5/1 x • 0 Sil
Figure 5 Estimate of 2 + cos ( ~;: ) via nearest-neighbor interpolation_
oL-______ ~ ______ ~ ________ L_ ______ ~
-5/1 x • 0 511
Figure 6 Estimate of 2 + cos(~;:) via linear interpolation_
I. The direct problem, where the output g(x) is computed from knowledge of the input f( x) and the system (J);
2. the inverse problem, where the input is found from knowledge of the output and the system; and
3. analysis of the system, i.e., derivation of the system from knowledge of the input and output.
In other words, given two of the three quantities (J), f(x), and g(x), find the third. Cases where two functions are partly known are not considered here_
Solutions of the inverse and system analysis problems are generally impossible for an arbitrary imaging system. Even if restricted to physically realistic systems, the mathematical system operators rarely are susceptible to convenient analysis. To make analysis tractable, two assumptions are helpful: 1) linearity and 2) shift- (space-, time-) invariance. In a 1-0 system governed by both linearity
and shift invariance (i.e., an LSI system), its action may be expressed mathematically as a convolution integral off(x) and a system function h(x) ; the discrete system is a convolution sum:
(J) { f( x)} = f( x) * h (x) ( 5 )
-100
f(a)h(x - a)da = g(x)
(J) {f( n)} = f( n)* h( n) (6) 00
= L f(m)h(n - m) = g(n) m--oo
To compute the convolution sum, the system function h (m) is "flipped" (reflected across the origin), translated to coordinate indexed by n, multiplied by f( n), and summed over all samples. In actual use the discrete summation must be made over finite limits. Iff(n) and h(n) have finite support, so will the output g( n). This is a "linear" convolution. Another variety of the discrete convolution assumes that f(n) and h(n) are N-point arrays which represent infinite arrays that are periodic over N samples. The circular convolution of the two arrays is obtained by "wrapping" the arrays onto cylinders and computing the area of the products over N samples. The circular convolution may be computed via the discrete Fourier transform.
Linear convolution of arrays with system functions (kernels) is performed with the" * " option in the OPERATIONS menu, which includes a selection of pre programmed functions including uniform averaging and derivatives of order one to four. The user may also manually enter a desired kernel, though this option is feasible only for compact functions. Circular convolution of the arrays is computed by selecting the "*" option in the
oL---____ ~ ______ -L ______ ~ ______ ~
-511 x • 0 511
Figure 7 Estimate of 2 + COS ( ~ ;:) via ideal interpolation_
..
· .0lJ ,---------.----------,
;f:\ o~----------~~H4~------------~
• .olJ l..-_______ -'-_______ --'
·118 •• 0 III
Figure 8 Second derivative OfGAUS( In6) .
ARITHMETIC menu. For example, load array fl with a triangle function of width YN, select the convolution option in the OPERATIONS menu to compute the second derivative. The result is shown in Figure 8.
Example 4: Modeling Imaging Systems by Circular Convolution via FITs in SIGNALS
In imaging, the system function is generally complex-valued and is called the "impulse response" or "point spread function" because it represents the output of the system for an impulsive input. Computation of the convolution with the impulse response requires translation, multiplication, and integration over coordinates. Such a process is difficult or impossible to invert, and thus solution of inverse or system analysis problems is difficult except in the simplest cases. However, these problems are solved easily by transforming the problem to a coordinate system based on complex sinusoidal functions. A convolution in the original coordinate system (i.e., in the "space domain") becomes a coordinate-bycoordinate multiplication in the new coordinate system ("frequency domain"), which may be inverted or analyzed easily. The new representation is a linear combination of projections of f(x) onto cosine and sine functions of all frequencies ~. In the continuous case:
F(t) = a L: f(x)COS(21r~x)dx + {j L: f(x)SIN(21r~x)dx (7)
SIGNALS INTERACTIVE SOFTWARE 495
The constants a and (j are arbitrary. If they are chosen to be unity, the transformation becomes:
FH(O = L: f(x)(COS(21r~x) + SIN(21r~x»dx!!! L: f(x)CAS(21r~x)dx (8)
This is the Hartley transform; the discrete version is computed by option "H" in the OPERATIONS menu. It is real-valued if f( x) is real-valued.
A more common linear combination of the cosines and sines is obtained by setting a = 1 and (j - V-1 i$ - i:
F(O = L: f(x)(COS(21r~x) - i SIN(21r~x»dx = L: f(x)e -2
" ' fXdx (9)
This transformation of coordinates is the basis for many signal processing operations. The two representations f( x) and F( 0 are equivalent because one may be derived from complete knowledge of the either. We often speak of f(x) as the space representation and F( 0 as the frequency representation. F( 0 is also called the spectrum of the function, analogous to the decomposition of white light into its spectrum components.
The discrete version of the Fourier transform (OFT) is an infinite summation:
00
~ {f(n)} !!!! F(O = L f(n)e -2" .-~n.ax (10) n=- (lCJ
The periodicity of e - 2",En' ax with ~ ensures that the
OFT will be periodic over the interval -1- , and thus ~x
only one period need be computed. The periodicity of the spectrum is another illustration of the limitation of sampling that results in aliasing; only sinusoids sampled more than twice per period may be reconstructed without error by ideal interpolation. If a sinusoid is sampled less than twice per period, the periodic components of the spectrum will overlap. This can be expressed as the Nyquist condition on the frequency ~ of sinusoids which may be reconstructed without error:
1 1 - --<~<--2·~x 2·~x
( 11)
..
496 EASTON
The limiting value is the "Nyquist sampling frequency" and it seems logical to give the name "Nyquist window" to the range of unaliased frequencies.
Obviously, the infinite summation in the DFT (Eq. 10) cannot be computed. A finite summation of f( n) over N samples will yield no more than N independent samples of F ( ~) that are separated by
a frequency interval d~ = N .ldX . The samples of
F(O may be indexed by an integer k. The common convention indexes the N samples in either domain from 0 to N - 1, so that the range of spatial fre-
.. 0 N - 1 Th . d" f quencles IS ~ = to ~ = -- . e peno ICIty 0 N·dx
the spectrum ensures that samples at frequencies
above the Nyquist limit ( ~ = 2. ~ x) are identical
to those at negative frequencies in the Nyquist window. The expression for the finite DFT is:
N - I 2 .. ink
F(k) = A L f(n)e- N (12) n- O
The form for the corresponding inverse transform is:
N- I 2 .. ink
f(n) = B L F(k)e+N (13) k- O
where A and B are normalization constants. Computation of the discrete Fourier transform
(eq. 12) is straightforward but numerically intensive: It requires a number of computations of order N 2
to compute N frequency components from N samples. Cooley and Tukey 7 developed the recursive Fast Fourier Transform algorithm (FFT) in 1965, which requires a number of computations of order N log2(N) ifN is a power of two. Options are available in the OPERATIONS menu of SIGNALS to compute the spectrum via the DFT and FFT, and displays the computation time to demonstrate the speed advantage of the FFT.
In imaging problems, it often is more convenient to place the origin of coordinates in the center of the array ("centered data"). For N even, the indices
N N of the array run from - 2" to 2" - 1, and that the
frequency range is - -2 1 < ~ < -2 1 . Users of ·dx ·dx
SIGNALS have the option of selecting either index-
ing convention, with the former as the default. It is possible to apply the "standard" form of the FFT to centered data in two ways. The first method, which may be called "torusing," exchanges the left and right halves of centered data before and after the standard DFT. The second method ("checkerboarding") multiplies the amplitudes of elements with odd indices by - 1 before and after the standard transform. These can be demonstrated in SIGNALS by loading a centered function in an array with the default indexing (0 s; n s; N - I), with circular
translation by ~ samples (option ">" in the OP
ERA TIONS menu) or "checkerboarding" (option "!" in the OPERATIONS menu) before and after the FFT.
To ensure that the cascade of a forward and inverse transform yields the original function f( n), the normalization factors A and B must be chosen such that their product is N - I . Different conventions have different advantages, and the traditional choice is to set A = I and B = N- 1• An alternative convention, where A = N - I and B = 1, results in a closer correspondence with continuous transforms of some functions. Again, SIGNALS supports both conventions, with normalization in the inverse transform as the default.
In the DFT option ("K" in the OPERATIONS menu), the user enters the maximum and minimum spatial frequencies (in cycles per sample, with default as the Nyquist limits of ±0.5), and the number of frequencies to be computed. The program warns the user if either frequency limit falls outside the Nyquist window. By computing the spectrum over a range larger than the Nyquist window, the periodicity of the spectrum is de~onstrated. In the DFT option, an odd number of frequencies symmetric about the origin usually is computed, which ensures that the amplitude at zero frequency is displayed. The DFT spectrum may be viewed in any of the normal formats (real/imaginary parts, magnitude/ phase, Argand diagram, etc.). The DFT arrays are computed in scratch memory and are discarded after display.
The forward and inverse FFT computation (options "T" and "I" in the OPERATIONS menu) uses the specified normalization and indexing conventions and retains the result in the original array. To compare the results of the DFT and FFT, load both arrays with a RECT function with the default width of VN samples in an array of size N. This can be done by loading fl and using the DUPLICATE option ("D" in the OPERATIONS menu) to copy
..
_/6 .-------.-----r----.-------"";I
./6 '-___ -'-___ --L ____ ~ ___ _I
./ ·0.5 ( • 0
Figure 9 DFf of RECT ( In6) over range of ± I cycles
per sample.
into f2. By computing the OFT off. over a frequency range of ± 1 cycle per sample, the periodicity of the spectrum and "overlap" of the spectral orders can be seen (Fig. 9); this is evidence of aliasing of the sampled RECf. The computation time should be noted. The FFf of f2 is computed and the computation time noted. Aliasing of the RECf can be seen by comparing to a true SINC function (normalize
the FFf to unity, load SINC( IN) into the
"Imaginary Part" of the array, and compare the amplitudes in the Values option of the PLOT menu (Fig. 1O).
Example 5: Data Windows and the FFT
Computation of the FFf assumes that both the input function f( n } and the spectrum F (k) are periodic over N samples. This is not true if f( n} has a noninteger number of periods in N samples. The resulting spectrum will exhibit "leakage," which can be demonstrated by comparing spectra of periodic functions that are similar except for their periods. This is easily done for real-valued even functions (e.g., cosines), because the spectra are also real-valued and even. The spectra of two even functions may be computed simultaneously and without mutual interference by loading them into the real and imaginary parts of one array. The FFf of an array consisting of cosines with periods of 16 and 24 samples (N = 256) in the real and imaginary parts will exhibit leakage in the second case (Fig. 11). The leakage may be reduced at the cost of resolution by modulating the function with a Hanning data window (option "W" in the FUNCTIONS menu); these force the function to be periodic over N samples. The resulting spectra are shown in Figure 12. The
SIGNALS INTERACTIVE SOFTWARE 497
ur---------x---------~
o "
·/6 '--------~---------' ·0.5 ( • 0 .0.5
Figure 10 Spectrum of RECT( In6) (solid line),
SINC ( ;6) (dotted line) via FFf.
available windows (Bartlett, Hanning, Hamming, etc.) are listed in the appendix. Windows may be generated with widths less than N to compare spectra.
_/16 r--------r--r-.,---------,
or-------------'--r~------------~
·/16 '----------'------------' ·0.5 (.0 U
Spectrum 0/ COS [ "%n] N D 256
/16 r------------r----------,
· /26 '---------'-----------' · 0.5
Figure 11 leakage.
( • 0 0.5
Sp«Irum 0/ COS[~) N = 2.S6
Spectra of sampled functions without and with
.,.
498 EASTON
118 2. mUltiply F(O by H(O at each frequency to
o~------------~~~------------~
.118 1.-_______ --'-_______ --'
.().j f • 0
Sp«trum 0/ COS [t,n] Modulated by Hanning Window
118 .-----------"'T""---------,
[ I o~------------~_r~------------~
.118 1--_______ --'-_______ --'
~ f·O ~
Spectrum 0/ COS [ 1: ] Modulated by Hanning Window
Figure 12 Spectra of sampled functions computed with Hanning window.
Example 6: Filter Theorem
Probably the most important application of the Fourier transform is to compute convolutions. In the continuous case,
';I {g(X)} !IE G(O = F(t)· H(t) (14)
The transform H( t) of the impulse response is called the "transfer function" and describes how well the system transmits specific sinusoidal frequencies to the output function. The representation of the out-
obtain G(t); and 3. compute the inverse Fourier transform of
G(O to obtain g(x).
If sampled functions are convolved via FFTs, the result is the circular convolution off(n) and h(n), which is periodic over N samples. The default normalization of the FFT should be used (multiply by N - I in the inverse transform) to obtain the correct amplitudes.
The steps of the filter theorem may be demonstrated in SIGNALS by loading the input f( n) and the impulse response h(n) into different arrays, individually transforming, multiplying the transforms, and inverse transforming. The complete computation also is selected by the "." option in the ARITHMETIC menu. As an example, uniform motion blur of a full-width three-bar chart may be modeled by loading fl from option "3" in the FUNCTIONS menu and f2 with a RECT function
· /L-_________ --'-________ -J
· 118 • • 0 111 J(n), 30 Bar Chart
./r-~-~-~---~--------,
put in the original spatial coordinate system is found 0 ~-~-~-........L---.I,-+-__ -'-....L._--l'----l
via the inverse Fourier transform:
g(x) = ';I - I {G(t)} (IS)
This direct imaging problem may be solved by this recipe:
1. Compute the Fourier transforms of f( x) and h(x);
· /1.-_______ --'-_______ --'
· 118 •• 0 III
f(n) alter t:tJtWOillllDn wit" 16 RECT[ T6]
Figure 13 Three-bar chart before and after FFf convolution with 1 /16 RECf ( n /16 ).
..
of unit area and width equal to the blur (e.g., a RECT function of width 16 and amplitude ff,). The visibility of the bars is reduced by this averaging (Fig. 13).
SIGNALS can be used to demonstrate the representations of the impulse response and transfer function of a wide variety of linear filters. Useful examples include the lowpass, highpass filters, bandpass and bandstop filters with different band profiles, bandwidths, and center frequencies. The impulse responses of allpass filters (i.e., the transfer functions have constant magnitude and varying phase) are useful, particularly to model optical imaging systems where the phase is often a quadratic function of ~. Mixed filters, i.e., where both the magnitude and phase of the transfer function vary with ~, can also be easily modeled and compared.
SIGNALS may be used to model the transfer functions of causal filters, i.e., where the impulse response h(n) = 0 for n < O. Such a filter is loaded into an array indexed for centered data and truncated by modulating by a STEP function. The transfer function is computed by FFT, though a window should be applied if the impulse response has semi-infinite support ( e.g., h (n) = COS (21r~on)· STEP ( n». The transfer functions of the causal and noncausal filters can be compared to illustrate the wider bandwidth and phase distortions of the former.
Other Demonstrations of Imaging Principles with SIGNALS
Operations available in SIGNALS can be used to demonstrate other imaging applications in signal processing. The following examples have proven useful in various courses. Readers who are interested in using SIGNALS to demonstrate these concepts are invited to write the author for examples and recommendations.
1. Derivation of the impulse response and transfer function of optimum linear filters, i.e., linear filters that are optimum for particular task in a least-squares sense. These include the inverse filter for estimating a function from knowledge of a blurred function and the blurring kernel; the matched filter for estimating the position of a known signal corrupted by additive noise; and the Wiener filter for estimating an unknown signal in additive noise from knowledge of the power spectra of the signal and the noise. Derivations of the expressions for the appropriate transfer func-
SIGNALS INTERACTIVE SOFTWARE 499
tions are found in many standard texts [1]. SIGNALS can be used to model any of these filters.
2. Derivation of the Fourier transform can be demonstrated frequency by frequency by multiplying some input by COS(21r~n)
- t'SIN (21r~n) and integrating. This computation is available in the PLOT menu.
3. The noise functions, histogram, and statistical calculations can be used to demonstrate the effects of filtering noisy images, e.g., by the mean and median filters.
4. The entropy calculation can be used to demonstrate the information content of a I-D function. Appropriate invertible transformations (e.g., the derivative, FFT, and WalshHadamard transform) can be implemented to demonstrate transform data compression.
S. The effect of system nonlinearities on the image spectrum can be modeled by comparing the spectra before and after mapping f( x) through some nonlinear lookup table or after equalizing its histogram.
6. The quadratic-phase functions may be used to model I-D optical diffraction by computing the convolution of an aperture function and the appropriate Huygens' wavelet for a particular distance and wavelength. For example, the appropriate wavelet for Fresnel diffraction has constant magnitude and quadratic phase and may be modeled easily with the available functions . The amplitude distribution oflight diffracted from an aperture may be computed by convolving the aperture function with this wavelet. If f( x) is a STEP function to model a knife edge, the Argand diagram of the diffracted amplitude is the familiar Cornu spiral.
7. The impulse response and modulation transfer function (MTF) of a lens system can be modeled by cascading the convolutions that model diffraction with the quadratic phase modulation of spherical lenses. The effect of defocus on the MTF can be modeled by adding an incremental quadratic phase to the lens modulation.
8. Schlieren imaging may be demonstrated by applying an appropriate highpass filter to an input phase function, i.e., f( x) has constant magnitude and varying phase, f(x) = l(x)e'·~X).
9. Image recovery in stellar speckle interferometry may be modeled by filtering the input f( x) with an appropriate phase transfer func-
500 EASTON
tion for the speckle before analyzing the resulting power spectrum.
APPENDIX: MENU OPTIONS IN SIGNALS
FUNCTIONS MENU Constant Signum Step Sinusoid Square Wave Discrete Delta Function Discrete COMB Function Rectangle Triangle Sinc Function Gaussian Bessel Function Besinc Function Profile Line with selectable endpoints Exponential modulated by Step Power Series Terms Chirp (quadratic-phase sinusoid) Fresnel Zone Plate Noise from the following distributions
Binomial, Gaussian, Uniform, Poisson, Shot, Boltzmann, Lorentz (Cauchy)
Window Functions Bartlett, Hanning, Hamming, Half-Cycle Sine, Half-Cycle Sine 3
, Blackman-Harris, Gaussian, Cosine squared, Parzen, Extended Cosine Bell, Welch, Rectangular, Blackman, Cauchy
Interpolators Nearest Neighbor, Linear, Quadratic, 3 Cubics, Sinc (ideal interpolator)
Special Functions Lorentzian, ArcSine, ArcTangent, SINH, COSH, TANH, TANH - I , Error Function
OPERA TIONS MENU Duplicate into other array Convert to real/imaginary parts Convert to magnitude/phase Complex conjugate of array normalize array time-reversal of array Circular translation of array Compute squared magnitude of array Raise complex amplitude to a power Compute reciprocal of complex amplitude Compute complex exponential of amplitude Compute complex logarithm of amplitude
Compute logarithm of the magnitude Exchange real and imaginary parts Compute integral Compute discrete derivative Quantize amplitude Threshold amplitude Clip amplitude Nonlinear filters
Median, Maximum, Minimum, Variance Autocorrelation Convolution with small kernel FFT/IFFT OFT Hartley transform Walsh-Hadamard transform Complex Cepstrum Histogram equalization
ARITHMETIC MENU Add Subtract Multiply Divide Convolve Correlate Shift and Add Lookup Table
PLOT MENU Real / Imaginary Parts Magnitude / Phase Power LogJO Power Read Values Argand Diagram Histogram Statistics Plot Sum of Arrays Plot Difference of Arrays Plot Product of Arrays Plot Ratio of Arrays Plot Real Part-Imaginary Part Compute Integral of Product of Arrays
REFERENCES
I. R. N. Bracewell, The Fourier Transform and Its Applications (2nd Ed., Rev.), McGraw-Hill, New York, 1986.
2. E. O. Brigham, The Fast Fourier Transform and Its Applications. Prentice-Hall, Englewood Cliffs, NJ, 1988.
3. R. W. Ramirez, The FFT, Fundamentals and Concepts, Prentice-Hall, Englewood Cliffs, NJ, 1985.
4. J. D. Gaskill, Linear Systems, Fourier Trans/orms, and Optics, John Wiley and Sons, New York, 1978.
5. M. Cartwright, Fourier Methods for Mathematicians, Scientists, and Engineers, Ellis Horwood, Chichester, England, 1990.
BIOGRAPHY
Roger L. Easton, Jr. is an Assistant Professor in the Chester F. Carlson Center for Imaging Science at the Rochester Institute of Technology. He received the B.S. degree in Astronomy from Haverford College, the M.S. in Physics from the University of Maryland, and the M.S. and Ph.D. degrees in Optical Sciences from the University of Arizona. He is a member of SPIE, OSA, and IEEE.
His interests include optical signal processing, digital image processing in astronomy, digital halftoning, and computer-generated holography.
SIGNALS INTERACTIVE SOFTWARE 501
6. J. S. Walker, Fast Fourier Trans/orms, CRC Press, Boca Raton, FL, 1991.
7. P. M. Cooley and J. W. Tukey, "An Algorithm for the Machine Computation of Complex Fourier Series, Mathematics o/Computation, Vol. 19, 1965, pp. 297-301.
• •
•
•