%% cossinmat %% function that returns the matrix to produce "Fourier" cosine-sine coefficients function A = cossinmat(N) % test of even or odd % even = 1 if N is even and even =0 if N is odd. Note the use of ~. even = ~rem(N,2);n = fix((N-1)/2); for i=1:N ti = (i-1)/N*2*pi; A(i,1)= 1; for j = 1:n A(i,j+1) = cos(j*ti); A(i,j+n+1) = sin(j*ti); end; end; %add extra column for even N if even for i=1:N A(i,N)= (-1)^(i-1); end; end;