function S = my_spectrum( signal, framelength, frameshift, preemp, do_zero_mean )
  
% function S = my_spectrum( signal, framelength, frameshift, [ preemp ], [ do_zero_mean ] )
%
% Default: preemp = 0.97 and do_zero_mean = 1
%
% By Guillaume Lathoud - lathoud@idiap.ch - 2005
  
if nargin < 3
    error( [ mfilename ' needs at least 3 input arguments.' ] );
  end

  if ~exist( 'preemp', 'var' )
    preemp = 0.97;
  end
  
  if ~exist( 'do_zero_mean' )
    do_zero_mean = 1;
  end
  
  signal = signal(:);
  
  % Bufferize
  
  tmp_signal = buffer( [ 0; signal ], 1 + framelength, 1 + framelength - frameshift, 'nodelay' );
  
  if do_zero_mean
      
    % Zero-mean
  
    tmp_signal = tmp_signal - repmat( mean( tmp_signal, 1 ), framelength + 1, 1 );
    
  end
  
  % Pre-emphasis
  
  tmp_signal = tmp_signal( 2:end, : ) - preemp * tmp_signal( 1:end-1, : );

  % zero-padded FFT
  
  win = diag( sparse( hamming( framelength, 'periodic' ) ) );
  
  S = fft( win * tmp_signal, 2 * framelength, 1 );
  