v_rdct

PURPOSE ^

V_RDCT Discrete cosine transform of real data Y=(X,N,A,B)

SYNOPSIS ^

function y=v_rdct(x,n,a,b)

DESCRIPTION ^

V_RDCT     Discrete cosine transform of real data Y=(X,N,A,B)

  Inputs: x(m,k)   Real-valued input data; transform will be applied to columns 
          n        Transform length. x will be zero-padded or truncated to length n [default: m]
          a        Output scale factor [default: sqrt(2*n)]
          b        Output scale factor for DC term [default: 1]

 Outputs: y(n,k)   Output data

 This routine is equivalent to multiplying by the matrix

   v_rdct(eye(n)) = diag([sqrt(2)*B/A repmat(2/A,1,n-1)]) * cos((0:n-1)'*(0.5:n)*pi/n)

 Default values of the scaling factors are A=sqrt(2N) and B=1 which
 results in an orthogonal matrix. Other common values are A=1 or N and/or B=1 or sqrt(2).
 If b~=1 then the columns are no longer orthogonal.

 see IRDCT for the inverse transform

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function y=v_rdct(x,n,a,b)
0002 %V_RDCT     Discrete cosine transform of real data Y=(X,N,A,B)
0003 %
0004 %  Inputs: x(m,k)   Real-valued input data; transform will be applied to columns
0005 %          n        Transform length. x will be zero-padded or truncated to length n [default: m]
0006 %          a        Output scale factor [default: sqrt(2*n)]
0007 %          b        Output scale factor for DC term [default: 1]
0008 %
0009 % Outputs: y(n,k)   Output data
0010 %
0011 % This routine is equivalent to multiplying by the matrix
0012 %
0013 %   v_rdct(eye(n)) = diag([sqrt(2)*B/A repmat(2/A,1,n-1)]) * cos((0:n-1)'*(0.5:n)*pi/n)
0014 %
0015 % Default values of the scaling factors are A=sqrt(2N) and B=1 which
0016 % results in an orthogonal matrix. Other common values are A=1 or N and/or B=1 or sqrt(2).
0017 % If b~=1 then the columns are no longer orthogonal.
0018 %
0019 % see IRDCT for the inverse transform
0020 
0021 % Bugs/Suggestions:
0022 %   (1) in line 51 we should maybe do truncation after transform and not before
0023 %   (2) should be able to choose which dimension to perform the transform
0024 %   (3) should cope with multi-dimensional input array
0025 
0026 %      Copyright (C) Mike Brookes 1998-2018
0027 %      Version: $Id: v_rdct.m 10865 2018-09-21 17:22:45Z dmb $
0028 %
0029 %   VOICEBOX is a MATLAB toolbox for speech processing.
0030 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
0031 %
0032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0033 %   This program is free software; you can redistribute it and/or modify
0034 %   it under the terms of the GNU General Public License as published by
0035 %   the Free Software Foundation; either version 2 of the License, or
0036 %   (at your option) any later version.
0037 %
0038 %   This program is distributed in the hope that it will be useful,
0039 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0040 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0041 %   GNU General Public License for more details.
0042 %
0043 %   You can obtain a copy of the GNU General Public License from
0044 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0045 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0047 
0048 fl=size(x,1)==1;
0049 if fl x=x(:); end
0050 [m,k]=size(x);
0051 if nargin<2 n=m;
0052 end
0053 if nargin<4 b=1;
0054     if nargin<3 a=sqrt(2*n);
0055     end
0056 end
0057 if n>m x=[x; zeros(n-m,k)];
0058 elseif n<m x(n+1:m,:)=[];
0059 end
0060 
0061 x=[x(1:2:n,:); x(2*fix(n/2):-2:2,:)];
0062 z=[sqrt(2) 2*exp((-0.5i*pi/n)*(1:n-1))].';
0063 y=real(fft(x).*z(:,ones(1,k)))/a;
0064 y(1,:)=y(1,:)*b;
0065 if fl y=y.'; end

Generated by m2html © 2003