Home > voicebox > ditherq.m

ditherq

PURPOSE ^

DITHERQ add dither and quantize [Y,ZF]=(X,M,ZI)

SYNOPSIS ^

function [y,zf]=ditherq(x,m,zi)

DESCRIPTION ^

DITHERQ  add dither and quantize [Y,ZF]=(X,M,ZI)
  Inputs:
      x   is the input signal
       m   specifies the mode:
          'w'  white dither (default)
          'h'  high-pass dither (filtered by 1 - z^-1)
          'l'  low pass filter  (filtered by 1 + z^-1)
          'n'  no dither

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [y,zf]=ditherq(x,m,zi)
0002 %DITHERQ  add dither and quantize [Y,ZF]=(X,M,ZI)
0003 %  Inputs:
0004 %      x   is the input signal
0005 %       m   specifies the mode:
0006 %          'w'  white dither (default)
0007 %          'h'  high-pass dither (filtered by 1 - z^-1)
0008 %          'l'  low pass filter  (filtered by 1 + z^-1)
0009 %          'n'  no dither
0010 
0011 %      Copyright (C) Mike Brookes 1997
0012 %      Version: $Id: ditherq.m 713 2011-10-16 14:45:43Z dmb $
0013 %
0014 %   VOICEBOX is a MATLAB toolbox for speech processing.
0015 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0016 %
0017 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0018 %   This program is free software; you can redistribute it and/or modify
0019 %   it under the terms of the GNU General Public License as published by
0020 %   the Free Software Foundation; either version 2 of the License, or
0021 %   (at your option) any later version.
0022 %
0023 %   This program is distributed in the hope that it will be useful,
0024 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 %   GNU General Public License for more details.
0027 %
0028 %   You can obtain a copy of the GNU General Public License from
0029 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0030 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0032 
0033 s=size(x);
0034 n=length(x);
0035 if nargin<3 | ~length(zi)
0036     zi=rand(1);
0037 end
0038     if nargin<2
0039         m='w';
0040     end
0041 if any(m=='n')
0042     y=round(x);
0043 elseif any(m=='h') | any(m=='l')
0044     v=rand(n+1,1);
0045     v(1)=zi;
0046     zf=v(end);
0047     if any(m=='h')
0048         y=round(x(:)+v(2:end)-v(1:end-1));
0049     else
0050         y=round(x(:)+v(2:end)+v(1:end-1)-1);
0051     end
0052 else
0053     y=round(x(:)+rand(n,2)*[1;-1]);
0054     zf=rand(1);                         % output a random number anyway
0055 end
0056 if s(1)==1
0057     y=y.';
0058 end

Generated on Tue 10-Oct-2017 08:30:10 by m2html © 2003