Davidlong said:
1.
1.Use MATLAB to demonstrate how the series converges to the triangular wave.
2.Generate a plot(properly labelled) with 6, 10 and 30 terms for a value of T = 2.
2. *A triangular wave with period T may be written as: 1/(2n+1)^2 * cos((2n+1)*w0*t) (this is a series, n starts at 0 and goes on until infinity). where w0 = 2pi/T. This wave form is sampled, with a sampling time of TS = T/200, to yield the sampled signal x(n).
"...the sampled signal x(n)" --this phrase might be a bit confusing. "n" is the series-sum index. x(t) might be clearer, where t is a sampled time vector. x
n might be better for referring to the nth vector term of the series. More on that below.
t=2;
Ts=t/200;
w=(2*pi)/t;
n=0:9999;
x=((2*n+1).^-2).*(cos((2*n+1)*w*Ts)); plot(x)
"...x=((2*n+1).^-2).*(cos((2*n+1)*w*Ts))" --The heart of your problem is in this statement (and what does not surround this statement). As you may already know, MATLAB can operate on vectors (1-dimensional matricies) and scalars (variable or constant), as well as larger-dimensioned matricies. The initial problem specified x, the output vector, as a series-sum. As
gneill points out, you have no summing mechanism (
for loop) specified the summing of the x
n vector terms. "n" is what would control the number of terms that get summed.
Use of ".^" and ".*" --you don't need the dot "." (read up on its special meaning) because "(2*n+1)" is a scalar (a constant for a given series term) and therefore so would be "(2*n+1)^2".
"cos((2*n+1)*w*Ts)" --is a scalar and needs to be a vector. "n" is the index variable for a given series term, and "w" is a constant, so that leaves "Ts" for you to scrutinize. You have specified Ts as a constant (2/200). Look again at the original problem. They differentiate "T" (the period) from "t" (the independent variable time). The way MATLAB works in this application (graphing a function of time), is to use a sampled time vector. You need to create one using Ts as your sample-time increment. The scalar, (2*n+1)*w, operates on this time vector (essentially converting it to a phase vector, then cos() operates on the phase vector. Multiplying this by (2*n+1)^2 results in an x
n vector term. You must accumulate all these x
n terms to get your final result.
"n=0:9999" --you don't need to make n a vector. It is a loop index. You will need to specify the maximum number of times to loop, say N=9999, if you want to loop that many times.
I imagine you need to get something working before you run with N=6,10 and 30 terms.
"plot(x)" --this will generate a raw plot of a vector x. The graph will not have much meaning (no timescale, no axis lables, etc.), just x as a function of the running index of x.