view m-toolbox/classes/@ao/ifft_core.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents f0afece42f48
children
line wrap: on
line source

% IFFT_CORE Simple core method which computes the ifft.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: Simple core method which computes the ifft.
%
% CALL:        ao = ifft_core(ao, type)
%
% INPUTS:      ao:   Single input analysis object
%              type: The ifft type
%                    'symmetric'
%                    'nonsymmetric'
%
% VERSION:     $Id: ifft_core.m,v 1.6 2011/02/14 19:33:35 ingo Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function bs = ifft_core(bs, type)
  
  switch class(bs.data)
    case {'fsdata'}
      fs     = bs.data.fs;
      % check fft type
      if any((bs.data.x)<0) % two sided fft
        utils.helper.msg(utils.const.msg.PROC1, 'two sided fft');
        y = ifftshift(bs.data.y);
      else
        % get minimum frequency step
        df = bs.data.x(end)-bs.data.x(end-1);
        if abs(((fs-df)-bs.data.x(end)))<eps % plain fft
          utils.helper.msg(utils.const.msg.PROC1, 'plain fft');
          y = bs.data.y;
        elseif abs((bs.data.x(end)-fs/2))<eps % onesided fft even nfft
          utils.helper.msg(utils.const.msg.PROC1, 'one sided fft even nfft');
          y1 = bs.data.y(1:end);
          y2 = conj(bs.data.y(end-1:-1:2));
          if size(y1,1)==1 % raw
            y = [y1 y2];
          else
            y = [y1;y2];
          end
        else % onesided fft odd nfft
          utils.helper.msg(utils.const.msg.PROC1, 'one sided fft odd nfft');
          y1 = bs.data.y(1:end);
          y2 = conj(bs.data.y(end:-1:2));
          if size(y1,1)==1 % raw
            y = [y1 y2];
          else
            y = [y1;y2];
          end
        end
      end

      y    = ifft(y, type);
      % Keep the data shape if the input AO
      if size(bs.data.y, 1) == 1
        y = y.';
      end

      % make a new tsdata object
      fsd = tsdata(y, fs);
      fsd.setXunits('s');
      fsd.setYunits(bs.yunits);
      
      % Set data
      bs.data = fsd;
      % clear errors
      bs.clearErrors;
      
    case {'tsdata', 'cdata', 'xydata'}
      error('### I don''t work for time-series, constant or x/y data.');
    otherwise
      error('### unknown data type.')
  end
  
  
end