Based on previous homework problems, you should be able to define a MATLAB vector called ak defined over a finite range of discrete k values, Kk. In MATLAB, we often represent continuous-time signals using discrete-time signals that have very short time intervals between each sample. A time vector can be generated using the function linspace. For example, linspace(-1, 1, 1000) will create a vector of 1000 points ranging in value from -1 to 1. One period of the signal r(t) defined above can be plotted using the following code:
t = linspace(-1, 1, 1000);
x = abs(t);
plot(t, x);
The real part of the complex exponential (c(t) = ejωt) defined over the same time period can be plotted using the following code:
t = linspace(-1, 1, 1000);
x = exp(j*(-2*pi)*t);
plot(t, real(x));
Summations can be coded in MATLAB by defining a vector of zeros and then adding to that vector using a loop. For example, the summation Σakejωkt can be coded in MATLAB as follows:
t = linspace(-1, 1, 1000);
x = zeros(size(t));
for n = 1:length(k)
x = x + a(n)*exp(j*k(n)*pi*t);
end
In the code, use the index variable "n" in the for loop to make sure that the ak vector and the independent variable line up properly. Finally, it is important to know that when typing "a*b" in MATLAB, the software attempts to perform vector multiplication. In order to perform element-wise multiplication (which is what we want when calculating the ax values), the syntax is "a.*b". For example, if we wished to calculate a.*p in MATLAB, we would use "a.*p" or "k.*p".
Using MATLAB, plot an approximation of I(t) = 1 - |t| over the interval -1 < t < 1. Use the ak given above, but only consider the coefficients for -3 < k < 3. Using MATLAB, plot an approximation of I(t) = 1 - |t| over the interval -1 < t < 1. Use the ak given above, but only consider the coefficients for 10 < k < 10. How many coefficients do you need to represent a sufficiently sharp corner? (This will vary based on the resolution and size of your 3D plot, but it should be an interesting exercise.) What happens if you look at a longer time interval, say 5 < t < 52?