$29
ECE-210B Homework 4
1. Professor Mintchev has just assigned you 20 tedious Gram Schmidt Orthonormalization
problems! Luckily, you are a master of MATLAB so you decide to build a function which
can handle them all for you in short time. Note: This homework has been assigned in all
three ECE-210 sections.
• Create a function called gramSchmidt. The input to the function should be a 2-D
array, each column of which is a vector in the original linearly independent set of
vectors. Implement GS to create an orthonormal set of vectors from these. Store
them as columns in an output matrix, similar to the input format. Feel free to use
the norm function if needed.
• After you’ve created this function, you’d like a way to test if it works. Create another
function called isOrthonormal which has a single 2-D array as the input. The function
should return 1 if all columns are orthonormal and 0 otherwise. Be careful with this
- direct floating point equality comparison is a bad idea. Instead apply a threshold
to the difference of the two numbers like so: if |x − xˆ| ? then ... The eps function
might be useful here. You can add a nice big fudge factor to make the tolerance big
enough that it works, just don’t make it huge. (Note that there is also the matter of
spanning the same space as the original matrix, don’t worry about this condition)
• Finally, we would like to estimate another vector as a linear combination of these
orthonormal vectors. (Project the vector onto the space of the orthonormal vectors.)
Implement a function called orthoProj which takes a vector to be estimated and and
array of orthonormal columns as arguments and outputs the estimated vector.
• Test all of the above functions on some random complex vectors. (use rand to make
a random vector) First test the case where there are more elements in each vector
than the number of vectors. Then test the case where the number of vectors is equal
to the number of elements in a vector. Compare the errors.
• Uniformly sample sin(x) on [0, 2π]. Generate 5 Gaussians with the equation
1
√
2πσ2
exp
−(x − µ)
2
σ
2
Give each Gaussian standard deviation 1 (σ = 1) and pick the mean from a linearly
spaced vector ranging from 0 to 2π. (µ ∈ {0, π/2, π, 3π/2, 2π}) Consider using ndgrid
for compact code. Plot the Sinusoid and Gaussians on the same plot. Give axis
labels and a title. Use gramSchmidt to create an orthonormal set of vectors from the
Gaussians. Use orthoProj to estimate the sinusoid from that set of vectors. Create
a 2x1 subplot. Plot the sinusoid and the estimated sinusoid together on the upper
plot. Plot the orthonormal basis functions on the lower plot. Give all plots proper
labels and titles.
1