Chapter 11

Digital Signal Processing

Objectives: To introduce the concepts of DSP and the Fourier Transform

DSP stands for Digital Signal Processor which is a special high performance processor optimized for performing numeric calculations in tasks such as filtering and Fourier transformation. In our context we will use DSP in a more liberal sense to mean Digital Signal Processing which is any numerical calculation performed by the computer to analyze time variant data in order to extract useful information.

Any time series can be considered to be a collection of frequencies. Thus a varying voltage can be transformed into an infinite number of frequencies by the process known as the Fourier transformation. During the digitizing process, the analog voltage is transformed into discrete numbers, quantized in both amplitude and time. One therefore expects that this results in a frequency transformation which is also quantized in amplitude and frequency. Thus the time-to-frequency transformation is called the Discrete Fourier Transform (DFT).

The Fast Fourier Transform (FFT) is an optimized algorithm for calculating the DFT.


An FFT subroutine is available within Visual Basic in the Physics 4D6 lab. In order to use the FFT subroutine it must first be declared as shown. In your VB Module, enter

Declare Sub FFT Lib "FFT.DLL" ( x as single, ix as single, y as single, iy as single, byval ndata as integer)

(Note that x, ix, y, iy and ndata are just dummy variables and any names can be choosen.)

Also in the same module declare four arrays each of length N.

Global Const N = 1024

Global ReIn(N) as single

Global ImIn(N) as single

Global ReOut(N) as single

Global ImOut(N) as single

The input time series will be entered in the two arrays ReIn( ) and ImIn( ) where ReIn( ) is the real part and ImIn( ) is the imaginary part. In this case all elements of ImIn() should be set to zero.

After the FFT subroutine is called the result will be contained in the two arrays ReOut( ) and ImOut( ) where ReOut( ) represents the real part and ImOut( ) the imaginary part of the frequency spectrum.

The FFT subroutine is called using the following statement

FFT ReIn(0), ImIn(0), ReOut(0), ImOut(0), N

where N is the number of data points in each array and should be a power of 2 and must never exceed the total length of each array (otherwise the program will crash!). Note also that only the first element of each array is specified, i.e. index is 0. The FFT subroutine actually receives the memory address of the first element of each array and uses this information to access all N elements in the four arrays. The actual number of data points transformed by the FFT is the largest integer value which is a power of 2 that is less than or equal to N.

The power spectrum is computed by summing the squares of the real and imaginary parts, i.e.

Power = ReOut2 + ImOut2

Note that the FFT program writes results into the PC's memory and no checking is performed on the validity of indices and sizes of the arrays. Incorrect usage of array indices and sizes could result in a system crash!


1. Write a program to perform a 1024-point FFT of a 1024-point time series.

Test your FFT program by performing the transformation of various time series whose transforms are known, for example:

  1. all zeros, i.e. 0 0 0 0 0 ...
  2. all ones, i.e. 1 1 1 1 1 ...
  3. a one followed by all zeros, i.e. 1 0 0 0 0 ...
  4. all zeros except for a one in the second position, i.e. 0 1 0 0 0 ...
  5. a rectangular function
  6. a triangular function

Display the results by printing to the screen the values of the first 10 elements, for example, of both real and imaginary parts. For example,

FOR I = 0 to 9

PRINT ReOut(I), ImOut(I)

NEXT I

2. By computer modelling, generate sampled points of a 100Hz sine-wave, sampled at a rate of 1000 samples per second. Display a graph of the time series. Use your FFT program to generate and display the power spectrum. Comment on your results.

3. Interface the AD7574 ADC to the PC and digitize a 100Hz sine-wave signal at 1000 samples per second. Display the time series and the power spectrum in graphical form. Observe the effect of the uncertainty of the PC's timing system. Compare your results with those obtained from the simulated sine-wave in Exercise 2.


4. Design an external timing circuit which will eliminate the jitter in the sampling period. Set your sampling frequency for 1000 samples per second and digitize the external 100Hz sine-wave. Compare your results with those obtained in Exercises 2 and 3.


Note: The sine-wave and sampling frequencies noted above are nominal values and may need to be adjusted to suit your particular system.


2001.09.04


Home