Let's suppose we want to plot the function f(t) = 3 + cos(2t) - 4sin(6t)
using the discrete fourier transform
first we need to define a vector for the time interval
t = linspace(0,2*pi,4096); should suffice
(that is we will create a vector of 4096 evenly spaced number between 0 and 2*pi)
now we will write your function
alrighty, in our vector, V, that is to be used in the fft command
the first element corresponds to any constants (or items of zero order frequency)
thus the first element of V will be 3.
The next frequency, 1, does not show up, so the second element of V is zero
The next frequency, 2, appears in a cosine and the amplitude of this frequency is 1 (the leading coefficient in front of cos(2t)).
So our vector V is now [3 0 1].
But how do we differentiate between a cosine and a sine? Well the cosine is the real part of the decomposition of exp(i*theta). So what we really need to take is the real part of this vector. So the first part of this function can be written as
real(fft([3 0 1],4096)) (need same # of elements both t and the fft)
We also need to add in the sine term
sin corresponds to the imaginary parts of the decomposition of exp(i*theta)
The only sine term has a frequency of 6 with amplitude -4. Thus,
V = [0 0 0 0 0 0 4];
Because exp(i*theta) = cos(theta*t) - i*sin(theta*t)
we must actually take the opposite of any amplitudes with imaginary functions associated with them. Thus if we had the function
h(t) = i + 3sin(2t) - 5sin(3t) our vector V must be [-1 0 -3 5];
remember, the first element corresponds to constant
the second will correspond to frequency of order 1
thus the seventh element will correspond to frequencies of order 6.
How to compute and plot sin(2*pi*t/P) and cos(2*pi*t/P) using [re,im}=plot_pair(t,P) where t is a vector of time samples to be computed and plotted and P is the period of the sin/cosine pair to compute.
Return: re-vector of same length as t contains sin(2*pi*t/P) values
im-vector of same length as t containing cos(2*pi*t/P) values
this makes use of the complex numbers somehow where.
We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling We Value Civility
• Positive and compassionate attitudes
• Patience while debating We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving