function [spec] = TS_transform (phys, nspec, basis)
% Computes 'spec', the first 'ndeal' dealiased coefficients
% of the expansion of 'phys' on the 'basis' functions

% phys is a vector of values of a function on a physical grid.
% ndeal is an even integer at most equal to the length of 'phys'.
% basis is a string 'a' or 'b' (see equation [18]).

nphys = 2* length(phys) -2;
temp = [phys;phys(2:nphys/2)];
nphys = length(temp);
spec = zeros(nspec,1);

h_max_cos = floor((nspec-1)/2);
h_max_sin = floor( nspec   /2);

temp = fft(temp)/nphys;

if strcmp(basis,'a')
   spec(3:2:(h_max_cos*2+1)) = temp(3:2:(h_max_cos*2+1)) + temp(nphys+2-(3:2:(h_max_cos*2+1))) ;
   spec(2:2:(h_max_sin*2))   =(temp(3:2:(h_max_sin*2+1)) - temp(nphys+2-(3:2:(h_max_sin*2+1)))) * 1i;
   spec(1) = temp(1);

elseif strcmp(basis,'b')
    disp('Not implemented yet. Will be uploaded soon!')
else
    disp('wrong ''basis'' flag. Must be ''a'' or ''b''');
    return;
end;


   
