I am trying to use the FFT to approximate a given function. So i have 10 points xk that are given for example, if i use the FFT that will give me Xk. So now using the inverse FFT we can get the polynomial that connects the given pionts, so y(t)=x(t) is this case. (with x(t) the sampled function and y(t) the approximated function).
Now if we want to know points in between the given point we can use
https://i.sstatic.net/PEXvr.png
With M the number of points we want to evaluate the function and N the number of points given( the samples from x(t)). So using the above function and the following
https://i.sstatic.net/VCBPX.png
We should be able to find a trigiometrical polynomial that approximates the sampled function. I've written the following code in matlab, but it doesn't seem to work.
function y = periotrig(x,K,M)
N=size(x,1);
for i=1:N
time(i)=i/N;
end
for m=1:M
tm(m)=m/M;
end
xn=diag(x); % Here we are going to extract the xn values from the matrix x
Xk=fft(xn); % We take the FFT to vind the Xk values
%Since we have the Xk values we can vind the Yk values aswell
%%=========================================================================
for k=0:((N/2)-1)
Yk(k+1)=(M/N)*Xk(k+1);
end
for k=N/2
Yk(k+1)=(M/N)*(Xk(k+1)/2);
end
for k=((N/2)+1):(M/2)
Yk(k+1)=0;
end
for k=((M/2)+1):M-1
Yk(k+1)=conj(Yk((M-k+2)));
end
%%=========================================================================
%Once we have the Xk and Yk values we can use the top formula on page 4
for m=0:M-1
temp=0;
for k=1:(M/2)-1
temp=temp+((real(Yk(k+1))*cos(2*pi*k*tm(m+1)))+(imag(Yk(k+1))*sin(2*pi*k*tm(m+1))));
end
y(m+1)=(1/M)*(Yk(1)+(2*temp)+(Yk((M/2)+1)+(Yk(M/2)*cos(pi*M*tm(m+1)))));
end
plot(tm,y);
hold on;
plot(time,diag(x),'.r');
end