Vous êtes sur la page 1sur 10

CE121 Experiment No.

3: Audio Signal Processing


Written by R. Palaniappan rpalan@essex.ac.uk; updated December 2009.

This experiments aims to give you an introduction to audio signal processing using two software: Audacity
and MATLAB. In the first part, you’ll be asked to complete a sequence of steps using GUI based Audacity
(Part A, which will give you a basic understanding on the concepts) and then move on to using MATLAB
(Part B), a more powerful software. Finally, you are given a voice signal conditioning and word
segmentation task (Part C), which you need to complete and submit a brief report.

Part A

Start Audacity

1. Recording - Ensure your microphone is turned on/set-up properly. Record the following by speaking
into the microphone: ‘I like Computer Systems Engineering’. You should be able to see the blocks of
waveform that corresponds to each letter. Play the waveform.

2. Do segmentation - remove the beginning and end parts and leave only the speech parts of the
waveform. Use cut (or copy) and paste tool.

3. Save (i.e. export) the file as Wav format with filename cse.wav.

4. Perform spectral analysis - select the waveform and click Analyze -> Plot Spectrum (Do not worry
about the other options such as windows, etc for now)
The resulting figure shows a frequency analysis of the waveform. Now what is frequency?
Frequency is the number of cycles per second, measured in Hz. For example, for the following
sawtooth signal recorded for 0.5 seconds, what is the frequency?

t (s)
0.5

Figure 1: Sawtooth signal

There are 4 cycles in a 0.5 second period, so in 1 second, we’ll have eight cycles, hence the
frequency is 8 Hz but how strong is this 8 Hz component? For this purpose, we can use spectral
analysis where one commonly used spectral analysis is Fourier method. To illustrate the concept of
frequency analysis further, let us generate a few artificial signals.

5. Generate 5000 Hz sinusoidal signal (i.e. wave) for 1 second with amplitude 1.0. Click Generate ->
Tone.

6. Obtain the spectrum. You should be able to see a peak at 5 kHz.


Page | 1
7. Now, create another 12000 Hz sinusoidal signal for 1 second with amplitude 0.5.

8. Select both signals and obtain the spectrum. You should be able to see two peaks, one at 5 kHz and
another at 12 kHz. But what about the magnitude values of the peaks? Move the cursor to the peaks
and you’ll be able to see that the peaks have a magnitude of 9 dB and 3 dB. Now what is decibel
(dB)? It measures the amplitude relative to a specified or implied reference level but using a
logarithmic scale. Since it expresses a ratio of two quantities with the same unit, it is a dimensionless
unit. A decibel is one tenth of a bel (B).

A 
dB = 20 log10  1  .
 A2 

Consider, a signal that is twice in amplitude of the another signal,

dB = 20 log10 (2 ) = 6.02 ,
which is why the peaks of the two sine waves have a difference of 6 dB (note: a division in
amplitude is a difference in logarithmic scale).

9. Amplify the 12 kHz signal by 6 dB (Click Effect – Amplify). Can you see that the amplitude of the
signal ranges from 1.0 to -1.0. Obtain the spectrum for both the signals. Can you see that both the
peaks of 5 kHz and 12 kHz signals are 9 dB. Show this to a demonstrator before continuing.

10. Attenuate the 12 kHz signal by 3 dB (repeat the procedure above but use -3 dB), what happens – can
you see the amplitude of the signal ranges from 0.7 to -0.7 rather than 1.0 to -1.0? This is since
dB = 20 log 10 (0.7 ) ≈ 3
Now, obtain the spectrum for both the signals – can you see the peaks at 9 dB and 6 dB?

11. Generate white noise (Click Generate->White noise) for one second. Obtain the spectrum for both
the white noise only – can you any distinct peak? No, because white noise has components from all
frequencies, hence the spectrum is flat. It is opposite to coloured noise, which has components from
certain frequencies only.

12. Now, let us look at the effects of filtering. Select the 12 kHz signal. Click Effect-Low Pass Filter and
key in the cut-off frequency as 3 Hz. You should be able to see that the 12 kHz sine wave is now a
line with zero amplitude. Plot the spectrum for this signal, can you see a small peak with -60 dB (i.e.
very low amplitude). The use of a low-pass filter (LPF) has cut-off any signal higher than 3 Hz.
We’ll look at filtering further again when we use MATLAB software. Show this to a demonstrator
before continuing.

13. Let us go back to the recording voice signal. Close all the waveforms. Change the sampling rate to
1000 Hz by clicking Project rate -> Other (bottom left of the screen). Now, record: ‘I like Computer
System Engineering.’ Play the waveform. What happened? Before we can understand what
happened, we need to know what are analogue-to-digital conversion and sampling.

Page | 2
Voice signals are analogue signals and the analogue signal form the microphone is converted to
digital signal by the sound card in the PC and the Audacity software captures this digital signal.

This process is known as analogue to digital (A/D) conversion, which involves mainly sampling (for
now, we’ll skip the other parts like quantization and coding).

Sampling (see Figure 2):


- Done by taking samples at specific uniform intervals of time
- The sampling interval is the time of one of these uniform intervals
- Sampling frequency (rate) is the number of uniform time intervals in one second

Analogue signal Digital signal

t t t

Figure 2: Sampling process

What happened to the recorded signal was that we used a too low sampling frequency (see the Figure
3) and as such, not enough digital data were obtained from the analogue signal (this is known as
aliasing problem). For most purposes, human speech is around 300 to 4000 Hz and Nyquist theorem
states that in order to faithfully represent the analogue signal digitally, the minimum sampling
frequency should be twice that of the highest frequency in the signal, so in the case of voice, we
should at least sample at 8000 Hz.

Figure 3: Aliasing problem – effects of low sampling frequency

14. Change the sampling frequency to 8000 Hz. Record: ‘I like Computer Systems Engineering’ and
play back the waveform. You should be able to hear it properly this time.

15. Close all the waveforms. To show that you can’t hear a 20 Hz signal, generate a one second sine
(tone) wave with frequency of 20 Hz (and amplitude of 1.0) and play back the signal. Can you hear
it? Now, try with a 500 Hz sine wave – you should be able to hear the annoying tone! Show this to a
demonstrator before continuing.

Page | 3
Part B

Read the MATLAB introduction and try out the examples (especially sections M1 – M7). Using MATLAB,
do the following:

1. Recording audio signals


Ensure your microphone is turned on/set-up properly. Type the following:
>> Fs = 8000;
>> y = wavrecord(5*Fs, Fs);
Immediately speak into the microphone: ‘I like Computer Systems Engineering’. The recorded
signal is now stored in variable y. Fs is the sampling frequency of 8000 Hz.

2. Playback of recorded signals


Play the recorded waveform by typing:
>> wavplay(y, Fs);
You should be able to hear the recorded signal.

3. Plot the speech waveform


Plot the signal by typing:
>> plot(y);
In the figure, you should be able to see the blocks of waveform (perhaps more than one) that
corresponds to each word.
Show this to a demonstrator before continuing.

4. Saving the signal


Save the file in MATLAB format with filename cse.mat:
>> save cse.mat y

5. Performing spectral analysis (i.e. obtaining the frequency content)


Type:
>> psd (y)
The y axis of the figure is power spectral density (i.e. power per unit frequency) in dB, while the x
axis of the figure is in normalised frequency. Before we look into what is normalised frequency, let
us generate an artificial signal.

6. Generating an artificial signal


Generate 10 Hz sinusoidal signal (i.e. wave) for 1 second with amplitude 1.0 and sampling
frequency of 100 Hz.
>> i=1:100; f1=10; Fs=100;
>> y=sin(2*pi*f1/Fs*i);
>> plot(y);

7. Obtaining the power spectrum.


>> psd(y);
You should be able to see a peak (about 12.2 dB, use magnifier if necessary) at 0.2 in the abscissa
axis – but is this correct? Should you not get one at 10 Hz? The psd function in Matlab plots the
abscissa scale using normalised frequency from 0 to 1. A scale of 0 to Fs/2 (i.e. half sampling

Page | 4
frequency) is represented as 0 to 1. So, 10 Hz is represented as 10/50=0.2. Show this to a
demonstrator before continuing.

8. Signal amplification
Now, amplify the signal by two times and obtain the spectrum
>> y2=y*2;
>> psd(y2);
Can you see a peak at about 18.2 dB? See the notes in Part A – 6 dB corresponds to twice the
amplitude, right?

9. White noise generation


Next, generate white noise for one second (there would be 100 points, assuming sampling frequency
of 100)
>> noise=rand(1,100);
Obtain the spectrum for the white noise (using the psd function) – can you any distinct peak in the
positive dB range? No, because white noise has components from all frequencies, hence the
spectrum is ‘relatively’ flat. It is opposite to coloured noise, which has components from certain
frequencies only. Show this to a demonstrator before continuing.

10. Filtering effects


Let us look at the effects of filtering. In general, there are four types of filters: LPF, high-pass filter
(HPF), band-pass filter (BPF) and band-stop filter (BSF).

Low-pass filter (LPF)


Passes all low-frequency components below the cut-off frequency, fc and blocks all higher frequency
components above fc .Eg: Consider a combination of 3 sinusoidal signals, 2 Hz, 5 Hz and 11 Hz. The
final output signals after LPF at fc=8 Hz and fc=3 Hz are shown:

Page | 5
High-pass filter (HPF)
Passes all high-frequency components above the cut-off frequency, fc and blocks all lower frequency
components below fc .Eg.: Consider the same combination of 3 sinusoidal signals, 2 Hz, 5 Hz and 11
Hz. The final output signals after HPF at fc=3 Hz and fc=8 Hz are shown:

Band-pass filter (HPF)


Passes all frequency components between edge passband frequencies, fp1<freq(allow)<fp2 and blocks all
frequencies below and above edge stopband frequencies, freq(block)<fs1; freq(block)>fs2.Eg.: Consider the
same combination of 3 sinusoidal signals, 2 Hz, 5 Hz and 11 Hz. The final output signal after BPF at
fp1=4 Hz, fp2=6 Hz, fs1=3 Hz, fs2=7 Hz is shown:

Page | 6
Band-stop filter (BSF)
Passes all frequency components lower and higher than edge passband frequencies, freq(allow)<fp1;
freq(allow)>fp2 and blocks all frequencies between fs1<freq(block)<fs2. Eg.: Consider the same
combination of 3 sinusoidal signals, 2 Hz, 5 Hz and 11 Hz. The final output signal after BSF at fp1=4
Hz, fp2=6 Hz, fs1=3 Hz, fs2=7 Hz is shown

11. Sine wave generation


Generate three sine waves, each with frequency 2 Hz, 5 Hz, and 11 Hz (with sampling frequency of
100 Hz) each with ten second length.
>> i=1:1000; Fs=100; f1=2; f2=5; f3=12;
>> y1=sin(2*pi*f1/Fs*i);
>> y2=sin(2*pi*f2/Fs*i);
>> y3=sin(2*pi*f3/Fs*i);
>> z=y1+y2+y3;
>> plot(z); % this is how to insert comments using %
>> psd(z); % you should see three peaks corresponding to frequencies: 2, 5 and 12
Show this to a demonstrator before continuing.

12. LPF filtering


Design a LPF (using Butterworth digital filter, don’t worry about why we use this filter for now) to
cut-off at 3 Hz, we first need to obtain a set of coefficients and then use these coefficients to perform
filtering.

Note that [B, A] = butter(10, Wn) designs a 10th order lowpass digital Butterworth filter and returns
the filter coefficients B and A. The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0
corresponding to half the sample rate.

Page | 7
>> [B,A]=butter(10, 3/50); % use 10th order, don’t worry about the order for now
>> LPFz=filtfilt(B,A,z); % do filtering
>> plot(LPFz) %can you see that only the 2 Hz signal remains
>> psd(LPFz) %you will only see a peak for 2 Hz signal
Show this to a demonstrator before continuing.

13. Other filtering operations


Try the HPF, BPF and BSF as given in the examples above and see if you can get the same answer
as shown in the diagrams.

For other filters: HPF, BPF and BSF, use the following:

[B,A] = butter (N,Wn,'high') designs a highpass filter.


[B,A] = butter N,Wn) is a bandpass filter if Wn = [W1 W2]. If Wn is a two-element vector, Wn =
[W1 W2], Butter returns bandpass filter with passband W1 < W < W2.
[B,A] = butter(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2].
Implement a HPF operation to remove 2 Hz and 5 Hz signals only. Show this to a
demonstrator before continuing.

14. Downsampling
Sometimes, we wish to reduce the length of the signal without distorting the signal. This is known as
downsampling. Generate a sine wave frequency of 500 Hz with Fs=2000 Hz. Skip each sample and
obtain the spectral content:
>> i=1:2000; Fs=2000; f1=400;
>> y=sin(2*pi*f1/Fs*i);
>> psd(y); %peak at 400 Hz
>> z=downsample(y,2);
>> psd(z); % you should find a peak at 0.8, corresponding to 400 Hz.

Effectively, we have reduced the length of the signal by half. The sampling frequency is also
effectively reduced by half to 1000 Hz, which is why you get a peak at 0.8 instead of 0.4. Now
downsample by 10 (i.e. keeping every 10th sample - skip nine samples, i.e. drop nine, keep one, drop
nine, keep one ......). Obtain the spectral content. Where is the peak now? Show this to a
demonstrator before continuing. What has happened? Effectively we have reduced the signal by
10 to a length of 200 and also the sampling frequency is effectively reduced to 200 Hz. Nyquist
theorem says that we must use sampling frequency of at least twice the highest frequency content of
the signal. Since our signal frequency is at 400 Hz, we should not use any sampling frequency lower
than 800 Hz. So, we have downsampled too much and the signal is distorted.

Page | 8
Part C - Assignment

Your report for this part needs to be submitted by Week 16 (20 January 2010) before midday on the
submission server in one of the following formats: PDF or Word .doc. The Undergraduate
Handbook provides guidelines and links to online resources to help you in writing your report.
Reports will be checked for plagiarism, so be careful not to include others' work or material from
websites or books; you must write all of the report yourself. Marked reports will normally be
returned within two weeks of submission.

Please read the following rules before you start: You are allowed to use only MATLAB for the
code. In your report, include the complete MATLAB code. Don’t forget to include any comments
that will aid in the understanding of the program. Marks will be given on how successfully you have
implemented the signal conditioning tasks, your ability to explain the parameters used in the code
and the overall code design and report presentation. Finally, remember to write your name and reg.
number in your report. Just like the reports for experiments 1 and 2, this is an individual
assignment. It is not to be done in group.

In this assignment, you’ll perform signal conditioning of voice signals and segment a sentence into
words. You are given a zipped file (download from the CE121 course webpage) that contains 100
signals (a sentence was spoken 100 times). The voice signals have been heavily corrupted with two
different noises: random noise and three single frequency noises. The sampling frequency is 12
kHz. Perform signal conditioning (i.e. noise reduction) by using simple averaging of all the signals
and frequency filtering. First, do a spectral analysis to decide the frequency of the three single
frequency noises. Employ a suitable filter to remove these three single frequency noises (with
suitable cut-off determined from the spectral analysis). Next, to reduce random noise in the 100
signals, do a simple averaging to obtain one noise reduced signal. After this, downsample the signal
using a suitable downsampling number – the smaller the signal, the better it would be but you
should be careful to avoid aliasing (explain how you arrived at this suitable downsampling number
in your report). If necessary, amplify the resulting signal. Now, segment the signal into words
(visually inspect the signal and do segmentation). Play each word, what are the words?

You can use any function in MATLAB for this task. You have completed experiment 3.

Page | 9
CE121 Exp 3 – sign-off sheet Name:

Reg. no:

After each part of the laboratory script has been completed, a demonstrator will sign and date the relevant
part of this form. Remember to write your registration number and name on the top of this sheet.

Task Marks available Demonstrator’s Date of Marks


signature signature awarded

1. Working through the script – signed off before submission


A: signal amplification and 5
spectrum
A: LPF 5

A: 500 Hz sine wave 5

B: plot waveform 5

B: power spectrum 5

B: spectrum for white noise 5

B: three sine wave 5


generation
B: LPF 5

B: HPF 10

B: downsample 10

2. Report: signed off after submission

Spectral analysis 5

Filter design 5

Averaging 5

Downsampling 5

Explanation 10

Overall code design and 10


report presentation
Total 100

See overleaf for any additional feedback on your report.


Page | 10

Vous aimerez peut-être aussi