Digital Signal Processing Techniques

Digital Signal Processing Techniques
Analog signals formerly processed by op-amps, resistors, capacitors and diodes, can also be
processed digitally. Digital signal processing (DSP) manipulates a data stream of numbers that
represent analog waveform amplitude. For this lab, a general purpose computer (a PC running
LINUX) will process an analog signal that has been digitized by an internal sound card. The
analog signal to be processed is a FAX format similar to that used to transmit images via
telephone. Weather satellite images are also transmitted using this analog format as well. Your
task is to accept digitized data from a file, and deliver bytes of output data suitable for gray scale
rendering of an image on the PC's screen. The primary DSP process in this task is AM
demodulation. Ideally, processing should occur in real time.
The sound card will be treated as a black box, where the digitizing process, and buffering of
the data stream is hidden from view. We will deal with the sound card interface through Clibrary function calls. Examples of how to initialize the soundcard, and how to access the data
stream are provided here.
Most of your time should be spent developing C-code that implements AM demodulator DSP
algorithms. "C" is the recommended language. Fast, low-level integer arithmetic is easily
implemented in C.
Criteria for evaluation
At the lowest level, your code should output data to a file that represents modulation
amplitude of an input disk file of sampled analog data. Speed of execution slower than real-time
is less than acceptable. You may use floating point number processing, along with transcendental
math operations at this low level.
Since much DSP hardware has no floating point operations, you should attempt to eliminate
transcendental operations, as well as floating point arithmetic. Fixed point mathematical
operations are very speedy in both this PC environment, and in DSP-specific chips. You should
attempt to implement fixed point arithmetic, once the basic DSP algorithms are mastered.
For input data streams that represent satellite images, you should consider how the output data
can be viewed on the PC screen. Considerations include:
•
how to transform output data into discrete pixels of suitable gray level
•
Timing and format of visual data transmission
•
pixel aspect ratio to give well proportioned images in an X-Y plane
•
graphical file formats that other X-windows programs can render on the computer
monitor
The next level of difficulty involves determining where the left margin of an image begins.
Using DSP techniques, find the "sync" tone burst markers in the data stream to determine where
a scan line begins. This can be difficult to do in real time.
At the highest level of difficulty, you will account for the PC's internal timing errors. Actually,
the satellite data stream includes some timing errors too, which involves doppler time shifting
due to high satellite orbital speeds. The PC's timing error mostly involves small sampling timing
errors of the sound card master clock. Using DSP techniques, all these timing errors can be
eliminated, by locking onto the 2400 Hz. subcarrier frequency. Since the modulation depth is
less than 100%, the 2400 Hz. carrier wave is present at all times. It is possible to phase-track this
subcarrier using DSP techniques. Successful phase tracking results in images with perfect
vertical alignment.
FAX and APT signal format
Automatic Picture Transmission format starts with a carrier sine wave having constant
frequency of exactly 2400 Hz. The amplitude of this carrier wave is directly proportional to the
image's gray level. Black corresponds to an amplitude of zero, while white corresponds to
maximum amplitude. This signal can then travel through any manner of transmission media
(telephone or VHF transmitter/receiver). Shown above is a short sample of this AM sinewave.
Since the carrier sinewave is in the audible range, you can listen to this signal as well.
Once this AM wave is demodulated, the baseband signal represents grey-scale levels of a
black and white image. The signal contains two images, each from a photo sensor of different
wavelength sensitivity. Two sensors of the following set are chosen by ground command:
Sensor Type
Spectral range (um.)
Silicon
0.55 - 0.9
Silicon
0.725 - 1.0
Indium Antimonide
3.55 - 3.93
Mercury Cadmium Telluride 10.5 - 11.5
Mercury Cadmium Telluride 11.5 - 12.5
For most daytime images, the first and third sensors are used to generate image data. To help
identify which image data comes from which sensor, each scan line of the image is preceded by a
short sync burst lasting 9.375 ms. Channel A modulates the carrier with a 1040 Hz. square wave
(7 cycles) during this time. Channel B modulates the carrier with seven pulses of 832 Hz.
modulation. Above, a channel-A sync can be seen in the middle third of the plot.
Immediately following the sync burst lies the minute marker, lasting 11.298 ms.
Following the minute marker is image data lasting 218.5 ms.
Channel A ends with 10.817 ms. of telemetry.
Channel B begins with 9.375 ms. of 832 Hz pulse modulation (sync burst).
Next comes 11.298 ms. of minute marker.
Next comes 218.5 ms. of image data from the other sensor.
Next comes 10.817 ms. of telemetry.
The Channel A + Channel B scans take exactly 0.5 seconds (0.25 seconds each). Then the
sequence is repeated (forever). This fraction of an image shows about 20 seconds of data from
channel A. This fraction of an image shows about the same 20 seconds of data from channel B.
In this case, channel A contains data from the Silicon sensor of 0.55 - 0.9 um. spectral range.
Channel B contains data from the Indium Antimonide sensor of 3.55 - 3.93 um. spectral range.
The rectangular area of the image is scanned using a raster format similar to that of a
television or computer monitor. The FAX image is scanned starting from the top of the page,
starting at the left edge. The scan follows a horizontal path from left to right, examining a very
small area of the page along that path. The gray level of this very small scanning area controls
the amplitude of the 2400 Hz. carrier wave.
After encountering the right edge of the page, a short "sync" pulse sequence of modulation
controls the carrier wave amplitude for a short time. Then another scan from left to right is
begun, slightly lower on the page than the previous scan, terminating with the short "sync" pulse
modulation sequence. The left-to-right scanning continues incrementally down the page to the
bottom. At the end, a unique sequence of modulation excursions signals the end of transmission.
DSP Lab facilities
A Pentium MX 200 MHz processor is to be used to develop and run your programs. An
Ensoniq sound card contains the analog to digital interface. The LINUX operating system has
been chosen for the code development environment, because the sound card interface is
relatively simple. The GNU "C" compiler gcc allows generic "C" or C++ to be compiled. You
should become familiar with the LINUX environment and any code development tools it
provides.
Other software tools that might be useful include gnuplot (plots data files and functions),
xoscope (an oscilloscope viewer of soundcard data), and various image viewers like XV, Gimp,
ImageMagik.
You may test your AM demodulator code on a laboratory signal source. Two function
generators are provided, one of which AM modulates the other. The resulting AM signal can be
monitored on an oscilloscope, and send to the "line" input of the sound card.
You may also wish to use previously recorded sound data to test your programs. noa.wav is a
file containing about 10 minutes of pre-recorded NOAA-14 satellite signal. This file will be used
to test your finished program.
Rendering Image data
The output of your program shall be bytes of gray or colour information in a format suitable as
input to a screen-rendering program. You need not write the screen-rendering code. There are
many simple image file formats that you may choose. For black and white images, the .pgm
(portable gray map) file format is recommended. It is very simple and is capable of dealing with
256 levels of gray. Details of this file format can be found by typing:
man pgm
on a command-line prompt.
AM Modulation
Amplitude Modulation (AM) is a process where the signal of interest (baseband) is combined
with a fixed amplitude cosine wave of higher frequency. In our case, the baseband signal
includes frequency components from zero Hz. up to about 1600 Hz. Our baseband signal has
been derived from the output of photo sensors which scans the surface of the earth. For the single
sensor that covers the visible range (from 0.55um. - 0.9um) a signal of zero amplitude
corresponds to darkness (BLACK), while a large amplitude corresponds to brightness (WHITE).
For infrared sensors, the baseband signal is reversed: BLACK corresponds to a large sensor
output, while WHITE corresponds to a small sensor output. Baseband signals must be
transmitted to a receiving site, and reproduced as levels of gray to reproduce the original image.
AM modulation allows the baseband signal to be transmitted through circuits that do not pass
DC voltages or currents. For example, the sound card has built-in filters that cut off below 20
Hertz, and cut off above 20000 Hertz. The sound card would fail to properly digitize the bare
baseband signal (which extends to zero Hz.), but can easily deal with a 2400 Hertz carrier that is
amplitude modulated with the baseband signal. Many receiving circuits, or recording media
suffer the same fault, and could not deal with a baseband signal that includes zero Hz.
Modulation solves this problem, and others.
The cosine carrier wave upon which the baseband modulation rides has a
precise fixed frequency of 2400 Hz. in our case. It appears here as a rotating
vector (rotating 2400 revolutions per second) of fixed amplitude Ca. In
amplitude modulation, the baseband signal is combined with this carrier in a
multiplication process, so that carrier amplitude Ca varies in proportion to
the amplitude of the baseband signal. Full modulation (modulation index of 100%) results when
a minimum modulating signal (in our case, BLACK level) causes the carrier amplitude Ca to be
zero . Maximum modulation (in our case, WHITE level) would drive the carrier level to twice
Ca.
For our modulation system, modulation never drives carrier Ca to zero amplitude. A
modulation index of 92% rather than 100% is used, so that a small amplitude carrier remains,
even for a baseband signal of zero. Having some carrier always present allows receiving systems
to track (phase lock) the carrier frequency Ca. The penalty for less than 100% modulation is a
degraded signal to noise ratio.
Spectrum Requirements for Amplitude Modulation
Let us consider the case where amplitude of the baseband signal fully modulates (modulation
index of 100%) the carrier wave. We shall consider a baseband signal of Ma cos (wm t). When
Ma = Ca, a modulation index of 100% results. To ensure that Ma remains always positive (equal
to, or less than 100% modulation index), we shall add a constant K = Ma = Ca. The modulating
signal is now K + Ma cos (wm t).
The output of the multiplying modulator is :
e(t) = (K + Ma cos (wm t) Ca cos (wc t)
This can be expanded to
e(t) = Ca cos (wc t) + ((K+Ma)/2) cos (wc + wm)t + ((K+Ma)/2) cos(wc - wm)t
The result of amplitude modulation is an unmodified
carrier wave, plus two half-amplitude replicas of the
baseband signal displaced from the carrier - one
above and one below. The complete AM signal
occupies a bandwidth from (wc - wm) to (wc + wm).
Multiplying the baseband signal with the carrier has
the effect of translating the baseband spectrum from
zero Hz. up to the carrier frequency wc.
Our baseband signal occupies a frequency space from
zero up to about 1600 Hertz. With a carrier frequency of
2400 Hertz, the total occupied bandwidth of the
amplitude modulated signal will be from 2400 - 1600 to
2400 + 1600 Hertz.
This signal in turn modulates a radio frequency
carrier of 137.5 MHz. (frequency modulation, FM) and
is transmitted to earth. A radio frequency receiver
amplifies and demodulates the FM signal. Output of the receiver is (ideally) the same as the
amplitude modulated signal described here. The last step in recovering the baseband signal is
amplitude demodulation.
AM Demodulation
Demodulation involves recovering the baseband signal from an amplitude modulated carrier.
In our case, we will be presented with discrete samples of the AM waveform. The algorithm
described below can work equally well in continuous time or discrete time.
We shall assume that our computer, like digital
signal processors, can time-efficiently multiply two
numbers and add (or subtract) two numbers. Division,
as well as all transcendental operations are not time
efficient. Any operators applied to discrete samples
would best use multiply and add (or subtract) over any
other. Scaling integers by any power-of-two (rotate) is
also a highly efficient operation.
Multiplying the input signal by sin(2PI 2400)t gives a two-component output: one at zero Hz.
and one at 4800 Hz. The component at zero Hz. contains desired baseband information, while the
4800 Hz. component is not desired. The desired baseband information can be separated with a
digital low-pass filter. The baseband component must fall within the filter's passband, while the
4800 Hertz component must fall within the filter's stopband.
This multiplying/filtering process is repeated with cos(2PI 2400)t.
Both sin and cos multiplying functions are required since the phase of the incoming carrier is
unknown. Had the incoming carrier been in phase with the multiplying sin(2PI 2400 t) function,
then the associated filtered output would be equal to the full, original baseband signal. With
unknown phase, the full, original baseband signal can be found from the magnitude vector sum
of the two filter outputs.
Unfortunately, vector addition involves an unavoidable square root - an expensive mathematical
operation. An approximation to this operation involving only addition and multiplication can be
done - provided you can accept the error involved. Another magnitude shortcut.
FIR, IIR Digital filters
The algorithm described above requires two identical low-pass filters. Input data to these two
filters is a discretely sampled stream of data, supplied by the sin(2PI 2400)t and cos(2PI 2400)t
multipliers. Input data rate is the same as the soundcard's data sampling rate. These two filters
should be identical, and could use the same subroutine pointing to different input data streams.
Major considerations in designing low pass filters are:
•
Pass band upper frequency limit
•
Stop band lower frequency limit
•
Minimum stopband attenuation permissible
•
Acceptable pass band ripple
•
Numerical precision required (for DSP filters) component tolerance required (analog
filters)
Pass band and stop band frequencies should be chosen based on the multiplier output spectrum
described above.
Spurious signals at the output of the low pass filter add noise to the desired baseband data. How
much noise is acceptable is a reasonable criteria for determining stopband attenuation. Original
baseband data (on board satellite) is limited to eight bit precision. Spurious output from the low
pass filter should therefore be suppressed by more than half of one part in 28. Acceptable
passband ripple could use a similar criteria, however, for simply viewing gray scale images, the
eye is very tolerant within the passband.
For any FIR or IIR filter you choose, you must choose coefficents and code the filter. There
are numerous web resources applets, and computer programs to aid you in this process.
Decimating Filters
Our baseband signal contain no frequency components above 1600 Hertz. Assuming that the
digital 1600 Hz. low pass filter is effective (so that no frequency components above 1600 Hertz
exist), output data rates no higher than 3200 samples per second are required. Output data may
be required at an even slower rate, depending on pixel size (and shape) and final image
resolution.
Data rates at the input to the low pass filter must be considerably higher, so that any spurious
high frequency components are not aliased back down into the filter's passband. Rather than
calculate an output data for every input data, some output data can be thrown away without
losing any essential information. Such a process is called decimation.
Filter output is only needed when a new output sample is required. The filter need not
calculate an output for every new input sample. In this situation FIR filters have an advantage
over IIR filters, since IIR filters must update internal states for every input sample. FIR filters
have no internal states , and can be applied to anycontinuous segment of the input data stream.
For example, let us assume that one output sample is required for every five input samples. An
FIR filter having 31 coefficients operates on the input data stream. The coefficients operate on
data [0...30], then operate on data [4...35], then on [8...39] etc.
Decimation saves calculation time by not processing unneeded samples. It can be applied
whenever maximum filter output data rate is lower than the input Nyquist data rate.
Analog to Digital Converter (Sound Card)
In our DSP setup, the sound card provides a stream of digital data representing an analog
waveform. Once initialized, data is continuously available from sound card -administered
memory buffers. Data is read by your program in a sequential manner, much like data from a
disk file.
Numerical Representation of an Analog Waveform
The sound card digitizes to either eight bit precision, or sixteen bit precision. Sixteen bit
number format is little-endian, with least significant byte at a lower address, followed by most
significant byte at the next higher address. Since "C" doesn't regard data size in a machineportable way, referring to data as "signed int" is non-portable. The closest (for the lab's PC
Linux system) number format would likely be "short int", which is automatically a signed
number. The most significant bit conforms to conventional 2's complement signed number
format, and data is suitably formatted for mathematical manipulation.
Eight bit data could be dealt with properly as "unsigned char". Before any mathematical
calculations with eight bit data, conversion to conventional signed numbers should be made, by
subtracting 128 (80 hex). Exclusive or-ing with 80 hex also works.
Waveform amplitude is unknown (set by mixer volume) -it is not calibrated to a particular
voltage or current level. The KDE mixer widget tool is an easy way to set signal source (line
input) and amplitude. You can use this tool to set input amplitude so that it lies within the
dynamic range of the digitizer. Should a sample exceed the range of the digitizer, either the most
positive number, or the most negative number will be substituted instead.
Data Representation
16-bit 8-bit
7fff
ff
7ffe
fe
7ffd
fd
....
...
0002
82
0001
81
0000
80
ffff
7f
fffe
7e
fffd
7d
....
...
8001
01
8000
00
Most positive
Next-to-most positive
Next-to-least positive
Least positive
Mid amplitude (amplitude of zero)
Least negative
Next-to-least negative
Next-to-most negative
Most negative
The analog waveform is sampled at equally spaced time intervals (determined at initialization
time). These samples are stored into memory buffers sequentially. You, the user of this data, may
ask for the "next" sample in sequence. Or you may request that a memory buffer be filled with
data, via a function call "read(void)". You should ensure that, on average, your requests for
data come faster than the sound card fills its buffers.
Buffer memory management is done for you in a similar way as file access. However, you
may request data not yet available. In this case, your request will result in a time delay while data
is digitized and sent to the memory buffer. This delay is transparent to you - every request for
data will eventually return with the next sequential datum. When the next digital sample is ready
before you request it, it is stored in a memory buffer, awaiting your request.
Sound Card Programming
Initializing the sound card cannot be done by manipulating IO registers directly - this is a job
reserved for the LINUX operating system. All functions of the sound card are manipulated
through the sound card "driver" defined in soundcard.h
Setting signal source, mono/stereo, sample rate, amplitude scaling, etc. is described in oss.pdf.
A sample program is shown below that initializes the sound card and collects some data into
memory.
Another very simple way to collect digitized data uses the unix "cat" command to connect the
digitized data stream from the sound card to the console:
cat /dev/dsp
You will see data scroll through the console until you hit "Cntl-C". If you wish to record this
raw data instead to a disk file, you could modify the cat command:
cat /dev/dsp foo.dat
File Format for Sound Card Data
You need not conform to any standard sound file format when recording or reading data from
disk. Recording sound card data can be as simple as:
cat /dev/dsp/ foo.dat
This command concatenates output from the /dev/dsp source (sound card) to a disk file
named foo.dat, at the default sample rate, and sample precision. Sampling continues until a
keyboard "Cntrl-C" hit breaks the process. Only raw data is stored in the disk file - data rate and
precision are not.
One suitable file format containing sampled data is the "xxxx.wav" type file. The "wav" file
format contains enough information to set up the sound card to play back audible data at the
proper sampling rate. A pre-recorded file (noaa.wav) contains over six minutes of eight-bit
mono data from the NOAA-14 satellite, sampled at 11025 samples per second. This file will be
used to test your finished AM demodulating program.
Sound Card Initializing Program (livedat.c)
/* Program demonstrating how to set up a soundcard for Analog-toDigital conversion. Setting amplitude, mixer is done by other
programs. Here, soundcard is set up to digitize one channel (left)
in linear 8-bit samples at a sample rate of 44100 samples per
second. Data is printed out to standard output (stdout). It can
be re-directed to a file - it is in a suitable format for plotting
by "gnuplot".
Documentation for soundcard setup is found in file "oss.pdf".
November 2000 Glen Leinweber
*/
#include <stdio.h
#include <sys/soundcard.h
#include <sys/ioctl.h
#include <unistd.h
#include <fcntl.h
#define BUF_SIZE 4096
int audio_fd;
/* a device number for audio I/O */
unsigned char audio_buffer[BUF_SIZE];
/*----------------------------------------------------------------*/
main() {
int
i, j;
int
format, no_channels, speed;
/* soundcard setup */
unsigned char *dbp;
/* open the audio device for reading
*/
if ((audio_fd = open("/dev/dsp", O_RDONLY, 0)) == -1) {
fprintf(stderr,"can't open /dev/dsp for reading\n");
exit(1);
}
format = AFMT_U8;
/* setup for unsigned 8-bit AtoD */
if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format) == -1) {
fprintf(stderr,"won't do 8-bit conversions\n");
exit(1);
}
no_channels = 1;
if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &no_channels) == -1) {
fprintf(stderr,"can't set single channel\n");
exit(1);
}
speed = 44100;
/* setup 44100 samples per second */
if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &speed) == -1) {
fprintf(stderr,"error setting sample rate\n");
exit(1);
}
/*---------------------------------------------------------------------*/
/* get sound data into a buffer, send it out to stdout */
dbp = audio_buffer;
if (read(audio_fd, dbp, 4096) != 4096) {
fprintf(stderr, "data not ready\n");
exit(1);
}
close (audio_fd);
dbp = audio_buffer;
for (j=0; j<4096; j++)
}
printf ("%d\n", audio_buffer[j]);
.WAV File Format
Digitized audio samples are stored, or played back using this very simple file format. No data
compression is used: audio data is stored in the "raw".
Three records describe the data:
1
The first record (twelve bytes) identifies the file as a ".wav" filetype, and it's length.
2
The second record (24 bytes) shows how the recording device was set up, including sample rate,
mono/stereo, number of bytes per sample.
3
The third record contains all the data samples.
Record 1 Identification:
Byte #:
1-3
"RIFF"
4-7
32-bit binary
8-11 "WAVE"
(four ascii characters)
total length of package
(four ascii characters)
Record 2 Soundcard setup.
12-15 "fmt "
16-19 32-bit binary
20,21 16-bit binary
22,23 16-bit binary
24-27 32-bit binary
28-31 32-bit binary
32,33 16 bit binary
(four ascii characters, ending in space)
(length of this record - most always 0x10)
(most always 0x01)
Channel number 0x01=mono, 0x02=stereo
Sample rate, Hertz (in binary)
bytes per second
bytes/sample 1=8-bit mono, 2=8-bit stereo or
16-bit mono, 3=nothing, 4=16-bit stereo
bits/sample 0x08=8-bit data, 0x10=16-bit data
34,35 16-bit binary
Record 3 Data
36-39 "data"
40-43 32-bit binary
44... data samples
(four ascii characters)
Length of data to follow
Example DING.WAV. distributed with windows:
246E:0100
246E:0110
246E:0120
246E:0130
246E:0140
52
10
01
80
80
49
00
00
80
80
46
00
08
80
80
46
00
00
80
80
46
01
64
80
80
2D
00
61
80
80
00
01
74
80
80
00-57
00-22
61-22
80-80
80-80
41
56
2D
80
80
56
00
00
80
80
45
00
00
80
80
66
22
80
80
80
6D
56
80
80
80
74
00
80
80
80
20
00
80
80
80
RIFFF-..WAVEfmt
........"V.."v..
....data"-......
................
................