# v_teager

## PURPOSE

V_TEAGER calculate v_teager energy waveform Y=(X,D,M)

## SYNOPSIS

function y=v_teager(x,d,m)

## DESCRIPTION

    V_TEAGER calculate v_teager energy waveform Y=(X,D,M)

      Inputs:  x         speech signal
               d         dimension to apply filter along [default 1st non-singleton]
               m         Normally Y has the same length as X and the first
                         and last output samples are extrapolated. Setting m='x'
                         supresses this extrapolation and Y will be two
                         samples shorter than X

     Outputs:  Y         output signal: y(n)=abs(x(n))^2 - x(n+1)*conj(x(n-1))

     Calculates the Teager energy waveform [1]. The following waveforms give
     a constant output (independent of n) where A, B, C are real constants:
      (a) x(n) = A*sin(B*n+C)    -->   y(n) = (A*sin(B))^2
      (b) x(n) = A*n + B         -->   y(n) = A^2
      (c) x(n) = A*exp(j(B*n+C)) -->   y(n) = A^2*(1-exp(2jB))
      (d) x(n) = A*exp(B*n+C)    -->   y(n) = 0

     Reference:
      [1]    J. Kaiser. On a simple algorithm to calculate the "energy" of a signal.
           In Proc IEEE Intl Conf Acoustics, Speech and Signal Processing,
           pages 381-384, vol.1, Apr. 1990. doi: 10.1109/ICASSP.1990.115702.

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 function y=v_teager(x,d,m)
    0002 %V_TEAGER calculate v_teager energy waveform Y=(X,D,M)
    0003 %
    0004 %  Inputs:  x         speech signal
    0005 %           d         dimension to apply filter along [default 1st non-singleton]
    0006 %           m         Normally Y has the same length as X and the first
    0007 %                     and last output samples are extrapolated. Setting m='x'
    0008 %                     supresses this extrapolation and Y will be two
    0009 %                     samples shorter than X
    0010 %
    0011 % Outputs:  Y         output signal: y(n)=abs(x(n))^2 - x(n+1)*conj(x(n-1))
    0012 %
    0013 % Calculates the Teager energy waveform [1]. The following waveforms give
    0014 % a constant output (independent of n) where A, B, C are real constants:
    0015 %  (a) x(n) = A*sin(B*n+C)    -->   y(n) = (A*sin(B))^2
    0016 %  (b) x(n) = A*n + B         -->   y(n) = A^2
    0017 %  (c) x(n) = A*exp(j(B*n+C)) -->   y(n) = A^2*(1-exp(2jB))
    0018 %  (d) x(n) = A*exp(B*n+C)    -->   y(n) = 0
    0019 %
    0020 % Reference:
    0021 %  [1]    J. Kaiser. On a simple algorithm to calculate the "energy" of a signal.
    0022 %       In Proc IEEE Intl Conf Acoustics, Speech and Signal Processing,
    0023 %       pages 381-384, vol.1, Apr. 1990. doi: 10.1109/ICASSP.1990.115702.
    0024
    0025 %      Copyright (C) Mike Brookes 1997
    0026 %      Version: $Id: v_teager.m 10865 2018-09-21 17:22:45Z dmb $
    0027 %
    0028 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0029 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0030 %
    0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0032 %   This program is free software; you can redistribute it and/or modify
    0033 %   it under the terms of the GNU Lesser General Public License as published by
    0034 %   the Free Software Foundation; either version 3 of the License, or
    0035 %   (at your option) any later version.
    0036 %
    0037 %   This program is distributed in the hope that it will be useful,
    0038 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0039 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0040 %   GNU Lesser General Public License for more details.
    0041 %
    0042 %   You can obtain a copy of the GNU Lesser General Public License from
    0043 %   https://www.gnu.org/licenses/ .
    0044 %
    0045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0046 e=size(x);
    0047 p=prod(e);
    0048 if nargin<2             % if no dimension given, find the first non-singleton
    0049     d=find(e>1,1);
    0050     if ~numel(d)
    0051         d=1;
    0052     end
    0053 end
    0054 k=e(d);                 % size of active dimension
    0055 q=p/k;                  % size of remainder
    0056 if d==1
    0057     z=reshape(x,k,q);
    0058 else
    0059     z=shiftdim(x,d-1);
    0060     r=size(z);
    0061     z=reshape(z,k,q);
    0062 end
    0063 if nargin>2 && any(m=='x')
    0064     y=z(2:k-1,:).*conj(z(2:k-1,:))-z(3:k,:).*conj(z(1:k-2,:));
    0065     k=k-2;              % we have lost two elements
    0066 elseif k>=4
    0067     y=zeros(k,q);
    0068     y(2:k-1,:)=z(2:k-1,:).*conj(z(2:k-1,:))-z(3:k,:).*conj(z(1:k-2,:));
    0069     y(1,:)=2*y(2,:)-y(3,:);             % linearly interpolate the end points
    0070     y(k,:)=2*y(k-1,:)-y(k-2,:);
    0071 elseif k==3
    0072     y=repmat(x(2,:).*conj(x(2,:))-x(3,:).*conj(x(1,:)),3,1);
    0073 else
    0074     y=zeros(k,q);
    0075 end
    0076 if d==1
    0077     e(d)=k;
    0078     y=reshape(y,e);
    0079 else
    0080     r(1)=k;
    0081     y=shiftdim(reshape(y,r),length(e)+1-d);
    0082 end