Digital Signal Processing Reference
In-Depth Information
This brings us a step closer, since we now see a straight line plotted on the
graph. But why do we see a straight line? Upon inspection, we notice that all x
values are 1. A few examples on a calculator reveal that the values for x are actually
correct. The problem here is the argument to the cosine function; 2 corresponds to
a rotation around the circle. So we can always add 2 to the argument of a sinusoid
without changing the result, i.e.,
cos(0) = cos(2) = cos(22):
Since t always has integer values in the above code, the cosine function's argument
always is just a 2 multiple of the one before it. We can x this by introducing a
fractional step to the for loop. Notice how we change the upper limit on t too, to
keep the number of points the same.
for t=1:0.01:2
x(t) = cos(2*pi*200*t);
end
plot(x);
This code gives us an error:
??? Subscript indices must either be real positive integers
or logicals.
>> t
t =
1.0100
We see that t has a value of 1.01, and using 1.01 to index an array will give us a
problem in just about any computer language. In other words, we cannot use x(t)
unless t has an integer value. To x this, we can introduce a new variable n just to
act as an index for array x.
n = 1;
for t=1:0.01:2
x(n) = cos(2*pi*200*t);
Search WWH ::




Custom Search