Southern Methodist University School of Engineering Electrical

Southern Methodist University

School of Engineering

Electrical Engineering Department

EE 2170 Design and Analysis of Signals and Systems

Laboratory Notes

Yasser Ghanbari, Carlos Davila, Scott C. Douglas, and Panos E.

Papamichalis,

©2011, SMU. All Rights Reserved

Spring 2011

Contents

4.

Integral in MATLAB a.

Example: integration in MATLAB b.

Example: convolution of two signals using ‘trapz’ c.

Example: convolution of two signals using ‘conv’ d.

Assignment 4: Convolution

5.

Exponential Fourier Series a.

Exponential Fourier series coefficients b.

Signal reconstruction using the exponential Fourier series coefficients c.

Side note: summation of vectors d.

Assignment 5: exponential Fourier series in MATLAB

6.

Introduction to Simulink a.

Example: Fourier series coefficient in Simulink b.

Example: square wave signal reconstruction in Simulink c.

Assignment 6: exponential Fourier series coefficients in Simulink

7.

Fourier Transform a.

Example: Fourier transform of a rectangular function b.

Assignment 7: Fourier transform

8.

Audio Signals in MATLAB a.

Example: audio signal plotting in MATLAB b.

Assignment 8: convolution and the Fourier analysis

9.

Filters in LTI Systems a.

Example: lowpass filtering of a noisy EKG signal b.

Assignment 9: Lowpass, Highpass, and Bandstop Filters

10.

Audio Signals a.

Example: audio signal analysis in MATLAB b.

Assignment 10: Notch Filter for Interference Removal

11.

Laplace Transform a.

Example: Laplace transform visualization in MATLAB b.

Assignment 11: Visualizing the Laplace Transform

12.

Image Signals a.

Example: image signal analysis in MATLAB b.

Assignment 12: Image Signal Enhancement and Resizing

8. Audio Signals in MATLAB

Audio signals are one-dimensional as opposed to the two-dimensional image signals. In order to save the Audio signals in a computer as a digital file, the signal is sampled at a constant rate per second and the samples are then recorded in a computer file as a vector of numbers. Among many file formats based on which the audio signals are recorded, the ‘.wav’ and ‘.au’ file formats are loaded in MATLAB using ‘ wavread

’ and ‘ auread

’ commands. The general syntax of these commands is:

[ y , fs , bits ] = wavread (‘ filename

’)

[ y , fs , bits ] = auread

(‘ filename

’) where ‘ filename ’ is the ‘.wav’ or ‘.au’ audio file name and address, ‘ y ’ is a vector of numbers including the samples of the recorded audio, ‘ fs

’ is the sampling rate per second (or sampling frequency in Hz), and ‘ bits

’ is the number of bits used to quantize and store any audio sample value. The audio samples are also played (sent to the speaker) using the MATLAB command

‘ sound ’: sound ( y , fs , bits )

Example: audio signal plotting in MATLAB

Suppose that two speech signals are recorded in two files named ‘A.wav’ and ‘Anoisy.wav’.

The following code shows how they are loaded, played, and plotted in MATLAB. Figure 8-2 displays the waveform of the signals, too. clc; clear; close all ;

[cf,fs,bits]=wavread( 'A.wav' ); % load the audio signal in vector cf sound(cf,fs,bits); % play the loaded signal via speaker

[f,fs,bits]=wavread( 'Anoisy.wav' ); % load the audio signal in vector f sound(f,fs,bits); % play the loaded signal via speaker t = 0 : 1/fs : (length(f)-1)/fs; % time vector associated with signals figure; subplot(2,1,1); plot(t,cf); xlabel( 't (sec)' ); ylabel( 'Clean signal' ); xlim([t(1) t(end)]); ylim([-1 1]); subplot(2,1,2); plot(t,f); xlabel( 't (sec)' ); ylabel( 'Noisy signal' ); xlim([t(1) t(end)]); ylim([-1 1]);

Figure 8-1. MATLAB code to load, play, and plot two audio signals of vowel “ah”

Figure 8-2. The audio signal plotted in MATLAB

Assignment 8: Convolution and the Fourier Analysis

In this assignment, we want to use the convolution concept applied to an audio signal and analyze the behavior of the system using the Fourier analysis. Please write your codes for the following two sections in two separate m-files.

I.

Load the signal “A.wav” into the vector ‘ cf

’ using the wavread command. Using your developed function in previous lab, FT , for the Fourier transform, compute the Fourier transform of cf into CF as [ CF ] = FT (c f’,t,omega ), in which the vector omega is defined in the interval [0 16000π] rad/sec with the step-size of 4π, and t is the time vector associated with the signal cf .

Plot the magnitude of the Fourier transform with respect to the frequency.

Explain why there are several spikes in the plot and what they correspond to.

Find and report the fundamental frequency of this vowel signal in rad/sec and Hertz.

II.

Write a MATLAB program (m-file) in which both of clean and noisy speech signals

(‘A.wav’ and ‘Anoisy.wav’) is loaded into the variables cf and f using ‘wavread’ command. When loading the signal, do not forget to load the sample rate ( fs ), too.

Listen to both cf and f using ‘ sound

’ command and explain the difference.

Define the stepsize of the time to be equal to the inverse of fs .

Define a time vector t1 in the interval of [0 (length( f )-1)/ fs ] with the stepsize you defined above (inverse of fs ).

Define the second time vector t2 consisting of the first N elements of t1 . The value of

N will be given later. For now, assume N = 10.

Define a vector h with the same length as t2 and all values being equal to 1/t2(N) .

This vector corresponds to a rectangular signal.

 Using Matlab command ‘ conv

’, calculate the convolution of

f (noisy signal) and h

(rectangular signal) and return the result in a vector g (for which you define the time vector as t ) for each of the following two cases:

Set N=10 and listen to the output g using ‘sound’ command. In separate figures, plot cf with respect to t1 in subplot(3,1,1), f with respect to t1 in subplot(3,1,2), and g with respect to t in subplot(3,1,3). For a better visualization, limit the time axis in all three subplots to [0 0.25] sec and the y-axis to [-1 1].

Set N=50 and listen to the output g using ‘sound’ command. In separate figures, plot cf with respect to t1 in subplot(3,1,1), f with respect to t1 in subplot(3,1,2), and g with respect to t in subplot(3,1,3). For a better visualization, limit the time axis in all three subplots to [0 0.25] sec and the y-axis to [-1 1].

In order to explain the convolution results, we use the Fourier analysis. Using your developed function, FT , for the Fourier transform, compute the Fourier transform of f into F as [ F ] = FT ( f’,t1,omega ), in which the vector omega is defined in the interval [0

16000π] rad/sec with the step-size of 4π. Plot the magnitude of the Fourier transform with respect to the frequency. Explain the difference between this plot and the one you obtained from the first section of this assignment for the clean signal cf . Also, find and report the range of the frequency of the noise by comparing the spectral contents of the clean ( cf ) and noisy ( f ) signals.

Using your developed Fourier transform function, FT , compute the Fourier transform of g (convolution result obtained above when N=10 ) into G as [ G ] = FT ( g’,t,omega ), in which the vector omega is defined in the interval [0 16000π] rad/sec with the stepsize of 4π. Plot the magnitude of the Fourier transform with respect to the frequency.

Explain the difference between this plot and the one you obtained for the noisy signal f . Explain your observations according to the property of the Fourier transform for convolutions, and based on your knowledge about the Fourier transform of rectangular signals.

Using your function, FT , compute the Fourier transform of g (convolution result obtained above when N=50 ) into G as [ G ] = FT ( g’,t,omega ), in which the vector omega is defined in the interval [0 16000π] rad/sec with the step-size of 4π. Plot the magnitude of the Fourier transform with respect to the frequency. Explain the difference between this plot and the one you obtained for N=10. Explain your observations according to the property of the Fourier transform for convolutions, and based on your knowledge about the Fourier transform of rectangular signals with different width.