% script: DFTderivtest.m
% description: perform some approximation experiments with complex
% Fourier polynomials on the function myfcn and its derivative myfncp,
% which are defined externally.

% programmer: t. shores
% last rev.: 2/8/16
 
% Octave and Matlab compatible file
n = 5 % highest frequency in Fourier approximation 
N = 2*n + 1 % account for Nyquist sampling rate 
% construct the coefficients for myfcn, derivative myfcnp
xnodes = linspace(0,2*pi,N+1)'; 
xnodes = xnodes(1:N); % trim off 2*pi
f = myfcn(xnodes);
fp = myfcnp(xnodes);
zeta = exp(-2*pi*i/N);
z = zeta.^(-n:n);
F = fliplr(vander(z))/N;
c = F*f;
cp = F*fp;
cpapprox = i*(-n:n)'.*c;
% ok, let's compare coefficients
disp("|| cpapprox - cp || : ");
disp(norm(cpapprox - cp,inf));
