% function yout = vfft(yin,n)
%
%  Perform an N length FFT on the VARYING matrix YIN.  N is optional,
%  defaulting to the number of INDEPENDENT VARIABLEs in YIN.  If N is
%  greater than the number of INDEPENDENT VARIABLEs in YIN, the data 
%  is zero padded.  If N is less the data is truncated.  The MATLAB 
%  function FFT is used for the actual calculation.
%
%  It is assumed that the YIN is a time scale in seconds and YOUT is
%  returned with a frequency scale in radians/sec.  The time scale
%  is assumed to be monotonic and only the first interval is used
%  to determine the frequency scale.  
%
%   See also:  FFT, IFFT and  VIFFT.

function Y = vfft(y,n)

if nargin == 0,
    disp('usage: Y = vfft(y,n)')
    return
    end
    
[type,nr,nc,npts] = minfo(y);
if type == 'syst',
    error('input is not VARYING or CONSTANT')
    return
    end

if type == 'cons',
    Y = y;
    return
    end

if nargin == 1,
    length = npts;
elseif nargin == 2,
    length = n;
else
    error('too many arguments')
    return
    end

[ydat,yptr,t] = vunpck(y);
tinc = t(2) - t(1);

finc = 2*pi/(tinc*length);
omega = [0:finc:finc*(length-1)];


Y = [];
for i = 1:nr,
    Yrow = [];
    for j = 1:nc
        [ydata,yptr,t] = vunpck(sel(y,i,j));
        sisoY = fft(ydata,length);
        sisoY = vpck(sisoY,omega);
        Yrow = sbs(Yrow,sisoY);
        end
    Y = abv(Y,Yrow);
    end
%
% Copyright MUSYN INC 1991,  All Rights Reserved
