QRABS absolute value and normalization of a real quaternions [m,q]=[q1] Inputs: q1(4n,...) A real quaternion array. Each quaternion is a column vector of the form [r, i, j, k]' Outputs: m(n,...) Array of quaternion magnitudes: m=sqrt(q'*q) q(4n,...) Normalized version of q1 with unit magnitude a zero quaternion is normalized to [1 0 0 0]'

0001 function [m,q]=qrabs(q1) 0002 %QRABS absolute value and normalization of a real quaternions [m,q]=[q1] 0003 % 0004 % Inputs: q1(4n,...) A real quaternion array. Each quaternion is a column 0005 % vector of the form [r, i, j, k]' 0006 % 0007 % Outputs: m(n,...) Array of quaternion magnitudes: m=sqrt(q'*q) 0008 % q(4n,...) Normalized version of q1 with unit magnitude 0009 % a zero quaternion is normalized to [1 0 0 0]' 0010 0011 % Copyright (C) Mike Brookes 2000-2012 0012 % Version: $Id: qrabs.m 1645 2012-03-16 17:00:15Z 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 q1=randn(8,3); 0033 q1(9:12)=0; 0034 s=size(q1); 0035 q=reshape(q1,4,[]); 0036 m=sqrt(sum(q.^2,1)); 0037 q(:,m>0)=q(:,m>0)./m(ones(4,1),m>0); 0038 q(1,m<=0)=1; 0039 q=reshape(q,s); 0040 s(1)=s(1)/4; 0041 m=reshape(m,s);

Generated on Fri 22-Sep-2017 19:37:38 by