CS 3291 Digital Signal Processing Barry Cheetham barryman
CS 3291: Digital Signal Processing Barry Cheetham barry@man. ac. uk www. cs. man. ac. uk/~barry/mydocs/CS 3291 Section 1: Introduction Sept '05 CS 3291 Section 1 1
• Signal: time-varying measurable quantity whose variation normally conveys information. • Quantity often a voltage obtained from some transducer e. g. a microphone. • It is useful to define two types of signal: • Continuous time (analogue) • Discrete time Sept '05 CS 3291 Section 1 2
• Analogue signals: continuous functions of time (t) measured in seconds. Exist for all values of t in range - to +. • Examples: (i) 5 sin(62. 82 t) : sine-wave of frequency 62. 82 radians/second ( 10 Hz) 0: t<0 (ii) u(t) = 1: t 0 • " step-function " signal. Graph of analogue signal against time gives continuous 'waveform' : Voltage 5 -0. 1 Sept '05 1 0. 1 t CS 3291 Section 1 t 3
• Discrete-time signals: exist only at discrete points in time. • Often obtained by sampling an analogue signal, i. e. measuring its value at discrete points in time. • Sampling points separated by equal intervals of T seconds. • Given analogue signal x(t), x[n] = value of x(t) when t = n. T. • Sampling process produces a sequence of numbers: {. . . , x[-2], x[-1], x[0], x[1], x[2], . . . } • Referred to as {x[n]} or ' the sequence x[n] '. • Sequence exists for all integer n in the range - to . Sept '05 CS 3291 Section 1 4
• Examples of discrete time signals: (i) {. . . , -4, -2, 0, 2, 4, 6, . . } sequence whose nth element, x[n], is defined by : x[n] = 2 n. Underline sample corresponding to n = 0. (ii) {. . . , -4. 75, -2. 94, 0, 2. 94, 4. 75, 4. 76, . . . } sequence with x[n] = 5 sin(62. 82 t) with t=n. T and T=0. 01. (iii) {. . . , 0, . . . , 0. 0, 1, 1, 1, . . . } “ unit step ” sequence whose nth element is: u[n] = 0: n<0 1: n 0 • Discrete time signals represented graphically as shown for example (i): Sept '05 CS 3291 Section 1 5
x[n] -3 -2 -1 2 - n 1 2 3 4 -2 - Sept '05 CS 3291 Section 1 6
MATLAB demonstration 1 To generate & plot 80 samples of a sine-wave: clear all; T = 0. 01; % sampling interval (seconds) % Generate 80 samples of a 10 Hz sine-wave of amplitude 5 % Need 5 sin(2*pi*10*t) with t=n. T for n=1, 2, . . . 200 for n=1: 80 s(n) = 5 * sin(2 * pi * 10 * n * T); end; plot (s); 5 0 -5 0 Sept '05 10 20 30 40 CS 3291 Section 1 50 60 70 80 7
• Discrete time signals often generated by ADC devices. • Produce binary numbers from sampled voltages or currents. • Accuracy determined by 'word-length ' of ADC device, i. e. number of bits available for each binary number. • Quantisation : Truncating or rounding sampled value to nearest available binary number • Resulting sequence of quantised numbers is a digital signal. . • Digital signal is discrete time signal with each sample digitised for arithmetic processing. Sept '05 CS 3291 Section 1 8
Signal Processing: • Analogue signals "processed" by circuits consisting of resistors, capacitors, inductors, transistors & operational amplifiers. • Digital signals "processed" using programmed computers, microcomputers or special purpose digital hardware. • Examples of the type of processing that may be carried out are: (i) amplification or attenuation. (ii) filtering : e. g. 'filtering out' some unwanted part of the signal. (iii) rectification : making waveform purely positive. (iv) modulation : multiplying signal by another signal, e. g. a high frequency sine wave. Sept '05 CS 3291 Section 1 9
MATLAB demo 2: Store 500 Hz sine-wave block in file clear all; fs = 8000; %sampling rate in Hz T = 1/fs; % sampling interval (seconds) % Generate 10000 samples of 500 Hz sine-wave: for n=1: 10000 s(n) = 4000 * sin(2 * pi * 500 * n * T); end; % Store in a non-formatted (binary) file: - OFid=fopen('newsin. pcm', 'wb'); fwrite(OFid, s, 'int 16'); fclose('all'); Sept '05 CS 3291 Section 1 10
MATLAB demo 3: Amplify sine-wave clear all; %Input from file: fs = 8000; % sampling rate in Hz IFid=fopen(’newsin. pcm', 'rb'); Insin = fread(IFid, 'int 16'); %Amplify by 6 d. B: for n=1: 10000 Outsin(n) = 2 * Insin(n); end; % Output to a file OFid=fopen('newop. pcm', 'wb'); fwrite(OFid, Outsin, 'int 16'); fclose('all'); Sept '05 CS 3291 Section 1 11
MATLAB Demo 4 Filtering speech clear all; %Input speech from a file: fs = 8000; % sampling rate in Hz IFid=fopen('operamp. pcm', 'rb'); Inspeech = fread(IFid, 'int 16'); %Design FIR digital filter: fc = 1000; % cut-off frequency in Hz [a b] = fir 1(20, fc/(0. 5*fs) ); freqz(a, b); %Process speech by filtering: Outspeech = filter(a, b, Inspeech); % Output speech to a file OFid=fopen('newop. pcm', 'wb'); fwrite(OFid, Outspeech, 'int 16'); Sept '05 CS 3291 Section 1 fclose('all'); 12
0 Magnitude (d. B) -20 -40 -60 -80 -100 0 0. 1 0. 2 0. 3 0. 4 0. 5 0. 6 0. 7 0. 8 Normalized Frequency ´ ( rad/sample) 0. 9 1 Phase (degrees) 0 -200 -400 -600 -800 -1000 0 Sept '05 CS 3291 Section 1 13
MATLAB Demo 5: Listen to speech in a file IFid=fopen('newop. pcm', 'rb'); speech = fread(IFid, 'int 16'); maxamp = max(abs(speech)); SOUND(speech/maxamp, 8000, 16); fclose('all'); Sept '05 CS 3291 Section 1 14
MATLAB demo 6 : Rectify sine-wave clear all; %Input from file: fs = 8000; % sampling rate in Hz IFid=fopen(’newsin. pcm', 'rb'); Insin = fread(IFid, 'int 16'); %Full-wave recify: for n=1: 10000 Outsin(n) = abs ( Insin(n) ) ; end; % Output to a file: OFid=fopen('newop. pcm', 'wb'); fwrite(OFid, Outsin, 'int 16'); fclose('all'); Sept '05 CS 3291 Section 1 15
Using MATLAB more efficiently for n=1: 10000 Outsin(n) = 2*Insin(n); end; Slow Faster for n=1: 10000 Outsin(n)=abs(Insin(n)); end; Sept '05 Outsin = 2*Insin; CS 3291 Section 1 Outsin = abs(Insin); 16
MATLAB exercise 1: Modulation Generate 320 samples of a 50 Hz sine wave sampled at 8 k. Hz and multiply this by by a 1 k. Hz sine wave sampled at 8 k. Hz. Plot the resulting waveform MATLAB exercise 2 : Simulate POTS speech quality A ‘plain old fashioned telephone’ transmits speech between 300 Hz & 3 k. Hz. Design & implement high- & low- filters to allow the effect of the band-width restriction to be assessed by listening. Sept '05 CS 3291 Section 1 17
Solution to MATLAB Exercise 1 clear all; fs = 8000; T=1/fs; for n=1: 320 s 50(n) = sin(2*pi*50*n*T); end; figure(1); plot (s 50); for n=1: 320 smod(n) = s 50(n)*sin(2*pi*1000*n*T); end; figure(2); plot (smod); 1 0. 8 0. 6 0. 4 0. 2 0 -0. 2 -0. 4 -0. 6 -0. 8 -1 0 Sept '05 50 100 150 200 250 CS 3291 Section 1 300 350 18
% A solution for MATLAB Exercise 2 clear all; %Input speech from a file: fs = 8000; % sampling rate in Hz IFid=fopen('operamp. pcm', 'rb'); Inspeech = fread(IFid, 'int 16'); %Design FIR band-pass digital filter: f. U = 3000; % upper cut-off freq Hz f. L = 300; % lower cut-off freq [a b] = fir 1(100, [f. L/(0. 5*fs) f. U/(0. 5*fs)] ); freqz(a, b); %Process speech by filtering: Outspeech = filter(a, b, Inspeech); % Output speech to a file OFid=fopen('newop. pcm', 'wb'); fwrite(OFid, Outspeech, 'int 16'); Sept '05 CS 3291 Section 1 fclose('all'); 19
WARNING • If you do experiments and listen to the output generated, be careful not to expose yourself to high levels of sound. • Avoid listening to sinusoids except at very low volume using speakers (Do not use headphones for sine-waves). • Avoid the use of headphones with such experiments. • Do not risk damage to your hearing. • And/or falling out with your neighbours. Sept '05 CS 3291 Section 1 20
Applications of DSP: • ’Real time' processing : • A mobile phone contains 'DSP' processor fast & powerful enough to perform the mathematical operations required to filter digitised speech as it is being received. • ‘Non real time’ processing: • A PC can perform DSP processing on a stored recording of music & can take as much time as it needs to complete this processing. • Non real time DSP useful in its own right; e. g for MP 3 compression. • Also used to 'simulate' software for real time DSP systems before they are built into special purpose hardware, say for a mobile phone. • Simulated DSP systems may be tested with stored segments of speech. Sept '05 CS 3291 Section 1 21
• Real time DSP often uses 'fixed point' microprocessors since they consume less power & are less expensive than 'floating point' devices. • A fixed point processor deals with all numbers as integers. • Numbers often restricted to a word-length of only 16 bits. • Overflow can occur with disastrous consequences to sound quality. • If we avoid overflow by scaling numbers to keep them small in amplitude, we lose accuracy as quantisation error is larger proportion of the value. • Fixed point DSP programming can be quite a difficult task. • When we use a PC for non real time DSP, we have floating point operations available with word-lengths that are larger than 16 bits. • This makes the task much easier. • When simulating fixed point real time DSP on a PC, we can restrict programs to integer arithmetic, & this is useful. Sept '05 CS 3291 Section 1 22
Examples of signals commonly processed in digital form: • Speech, as encountered in telephony, for example. • Biomedical signals such as heart signals & “brain waves”. • Sound & music. • Video & images. • Radar & sonar signals. Sept '05 CS 3291 Section 1 23
• • • Advantages of DSP: More & more signals are being transmitted & stored in digital form so it makes sense to process them in digital form also. DSP systems can be designed & tested in simulation using PCs. Accuracy pre-determined by word-length & sampling rate. Reproducible as every copy of DSP system will perform identically. Characteristics of system will not drift with temperature or ageing. Availability of advanced VLSI technology. DSP systems can be reprogrammed without changing hardware. Products can be updated via Internet. DSP systems can perform functions that would be extremely difficult or impossible in analogue form; e. g. adaptive filtering speech recognition. Sept '05 CS 3291 Section 1 24
Disadvantages of digital signal processing: • DSP designs can be expensive especially for high bandwidth signals where fast analogue/digital conversion is required. • Design of DSP systems can be extremely time-consuming & a highly complex and specialised activity. There is an acute shortage of computer science and electrical engineering graduates with the knowledge and skill required. • Power requirements for digital processing can be high, thus making it unsuitable for battery powered portable devices. Fixed point processing devices are available which are simpler than floating point devices and less power consuming. However the ability to program such devices is a particularly valued and difficult skill. Sept '05 CS 3291 Section 1 25
• Some processes, e. g. amplification, & filtering, are linear. • Processes may also be time-invariant. • Processes which are both linear & time-invariant are LTI. • Consider impulse-responses of such LTI systems. • Leads to frequency-response & system function • These come from the Fourier, Laplace and z-transforms, and are all related to 'convolution'. • These concepts allow us to: (i) analyse effects of LTI systems on analog & digital signals, (ii) understand & employ design methods for such systems. Sept '05 CS 3291 Section 1 26
GAIN Gain-response of a low-pass filter may be derived from its frequency-response 1 f. C Sept '05 CS 3291 Section 1 FREQUENCY 27
• Modern signal processing often programmed on ‘DSP’ microprocessors which are fast enough to compute each output in "real time". • Consider how a DSP processor differs from a Pentium IV ? • Analogue signals must be converted into digital form and vice-versa. • Effects of sampling, ADC & DAC studied in this course. • Also the Fast Fourier transform (FFT) & its many applications, including spectral estimation. Sept '05 CS 3291 Section 1 28
Summary of Course Objectives: 1 Importance of DSP, its jargon, & meaning of real time processing. Advantages/disadvantages. Analogue, discrete time & digital signals. Sampling & quantisation in general terms. 2. Brief review of analogue & digital signal processing systems, Transfer function and frequency-response of an analogue filter. Low-pass and band-pass analogue filters. Butterworth low-pass gain response approximation. 3. Discrete LTI signal processing systems. Recursive & non-recursive difference equations. Signal flow-graphs & their implementation by computer programs. Impulse-response for discrete time systems. FIR & IIR type digital filters. Stability and causality. Time-domain convolution. Frequency response & DTFT. Gain and phase responses. Linear phase and group delay. Inverse DTFT. Use of MATLAB for analysing the frequency-response of digital filters. Sept '05 CS 3291 Section 1 29
4. Design of FIR digital filters by windowing method & alternative methods. 5: Introduction to z-transforms & IIR type discrete time filters System function, H(z), as z-transform of impulse response. Relationship between system function, difference equation, signal flow-graph & software implementation of FIR and IIR type digital filters. Poles and zeros & distance rule. Design of a digital IIR "notch" filter and a resononator by pole/zero placement. Application to these filters to sound recordings. 6: Design of IIR type digital filters using analogue filter approximations Derivative approximation & bilinear transformation & other methods. 7: Digital processing of analogue signals and other data Sampling theory, aliasing, effect of quantisation and, sample and hold reconstruction. Oversampling to simplify analogue filters. . 8. Introduction to the DFT Relation to DTFT. Inverse DFT. Effects of windowing & frequency domain sampling. Implementation by the ‘FFT’ algorithm (FFT). Use of DFT and FFT for spectral estimation. 9. Use of MATLAB for implementing digital filters & FFT. Sept '05 CS 3291 Section 1 30
Background knowledge needed: Basic maths ( complex numbers, Argand diagram, modulus & argument, differentiation, simple integration, sum of an arithmetic series, complex roots of unity, factorisation of quadratic equation, De Moivre's Theorem, exponential function, natural logarithms). Experience with any high-level computer programming language. Material from the 2 nd Yr Course CS 2232: Signals & Systems useful. Sept '05 CS 3291 Section 1 31
Recommended Book: 1. S. W. Smith, "Scientist and Engineer's Guide to Digital Signal Processing " California Tech. Publishing, 2 nd ed. , 1999, available complete at: http: //www. dspguide. com/ Sept '05 CS 3291 Section 1 32
Problems: 1. Why do we call continuous time signals “analogue”. 2. When could you describe a SIGNAL as being linear? 3 Give a formula for an analogue signal which is zero until t=0 and then becomes equal to a 50 Hz sine wave of amplitude 1 Volt. 4. Given that u(t) is an analogue step function, sketch the signal u(t)sin(2. 5 t). 5. If u(t)sin(5 t) is sampled at intervals of T=0. 1 seconds, what discrete time signal is obtained? What is the sampling frequency? 6. What is the difference between a discrete time signal and a digital signal? 7. Define (i) amplification, (ii) filtering, (iii) rectification and (iv) modulation. 8. From the types of signals listed as being commonly processed by DSP, choose one & describe a form of DSP processing which may usefully be applied to it. 9. Are there advantages of DSP other than those listed. 10. Give one further possible disadvantage of DSP? Sept '05 CS 3291 Section 1 33
11. What is meant by “fixed point” and “floating point”? 12. What does the term “filter” normally mean to a Computer Scientist? Explain the terms “analogue filter” and “digital filter”. 13. What is meant by the term “real time” in DSP? 14. Think of an application of DSP where the processing of a digitised analogue signal need not be carried out in real time? 15. There are many applications of DSP where the digital signal being processed is not obtained by sampling an analogue signal. Give some examples. 16. Give modulus &argument of the complex numbers: 3+4 j and -3 e 4 j. Plot these numbers on an Argand diagram & calculate the distance between them. 17. Analogue signal: x(t) = 4 cos( t) is passed through a circuit that differentiates it with respect to t. Give formula for output. Plot amplitude & phase of the sinusoid obtained against in range 0 to 20 radians/second. 18. Analogue signal: x(t) = 4 cos( t) is passed thro’ circuit that integrates it with respect to t. Give formula for output & plot its amplitude & phase against . 19. Sum the geometric series: 1 + e-j + e-2 j + e-3 j + … + e-Nj. 20. Sum the infinite geometric series: 1 + 0. 9 e-j + 0. 81 e-2 j + 0. 729 e-3 j + … Sept '05 CS 3291 Section 1 34
21. Show that 1 + e-j = 2 e-j /2[cos( /2)] and hence plot the modulus & argument of this complex number against in the range 0 to . 22. Find the roots of: x 2 + 0. 9 x + 0. 81 = 0 in polar (modulus & argument) form. 23. The Fourier series for a periodic signal x(t) with period radians/s can be written in 3 forms: cos & sin form, amplitude & phase form & exponential form. If x(t) = 1+sin t-(1/2) cos(2 t)-(1/3)sin(3 t) +(1/4)cos(4 t) +(1/5)sin(5 t)- … convert this to each of the other two forms. 24. Fourier transform of analogue signal x(t) is complex function of frequency (in radians/second) referred to in many textbooks as X(j ). Some books call this X( ) & most Comms books use f (freq in Hertz) rather than . Give formulae for analogue Fourier transform & its inverse using these 3 forms of notation. 25. Show that if x(t) is real, then X(-j ) = X*(j ) or in other notation X(- ) = X*( ) or X((-f)) = X*((f)). Why do we need negative frequencies? 26. An nth order analogue Butterworth low-pass filter has the gain-response: G( ) = 1 / (1 + ( / C )2 n ). Show that its gain is 0 d. B at =0 & -3 d. B at = C. Show that gain at = 10 C for 6 th order Butt low-pass filter is -120 d. B. 27. Given sinusoid of frequency , if filter A attenuates it by 20 d. B & filter B amplifies it by 50 d. B, is it true that if x(t) is passed thro’ filter A and the output from filter A is passed through filter B, the overall gain would be 30 d. B? Sept '05 CS 3291 Section 1 35
Sept '05 CS 3291 Section 1 36
- Slides: 36