EE313 Linear Systems and Signals - Homework #7 Hints

• Prof. Evans' Wednesday office hours will be shifted to 7:30-9:00 pm and take place in his office of ENS 433B.

• Computing phase responses: One can compute the phase a complex number with `angle` in Matlab/Mathscript. The `angle` also works for a vector of complex values, e.g. samples of a frequency response taken at different frequencies. The `angle` command returns a phase between [-pi/2, pi/2], which is known as wrapped phase.

One could compute the unwrapped phase by applying the `phase` command to a vector of complex values.

Here is a simple example illustrating unwrapped phase. Consider an ideal delay. The transfer function is H[z] = z-1. The frequency response is H[ej w] = e-j w. The phase is -w. If we were to plot the phase response as arctan( e-j w ), then we would see jumps of discontunity at ..., -3 pi/2, -pi/2, pi/2, 3 pi/2, ... instead of a straight line.

• Problem 7.1. The Web link and Matlab code from the question are repeated here:
• Western Musical Scale Frequencies
• (a) Matlab code.
```load gong
n = 1 : Fs;
f0 = 440;
w0 = 2*pi*f0/Fs;
noteSound = cos(w0*n);
sound(noteSound);
```
The command `load gong` loads the samples in the gong sound to the variable y and sets the sampling rate Fs for the sound card.
Note: For LabVIEW Mathscript users, you can replace `load gong` with `Fs = 8192;` or load a different sound file of a similar format.

The following Matlab code assumes that the variable `noteSound` holds the samples of the sound and plots the magnitude of the frequency content in `y` frequencies -Fs/2 to Fs/2. The amplitude A is shown on a deciBel (dB) scale, i.e. 20 log10 A.

```y = noteSound;
freqPoints = (-1 + 2*cumsum(ones(1,length(y)))/length(y))*Fs/2;
magValuesIndB = 20*log10(fftshift(abs(fft(y))));
plot( freqPoints, magValuesIndB );
```
• (b) Matlab code to play individual notes for one second each.
```%%% Set the sampling rate, Fs, of sound card

wholeNotesWesternScale = [ 440 494 523 587 659 698 784 880 ];
n = 1 : Fs;

%%% Play one note at a time
for f0 = wholeNotesWesternScale
w0 = 2*pi*f0/Fs;
noteSound = cos(w0*n);
sound(noteSound);
end
```
Note: For LabVIEW Mathscript users, you can replace `load gong` with `Fs = 8192;` or load a different sound file of a similar format.

Here is Matlab code to load the homework7sound file, play it and plot its frequency content:

```load homework7sound.mat
sound(homework7sound);
y = homework7sound;
freqPoints = (-1 + 2*cumsum(ones(1,length(y)))/length(y))*Fs/2;
magValuesIndB = 20*log10(fftshift(abs(fft(y))));
plot( freqPoints, magValuesIndB );
```

• Problem 7.2: Compute the Fourier series coefficients using a0, an and bn as we did on slide 11-7 (which is mistakenly numbered 19-7 but appears in the place where lecture 11 slides should be).

The function x(t) is odd symmetric about the origin. Hence, the terms a0 and an will be zero.

Here is example Matlab code that could be used to generate x(t) and the Fourier expansion for n=1, x1(t), for two periods. The Matlab expression `rectpuls(t)` is a rectangular pulse centered at the origin with non-zero extent over -0.5 ≤ t ≤ 0.5. We need two rectangular pulses, i.e. one for each period being plotted. The example code uses the `hold` command to superimpose plots in Matlab on the same figure.

```T0 = 2;
f0 = 1/T0;
w0 = 2*pi*f0;
t = -1 : 0.01 : 3;
x = sin(2*pi*t) .* ( rectpuls(t) + rectpuls(t - T0) );
b1 = 1;                  %%% Use your calculated value
x1 = b1 * sin(w0*t);
hold on;
plot(t, x, 'b-');        %%% Plot in blue solid lines
plot(t, x1, 'r--');      %%% Plot in red dashed lines
hold off;
```

If you experience a division by zero in computing one of more the bn terms, then you might try to simplify the expression of bn for that value of n using L'Hopital's Rule.

• Problem 7.4. The impulse train in the time domain provides a way to express the sampling of a signal f(t) using a sampling period of Ts by multiplying f(t) and the impulse train.

The impulse train is even symmetric about the origin. Hence, the bn terms will be zero.

The Fourier series expansion of a periodic signal will be exact if an infinite number of terms is used.

Here is Matlab code to visualize what the Fourier series expansion is converging to. The code arbitrarily sets the fundamental period to 1 s. Try out N = 10 and then N = 100 and finally N = 1000.

```T0 = 1;
f0 = 1/T0;
w0 = 2*pi*f0;

tmin = -0.5*T0;
tmax = 0.5*T0;
t = tmin : (tmax-tmin)/1000 : tmax;

%%% Fourier series expansion
N = 10;
a0 = 1;
fourierSeriesExp = a0*ones(1,length(t));
for n = 1:N
an = 2;
fourierSeriesExp = fourierSeriesExp + an * cos(n*w0*t);
end

plot(t, fourierSeriesExp);
```

Last updated 10/20/10. Send comments to bevans@ece.utexas.edu