%% cossinmat2
%% function that returns the matrix to produce "Fourier"  cosine-sine coefficients
%% this function is the same as cossinmat except the calculation is vectorized


function A = cossinmat2(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);

%Construct column vector of sample points. Note the use of ' 
t = (2*pi/N)*(0:1:(N-1))';

% the following loops use vectorized function evaluation
A = ones(N,1);
for j = 1:n A = [A,cos(j*t)]; end;
for j = 1:n A = [A,sin(j*t)]; end;

if even A = [A, cos((N/2)*t)]; end;

