Descrete Fourier coefficient determination

I want to develop a Fourier coefficients determination algorithm. I have a challenge of creating one because whenever I increase the Fourier Harmonics the first Fourier coefficients remain the same and I only see the addition of the new one.
The simulated values do not make sense all after a certain harmonics. How can I fix this. I attached my code.
for example, for the below set of points I determined the Fourier approximation:
xx=[-3.14;-2.44;-1.75;-1.05;-0.35;0.35;1.05;1.75;2.44;3.14];
yy=[-8.87;-4.97;-2.05;-0.10;0.88;0.88;-0.10;-2.05;-4.97;-8.87];
For N=4
an= n=0,1,2..
-2.3722
4.1685
-1.1708
0.6241
-0.4856
For N=13
an=
-2.3722
4.1685
-1.1708
0.6241
-0.4856
0.5250
-0.7055
1.1980
-4.1518
4.7429
-4.1841
1.1457
-0.5443
0.4454
*
[xnt,ynt]=FR_approximation(xx,yy,N);
% xx=[-3.14;-2.44;-1.75;-1.05;-0.35;0.35;1.05;1.75;2.44;3.14];
%
% yy=[-8.87;-4.97;-2.05;-0.10;0.88;0.88;-0.10;-2.05;-4.97;-8.87];
%
% N=13;
% The fourier descriptors calculation
an=[ ]; bn=[ ]; % initialization of Fourier coefficients
% determining the first term of the series a0
n=length(xx);
deltax=2*pi/(n-1); beta= (2*pi)/(xx(end)-xx(1));
% Calcuklating a0
suma0=[ ];
for i=1:n-1
suma_0=yy(i)*deltax; % part of the calculation of an
suma0=[suma0;suma_0];
end
a0=(1/(2*pi))*sum(suma0)
% the number of intervals
for k=1:N % N is the number of harmonics
suma=[ ]; sumb=[ ]; % initialization
for i=1:n-1
suma1=yy(i)*cos(k*beta*xx(i))*deltax; % part of the calculation of an
suma=[suma;suma1];
sumb1=yy(i)*sin(k*beta*xx(i))*deltax;
sumb=[sumb;sumb1]; % part of the calculation of bn
end
ani=(1/(pi))*sum(suma);
bni=(1/(pi))*sum(sumb);
%
an=[an;ani]; % Fourier coefficients
bn=[bn;bni];
end

Answers (0)

Categories

Find more on Wavelet Toolbox in Help Center and File Exchange

Asked:

on 2 Nov 2015

Edited:

on 2 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!