![]() CE.adsp: Laboratory 1 | |||||||||||||||||||||||||||||||||||
Instructions for the first laboratory - MatlabYou're not expected be able to finish all the laboratory exercises in the time available, so just try to get as much out of it as you can. Please ask one of us if you get stuck on anything.
Getting startedBefore you begin your Matlab session, you'll want to create a directory in your home directory where you can store any programs and data that you use. At the command prompt (i.e., in a terminal window), type "mkdir matlab" which you can see listed with the ls command in Linux/Unix. You can enter this directory as in DOS, with "cd matlab". To start Matlab, type "matlab &" at the prompt (& will leave the command window active). Once Matlab has fired up, there are a number of resources available to you:
Scripts and functions can be edited either in the Matlab editor or using a standard text editor. For example, to edit a file called sigdemo1.m, simply type "edit sigdemo1" in the Matlab command window, or you could use gedit from within your original terminal window: "gedit yourfile.m &". To run a script (a .m file containing a list of instructions), just enter the filename without its extension into the Matlab command window: e.g., "sigdemo1". 1. FundamentalsIf you are new to Matlab, click on the Help menu (see toolbar) and then click on "Demos", that is, [Help | Demos]. This will give you an idea to some of Matlab's capabilities. If you have some experience with the signal processing toolbox, proceed to section 2; experts, please go on to section 3 or invent your own variations of the parts that interest you most. 1.1 DemonstrationsType "sigdemo1" at the Matlab command prompt, and investigate the spectra produced by some common signals. This demonstration also allows you to see the effects of different window functions on the resultant spectra. Type "phone" at the prompt to see an example of a simple coder. 1.2 Generate a sine waveThere are (at least!) two ways to work in Matlab. The first, and simplest, involves entering commands directly at the command prompt. Let's begin by setting the sample rate to 100 Hz: "Fs = 100". Matlab will respond with the variable Fs and echo its value of 100. To suppress this response, which can become annoying with vectors and matrices of data, put a semicolon at the end of the line. Next, define a time vector with which to sample the waveform, running from 0 s to 1 s in steps of 1/Fs: t = (0:1/Fs:1)';The notation A:B:C denotes a row vector of numbers that run from A to C, spaced by increment B. The transpose symbol ' converts a row vector into a column vector, and vice-versa. The sine wave is then defined in the form A sin(wt), where w is the angular frequency: "y = 2*sin(2*pi*10*t);" and this can be plotted in x-y form using "plot(t,y)". The second way of programming in Matlab is to create a text file using the editor. By listing commands in a script file, we can get Matlab to execute them as if they were entered at the command prompt. Type "edit" and then enter the following text (you can ignore anything after "%", which indicates a comment): Now save the file with a suitable name (not fogetting the .m extension), and run the program by entering its name at the prompt. 1.3 Display the spectrumAdd the following lines of code to your text file, and run it to display the spectrum of the sine wave: Try changing the sampling frequency and the amplitude and frequency of the sine wave. 1.4 Using a square waveRepeat the previous two exercises using a square wave, instead of a sinusoid. Use the help window to find the command (if you can't guess it!). 1.5 Low-pass filteringUse the commands "fir1", "freqz" and "filter" to design a low-pass filter that will convert the square wave back into a sine wave. Think carefully about the filter order and its cut-off frequency. Note that Matlab uses normalised frequencies in its filter specifications, so the cut-off frequency must be divided by the Nyquist frequency (viz., half the sampling frequency). Examine the effects of varying these parameters, the order and cut-off frequency. Try, and investigate the differences, of using different window functions in "fir1", such as boxcar (rectangular), bartlett (triangular), hamming, blackman, etc. 2. Speech processingThis section applies some signal processing techniques to a speech waveform. An example file can be saved by right-clicking over the following link: speech.wav. You can load the contents of this file into Matlab using wavread (conversely, you can save a waveform to file with wavwrite): [y,Fs] = wavread('speech.wav'); Voiced speech is strongly periodic, since tension of the vocal cords is adjusted by the larynx so that they vibrate in a fairly regular fashion. During unvoiced speech, the lungs force air through constrictions within the vocal tract which produce turbulence. An example is the /s/ sound (fricative) at the beginning of the word "speech". 2.1 Pitch period from time domainFind a section of voiced speech in your waveform, and copy it to a smaller array. Observe the pitch pulses and estimate the pitch period of the voiced speech from the waveform. The pitch period in human speech typically lies in the range 4-20 ms. 2.2 Formants from spectral envelopeExamine the spectrum of the 30 ms window of speech and estimate the formant frequencies. First draw an imaginary line joining the peaks of the spectrum to form a spectral envelope. Then look for humps in this envelope and estimate their centre frequencies. These are known as the formant frequencies. Formants are caused by resonances in the vocal tract, and there should be about five of them in the first 5 kHz. 2.3 Pitch period from autocorrelationLow-pass filter the voiced speech, with a cut-off frequency of 800 Hz, the examine the results of the autocorrelation function xcorr, with maxlags set to 100. Observe the maximum correlation after the zeroth lag (remember that the zeroth lag corresponds to 100, in this case, since the autocorrelation function is symmetrical about maxlags). Re-estimate the pitch period from the autocorrelation function, and compare it to the one you obtained from the time waveform. 2.4 Linear predictive analysisNow, find the spectral envelope using linear prediction (see lpc), and compare it to the original spectrum. Think about the order of your filter and see the effect of varying it. The following commands may help you, where a is a vector of LPC coefficients: The excitation may be observed by filtering with an analysis filter. The output of this filter is known as the residual. If the autocorrelation function is then performed on the residual, the pitch pulse is more clearly visible, since the harmonics previously enhanced by the formants have now been suppressed. Reconstructing the frame of speech (synthesis) is achieved by passing the residual through an all-pole model (synthesis filter), which is simply the inverse of the analysis filter. 2.5 Real cepstrum
3. Advanced exercises3.1 FIR Wiener filterUsing the block diagram shown in Figure 1, design a 40th-order Wiener filter for the aplpication of noise cancellation (see also section 3.3, below), where W = R-1pand v(n) is the noise source (reference), v'(n) corrupting noise, s(n) signal of interest (say, a sine wave), and u(n) is the signal plus noise input signal.
3.2 Hartley transform
3.3 Adaptive line enhancementAdaptive line enhancement (ALE) refers to the case where a noisy signal u(n), consisting of one or more sinusoidal components s(n), is available and the requirement is to remove the noise part of the signal v(n). This may be achieved by the arrangement of Figure 2, below. It consists of a de-correlation stage, symbolised by z-Δ and an adaptive predictor. The decorrelation stage attempts to remove any correlation that may exist between the samples of noise, by shifting them Δ samples apart. As a result, the predictor can only make a prediction about the sinusoidal components of u(n), and when adapted to minimise the output mean-squared error (MSE), the line enhancer will be a filter tuned to those sinusoidal components.
See if you can use the LMS algorithm to control a 40th-order FIR filter to enhance a 100 Hz sine wave corrupted by noise. You might find it informative to plot the frequency response of the filter at each iteration, and then finally display the output plotted over the input, for comparison.
Tips and sources of extra help
If you have any other specific questions outside of the lab, you can email me, and I'll do my best to respond swiftly. |
![]() Dept. |
[
Home |
People:
Ted,
Philip |
Labs:
1,
2 ]
© 2002-5, maintained by Philip Jackson, last updated on 29 June 2005. |
![]() School |