Hi to everyone,
I am new in matlab programming and this is one of my first tries to complete a programme. I would like to find the sum of the fourier coefficients, the first ten at first, using a for loop and then plot them against t (duration).And then I must also plot the sum of three specific terms of the fourier coefficients (2,4,6)
The fourier series coefficients are:
A0=1/2 , Ak=2/π*k (for k:odd) , Ak=0 (for k even, greater than 0)
% initialize variables
SR=44100; % sample rate
N=10; % number of fourier coefficients
t=[0:1/SR:Tf]; % duration 2 seconds with an 1/44100 step
fc=ones(1,N); % put ones to vector fc
%for loop that finds the even and odd fourier coefficients
f(1)=0.5; % the first coefficients(which is the zero one), is 0.5.
x=ones(1,N); %put ones to an new vector x
x(1)=f(1); % the first value of x is equal to 0.5.
x(n)=fc(n)+x(n-1); % a for loop that adds the fourier coefficients starting for f(1)=0.5
I have done this until now..Although,I have the correct sum resaults I think that I have made some mistake in the use of for loop...
The most serious for me is that i cannot plot x against t. How can I plot different sized vectors? I am not sure if I have understand it well.I have tried to see their sizes and then change x length like t length but the plot was not right.
This exercise also suggests to change the sample rate in order to see the differences in the plot.
I hope this would be clear for you..
Thanks in advance..
||10/23/2010 8:34:05 PM