function [A] = ccesaro(x,N,L,v)
%Soveltaa kompleksiseen lukujonoon Cesaron menetelmää
%[A] = ccesaro(x,N,L,v)
%x lukujono
%N kertaa
%L pituus
%v valinta: 1=Cesaro, 2=käänteinen Cesaro
%
%s=randn(1,100).*(1:100).^3.*exp(2*pi*1i*rand(1,100));
%A=ccesaro(s,3,16,1);

if v==1,
A=zeros(L,3+2*N);
A(:,1)=1:L;
A(:,2)=1./A(:,1);
A(:,3)=x(1:L);
for k=1:N
    for j=1:L
    A(j,2*k+2)=sum(A(1:j,2*k+1));
    A(j,2*k+3)=mean(A(1:j,2*k+1));
    end
end
h=figure;hold on
for k=0:N
a=[1 0 1]*(1-(k/N))+[0 1 0]*(k/N);
plot(real(A(:,2*k+3)),imag(A(:,2*k+3)),'Color',a)
end
elseif v==2,
A=zeros(L,3+2*N);
A(:,1)=1:L;
A(:,2)=1./A(:,1);
A(:,3)=x(1:L);
for k=1:N
    A(:,2*k+2)=A(:,1).*A(:,2*k+1);
    A(:,2*k+3)=[A(1,2*k+2);A(2:L,2*k+2)-A(1:L-1,2*k+2)];
end
h=figure;hold on
for k=0:N
a=[1 0 1]*(1-(k/N))+[0 1 0]*(k/N);
plot(real(A(:,2*k+3)),imag(A(:,2*k+3)),'Color',a)
end
end
end

