Digital Signal Processing

By Steven W. Smith, Ph.D.

- 1: The Breadth and Depth of DSP
- 2: Statistics, Probability and Noise
- 3: ADC and DAC
- 4: DSP Software
- 5: Linear Systems
- 6: Convolution
- 7: Properties of Convolution
- 8: The Discrete Fourier Transform
- 9: Applications of the DFT
- 10: Fourier Transform Properties
- 11: Fourier Transform Pairs
- 12: The Fast Fourier Transform
- 13: Continuous Signal Processing
- 14: Introduction to Digital Filters
- 15: Moving Average Filters
- 16: Windowed-Sinc Filters
- 17: Custom Filters
- 18: FFT Convolution
- 19: Recursive Filters
- 20: Chebyshev Filters
- 21: Filter Comparison
- 22: Audio Processing
- 23: Image Formation & Display
- 24: Linear Image Processing
- 25: Special Imaging Techniques
- 26: Neural Networks (and more!)
- 27: Data Compression
- 28: Digital Signal Processors
- 29: Getting Started with DSPs
- 30: Complex Numbers
- 31: The Complex Fourier Transform
- 32: The Laplace Transform
- 33: The z-Transform
- 34: Explaining Benford's Law

Your laser printer will thank you!

Most DSP applications are programmed in C or Fortran. Just the thing you need when programs contain thousands of lines of code, have multiple programmers working together, or will need to be modified and maintained in the future.

However, *learning* DSP has different requirements than *using* DSP.
You need to concentrate on understanding the algorithms and techniques, without being
distracted by the quirks of a particular language. You don't care about power and
flexibility; you need simplicity! The programs in this book are written
to teach DSP strategies in the most straightforward way, with all other factors being
treated as secondary. Good programming style is disregarded if it makes the program
logic more clear. For instance:

- a simplified version of BASIC is used
- line numbers are included
- the only control structure allowed is the FOR-NEXT loop
- there are no I/O statements
- integer variables are always identified by a "%" (such as I% or K%)

Here is an example program, showing how to carry out a recursive filter.

100 'RECURSIVE FILTER 110 'INITIALIZE AND DEFINE THE ARRAYS TO BE USED 120 DIM X[499] 'holds the input signal 130 DIM Y[499] 'holds the filtered output signal 140 ' 150 A0 = 0.93 'Set the recursion coefficients 160 A1 = -0.93 '(these values define a high-pass filter) 170 B1 = 0.86 180 ' 190 GOSUB XXXX 'Subroutine to load the input signal into X[ ] 200 ' 210 'FILTER THE SIGNAL BY RECURSION TO FIND Y[ ] 220 FOR I% = 2 TO 499 230 Y[I%] = A0*X[I%] + A1*X[I%-1] + B1*Y[I%-1] 240 NEXT I% 250 ' 260 END

A wide variety of filter responses can be created by simply changing the values of A0, A1, and B1. For instance, the program as written is a high pass filter. It can be changed into a low-pass filter by defining the coefficients to be: A0 = 0.05, A1 = 0, B1 = 0.95. The graphs below show examples of this program in action.

Here is another example program: the Discrete Fourier Transform, one of the most important algorithms in DSP.

100 'THE DISCRETE FOURIER TRANSFORM 110 'The frequency domain signals, held in REX[ ] and IMX[ ], are 120 'calculated from the time domain signal, held in XX[ ]. 130 ' 140 ' 'INITIALIZE AND DEFINE THE ARRAYS TO BE USED 150 DIM XX[511] 'holds the time domain signal 160 DIM REX[256] 'holds the real part of the frequency domain 170 DIM IMX[256] 'holds the imaginary part of the frequency domain 180 ' 190 PI = 3.14159265 'Set the constant, PI 200 N% = 512 'N% is the number of points in XX[ ] 210 ' 220 GOSUB XXXX 'Mythical subroutine that loads data into XX[ ] 230 ' 240 FOR K% = 0 TO 256 'Zero the values in REX[ ] & IMX[ ] so 250 REX[K%] = 0 'they can be used as accumulators 260 IMX[K%] = 0 270 NEXT K% 280 ' 'CALCULATE EACH SAMPLE IN REX[ ] and IMX[ ] 290 ' 300 FOR K% = 0 TO 256 'Loop through each sample in REX[ ] and IMX[ ] 310 FOR I% = 0 TO 511 'Loop through each sample in XX[ ] 320 ' 330 REX[K%] = REX[K%] + XX[I%] * COS(2*PI*K%*I%/N%) 340 IMX[K%] = IMX[K%] - XX[I%] * SIN(2*PI*K%*I%/N%) 350 ' 360 NEXT I% 370 NEXT K% 380 ' 390 END

Don't understand what is happening in lines 330 and 340? Don't worry, *three*
pages in the text are devoted to explaining how this algorithm works. These programs
may not be elegant or efficient- that's not their purpose- but they are guaranteed to
teach you DSP!