## octave-cvsupdate

 [Octave-cvsupdate] SF.net SVN: octave:[5705] trunk/octave-forge/main/comm/inst From: - 2009-04-13 22:16:34 ```Revision: 5705 http://octave.svn.sourceforge.net/octave/?rev=5705&view=rev Author: gnumuthu Date: 2009-04-13 22:16:33 +0000 (Mon, 13 Apr 2009) Log Message: ----------- PRBS : Pseudo Random Binary sequence generator Added Paths: ----------- trunk/octave-forge/main/comm/inst/prbs_generator.m trunk/octave-forge/main/comm/inst/prbs_iterator.m trunk/octave-forge/main/comm/inst/prbs_sequence.m Added: trunk/octave-forge/main/comm/inst/prbs_generator.m =================================================================== --- trunk/octave-forge/main/comm/inst/prbs_generator.m (rev 0) +++ trunk/octave-forge/main/comm/inst/prbs_generator.m 2009-04-13 22:16:33 UTC (rev 5705) @@ -0,0 +1,50 @@ +## +## (C) 2006 Muthiah Annamalai +## +## Implement book keeping for a Pseudo-Random Binary Sequence ( PRBS ) +## also called as a Linear Feedback Shift Register. +## +## Given a polynomial create a PRBS structure for that polynomial. +## Now all we need is to just create this polynomial and make it work. +## polynomial must be a vector containing the powers of x and an optional +## value 1. eg: x^3 + x^2 + x + 1 must be written as [3 2 1 0] +## all the coefficients are either 1 or 0. It generates only a Binary \ +## sequence, and the generator polynomial need to be only a binary +## polynomial in GF(2). +## +## connections, contains a struct of vectors where each vector is the +## connection list mapping its vec(2:end) elements to the vec(1) output. +## +## Example: If you had a PRBS shift register like the diagram +## below with 4 registers we use representation by polynomial +## of [ 1 2 3 4], and feedback connections between [ 1 3 4 ]. +## The output PRBS sequence is taken from the position 4. +## +## +---+ +----+ +---+ +---+ +## | D |----| D |---| D |---| D | +## +---+ +----+ +---+ +---+ +## | | | +## \ / / +## [+]---------------+------+ +## 1 + 0.D + 1.D^2 + 1.D^3 +## +## The code to implement this PRBS with a start state of [1 0 1 1] +## will be: +## +## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]); +## x = prbs_sequence(prbs) #gives 15 +## +## prbs_iterator( prbs, 15 ) #15 binary digits seen +## [ 1 1 0 1 0 1 1 1 1 0 0 0 1 0 0 ] +## +## See Also: This function is to be used along with functions +## prbs_iterator, and prbs_sequence. +## +function prbs=prbs_generator(polynomial,connections,initstate) + prbs.reglen=max(polynomial); + prbs.polynomial=polynomial; + prbs.sregs=initstate; + prbs.connections=connections; + prbs.conlen=length(connections); + return +end Property changes on: trunk/octave-forge/main/comm/inst/prbs_generator.m ___________________________________________________________________ Added: svn:executable + * Added: trunk/octave-forge/main/comm/inst/prbs_iterator.m =================================================================== --- trunk/octave-forge/main/comm/inst/prbs_iterator.m (rev 0) +++ trunk/octave-forge/main/comm/inst/prbs_iterator.m 2009-04-13 22:16:33 UTC (rev 5705) @@ -0,0 +1,125 @@ +## +## (C) 2006 Muthiah Annamalai +## +## This function generates the output bits from the PRBS +## state, for the number of iterations specified. +## +## First argument is the PRBS structure obtained from prbs_generator. +## PRBS iterations is specified in the second argument. +## PRBS start state is taken from the prbs.sregs. +## +## Example: If you had a PRBS shift register like the diagram +## below with 4 registers we use representation by polynomial +## of [ 1 2 3 4], and feedback connections between [ 1 3 4 ]. +## The output PRBS sequence is taken from the position 4. +## +## +---+ +----+ +---+ +---+ +## | D |----| D |---| D |---| D | +## +---+ +----+ +---+ +---+ +## | | | +## \ / / +## [+]---------------+------+ +## 1 + 0.D + 1.D^2 + 1.D^3 +## +## The code to implement this PRBS will be +## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]); +## x = prbs_iterator(prbs,15) +## +## See Also: This function is to be used along with functions +## prbs_iterator, prbs_generator and prbs_sequence. +## +function outputseq=prbs_iterator(prbs,iterations) + if ( nargin < 2 ) + iterations=2^(prbs.reglen)-1; + end + outputseq=zeros(1,iterations); + nstate=zeros(1,prbs.reglen); + + ## For each iteration, shift the output bit. Then compute the xor pattern of connections. + ## Finally apply feedback the stuff. Insert the computed pattern. + for itr=1:iterations + ## save output. + outputseq(itr)=prbs.sregs(prbs.reglen); + + ## compute the feedback. + for itr2=1:prbs.conlen + val=0; + L=length(prbs.connections{itr2}); + for itr3=2:L + val=bitxor(val,prbs.sregs(prbs.connections{itr2}(itr3))); + end + nstate(prbs.connections{itr2}(1))=val; + end + + ## rotate the output discarding the last output. + prbs.sregs=[0 prbs.sregs(1:prbs.reglen-1)]; + + ## insert the feedback. + for itr2=1:prbs.conlen + prbs.sregs(itr2)=nstate(itr2); + nstate(itr2)=0; # reset. + end + + end + return; +end + +## +## TEST CASES FOR PRBS. +## +## +## 2^31 -1 : D31 + D28 + 1 =0 inverted +## 2^23 -1 : D23 + D18 + 1 = 0 , +## 2^15 -1 : D15 + D14 + 1 = 0, +## 2^10 -1 : D10 + D7 + 1 = 0, +## 2^7 -1 : D7 + D6 + 1 = 0, +## 2^4 -1 : D3 + D2 + 1 = 0, +## +## +---+ +----+ +---+ +---+ +## | D |----| D |---| D |---| D | +## +---+ +----+ +---+ +---+ +## | | | +## \ / / +## [+]---------------+------+ +## 1 + 0.D + 1.D^2 + 1.D^3 +## +## +## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]); +## x = prbs_iterator(prbs,15) +## y = prbs_iterator(prbs,30)(16:end) +## z = prbs_sequence(prbs) +## exit +## break + +## +## Multiple Tap, Simple Sequence Generator. +## +## n=10; +## k=8; +## inits=round(abs(rand(1,n)*1.0)) +## prbs=prbs_generator([n 1],{[1 2 k n-1 n]},inits); +## prbs_iterator(prbs,1023) +## prbs_seqlength(prbs,inits) + +##prbs=prbs_generator([1 2 3],{[1 2 3]},[1 1 1]); +##prbs_iterator(prbs,7) + +## +## 2^4 -1 : D4 + D1 + 1 = 0, +## +## +---+ +----+ +---+ +---+ +## | D |----| D |---| D |---| D | +## +---+ +----+ +---+ +---+ +## | | | +## \ / / +## [+]---------------+------+ +## 1 + 0.D + 1.D^2 + 1.D^3 +## +##prbs=prbs_generator([1 3 4],{[1 2 4]},[1 0 1 1]); +##prbs_iterator(prbs,16) +##prbs_iterator(prbs,32) + + +##prbs=prbs_generator([7],{[1 7 6]},[1 0 0 1 0 0 0]); +##y=prbs_iterator(prbs,128); +##x=prbs_iterator(prbs,256); Property changes on: trunk/octave-forge/main/comm/inst/prbs_iterator.m ___________________________________________________________________ Added: svn:executable + * Added: trunk/octave-forge/main/comm/inst/prbs_sequence.m =================================================================== --- trunk/octave-forge/main/comm/inst/prbs_sequence.m (rev 0) +++ trunk/octave-forge/main/comm/inst/prbs_sequence.m 2009-04-13 22:16:33 UTC (rev 5705) @@ -0,0 +1,73 @@ +## +## (C) 2006 Muthiah Annamalai +## +## Implement book keeping for a Pseudo-Random Binary Sequence ( PRBS ) +## also called as a Linear Feedback Shift Register. +## +## For the given PRBS in a intial state, compute the PRBS sequence length. +## Length is period of output when the PRBS state is same as +## the start state of PRBS. +## +## Example: If you had a PRBS shift register like the diagram +## below with 4 registers we use representation by polynomial +## of [ 1 2 3 4], and feedback connections between [ 1 3 4 ]. +## The output PRBS sequence is taken from the position 4. +## +## +---+ +----+ +---+ +---+ +## | D |----| D |---| D |---| D | +## +---+ +----+ +---+ +---+ +## | | | +## \ / / +## [+]---------------+------+ +## 1 + 0.D + 1.D^2 + 1.D^3 +## +## The code to implement this PRBS will be +## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]); +## x = prbs_sequence(prbs) #gives 15 +## + +## See Also: This function is to be used along with functions +## prbs_generator. +## +function itrs=prbs_sequence(prbs) + if nargin < 1 + error("usage: prbs_sequence(prbs struct ); \ + create the prbs sequence using prbs_generator() function. \ + This function generates the ML length sequence of 1 period\ + and returns to the user.") + end + nstate=zeros(1,prbs.reglen); + itrs=0; + inits = prbs.sregs; + + ## For each iteration, shift the output bit. Then compute the xor pattern of connections. + ## Finally apply feedback the stuff. Insert the computed pattern. + while( true ) + itrs = itrs + 1; + + ## compute the feedback. + for itr2=1:prbs.conlen + val=0; + L=length(prbs.connections{itr2}); + for itr3=2:L + val=bitxor(val,prbs.sregs(prbs.connections{itr2}(itr3))); + end + nstate(prbs.connections{itr2}(1))=val; + end + + ## rotate the output discarding the last output. + prbs.sregs=[0 prbs.sregs(1:prbs.reglen-1)]; + + ## insert the feedback. + for itr2=1:prbs.conlen + prbs.sregs(itr2)=nstate(itr2); + nstate(itr2)=0; # reset. + end + + if(isequal(prbs.sregs,inits)) + break; + end + end + + return; +end Property changes on: trunk/octave-forge/main/comm/inst/prbs_sequence.m ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[5855] trunk/octave-forge/main/comm/inst From: - 2009-05-22 12:48:22 ```Revision: 5855 http://octave.svn.sourceforge.net/octave/?rev=5855&view=rev Author: rlaboiss Date: 2009-05-22 12:48:17 +0000 (Fri, 22 May 2009) Log Message: ----------- Fix permission of prbs_*.m scripts Property Changed: ---------------- trunk/octave-forge/main/comm/inst/prbs_generator.m trunk/octave-forge/main/comm/inst/prbs_iterator.m trunk/octave-forge/main/comm/inst/prbs_sequence.m Property changes on: trunk/octave-forge/main/comm/inst/prbs_generator.m ___________________________________________________________________ Deleted: svn:executable - * Property changes on: trunk/octave-forge/main/comm/inst/prbs_iterator.m ___________________________________________________________________ Deleted: svn:executable - * Property changes on: trunk/octave-forge/main/comm/inst/prbs_sequence.m ___________________________________________________________________ Deleted: svn:executable - * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[6036] trunk/octave-forge/main/comm/inst From: - 2009-07-20 20:39:24 ```Revision: 6036 http://octave.svn.sourceforge.net/octave/?rev=6036&view=rev Author: hauberg Date: 2009-07-20 20:39:23 +0000 (Mon, 20 Jul 2009) Log Message: ----------- Make qaskenco and qaskdeco handle NDArrays. Add tests (from David Bateman) Modified Paths: -------------- trunk/octave-forge/main/comm/inst/qaskdeco.m trunk/octave-forge/main/comm/inst/qaskenco.m Modified: trunk/octave-forge/main/comm/inst/qaskdeco.m =================================================================== --- trunk/octave-forge/main/comm/inst/qaskdeco.m 2009-07-20 13:32:17 UTC (rev 6035) +++ trunk/octave-forge/main/comm/inst/qaskdeco.m 2009-07-20 20:39:23 UTC (rev 6036) @@ -166,10 +166,10 @@ a = a'; endif - if (any(isnan(a))) + if (any(isnan(a(:)))) ## We have a non-square constellation, with some invalid points. ## Map to nearest valid constellation points... - indx = find(isnan(a)); + indx = find(isnan(a(:))); ix = ix(indx); qx = qx(indx); ang = atan2(quadr(indx),inphase(indx)); @@ -191,3 +191,25 @@ end_unwind_protect endfunction + +%!function dec = __fntestqask1__ (msg, m) +%! [inp, qudr] = qaskenco (msg, m); +%! dec = qaskdeco (inp, qudr, m); + +%!function __fntestqask2__ (m, dims) +%! msg = floor( rand(dims) * m); +%! assert (__fntestqask1__ (msg, m), msg); + +%!test __fntestqask2__ (2, [100,100]) +%!test __fntestqask2__ (4, [100,100]) +%!test __fntestqask2__ (8, [100,100]) +%!test __fntestqask2__ (16, [100,100]) +%!test __fntestqask2__ (32, [100,100]) +%!test __fntestqask2__ (64, [100,100]) + +%!test __fntestqask2__ (2, [100,100,3]) +%!test __fntestqask2__ (4, [100,100,3]) +%!test __fntestqask2__ (8, [100,100,3]) +%!test __fntestqask2__ (16, [100,100,3]) +%!test __fntestqask2__ (32, [100,100,3]) +%!test __fntestqask2__ (64, [100,100,3]) Modified: trunk/octave-forge/main/comm/inst/qaskenco.m =================================================================== --- trunk/octave-forge/main/comm/inst/qaskenco.m 2009-07-20 13:32:17 UTC (rev 6035) +++ trunk/octave-forge/main/comm/inst/qaskenco.m 2009-07-20 20:39:23 UTC (rev 6036) @@ -64,7 +64,7 @@ if (nargin == 1) M = msg; elseif (nargin == 2) - if ((min(msg) < 0) || (max(msg) > M-1)) + if ((min(msg(:)) < 0) || (max(msg(:)) > M-1)) error ("qaskenco: message invalid"); endif else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[7377] trunk/octave-forge/main/comm/inst From: - 2010-06-01 02:37:54 ```Revision: 7377 http://octave.svn.sourceforge.net/octave/?rev=7377&view=rev Author: mborg Date: 2010-06-01 02:37:48 +0000 (Tue, 01 Jun 2010) Log Message: ----------- new interleavers Added Paths: ----------- trunk/octave-forge/main/comm/inst/helintrlv.m trunk/octave-forge/main/comm/inst/helscandeintrlv.m trunk/octave-forge/main/comm/inst/helscanintrlv.m Added: trunk/octave-forge/main/comm/inst/helintrlv.m =================================================================== --- trunk/octave-forge/main/comm/inst/helintrlv.m (rev 0) +++ trunk/octave-forge/main/comm/inst/helintrlv.m 2010-06-01 02:37:48 UTC (rev 7377) @@ -0,0 +1,72 @@ +## Copyright (C) 2010 Mark Borgerding +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{outdata} =} helintrlv (@var{data}, @var{col}, @var{ngrp},@var{stp}) +## @var{col}-by-@...{ngrp}. +## @seealso{heldeintrlv} +## @end deftypefn + +function [outdata,outstate] = helintrlv(data,col,ngrp,stp,init_state) + + if (nargin < 4 ||nargin>5) + error('usage : interlvd = helintrlv(data,col,ngrp,stp)'); + end + + if(~isscalar(col) || ~isscalar(ngrp)) + error("col and ngrp must be integers"); + end + + if( col ~= floor(col)|| ngrp ~= floor(ngrp)) + error("col and ngrp must be integers"); + end + + didTranspose=0; + if ( isvector(data) && columns(data) > rows(data) ) + data = data.'; + didTranspose=1; + end + + s = size(data); + + if s(1) ~= col*ngrp + error("The length of data must be equals to ngrp*col"); + end + + if nargin==4 + init_state = zeros(stp*col*(col-1)/2,s(2)); + end + + outstate =[]; + # for each column + for k = 1:s(2) + tmp = reshape( data(:,k) , ngrp, col ); + instate = init_state(:,k); + outstateCol=[]; + for k1=2:col + curStepSize = (k1-1)*stp; + tmpCol= [instate(1:curStepSize) ;tmp(:,k1)]; + tmp(:,k1) = tmpCol(1:ngrp); + outstateCol=[outstateCol;tmpCol(end+1-curStepSize:end)]; + instate = instate(curStepSize+1:end); + end + outdata(:,k) = reshape(tmp.',s(1),1); + outstate = [outstate outstateCol]; + end + + if didTranspose + outdata = outdata.'; + end Added: trunk/octave-forge/main/comm/inst/helscandeintrlv.m =================================================================== --- trunk/octave-forge/main/comm/inst/helscandeintrlv.m (rev 0) +++ trunk/octave-forge/main/comm/inst/helscandeintrlv.m 2010-06-01 02:37:48 UTC (rev 7377) @@ -0,0 +1,24 @@ +## Copyright (C) 2010 Mark Borgerding +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{outdata} =} helscandeintrlv (@var{data}, @var{nrows}, @var{ncols},@var{Nshift}) +## @var{nrows}-by-@...{ncols}. +## @seealso{helscandeintrlv} +## @end deftypefn + +function outdata = helscandeintrlv(data,Nrows,Ncols,Nshift) + outdata = helscanintrlv(data,Nrows,Ncols,Nrows-Nshift); Added: trunk/octave-forge/main/comm/inst/helscanintrlv.m =================================================================== --- trunk/octave-forge/main/comm/inst/helscanintrlv.m (rev 0) +++ trunk/octave-forge/main/comm/inst/helscanintrlv.m 2010-06-01 02:37:48 UTC (rev 7377) @@ -0,0 +1,62 @@ +## Copyright (C) 2010 Mark Borgerding +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{outdata} =} helscanintrlv (@var{data}, @var{nrows}, @var{ncols},@var{Nshift}) +## @var{nrows}-by-@...{ncols}. +## @seealso{helscandeintrlv} +## @end deftypefn + +function outdata = helscanintrlv(data,Nrows,Ncols,Nshift) + + if(nargin ~= 4 ) + error('usage : interlvd = helscanintrlv(data,Nrows,Ncols,Nshift)'); + end + + if(~isscalar(Nrows) || ~isscalar(Ncols)) + error("Nrows and Ncols must be integers"); + end + + if( Nrows ~= floor(Nrows)|| Ncols ~= floor(Ncols)) + error("Nrows and Ncols must be integers"); + end + + didTranspose=0; + if ( isvector(data) && columns(data) > rows(data) ) + data = data.'; + didTranspose=1; + end + + s = size(data); + + if size(data,1) ~= Nrows*Ncols + error("The length of data must be equals to Ncols*Nrows"); + end + + # create the interleaving indices + idx0 = 0:Nrows*Ncols-1; + idxMod = rem(idx0,Ncols); + idxFlr = idx0 - idxMod; + inds = 1+rem(idxFlr + idxMod * Ncols * Nshift + idxMod,Nrows*Ncols); + + # for each column + for k = 1:s(2) + outdata(:,k) = data(inds,k); + end + + if didTranspose + outdata = outdata.'; + end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[8279] trunk/octave-forge/main/comm/inst From: - 2011-05-23 20:56:24 ```Revision: 8279 http://octave.svn.sourceforge.net/octave/?rev=8279&view=rev Author: adb014 Date: 2011-05-23 20:56:18 +0000 (Mon, 23 May 2011) Log Message: ----------- yet more updates of the communication package for Octave 3.4 Modified Paths: -------------- trunk/octave-forge/main/comm/inst/@galois/conv.m trunk/octave-forge/main/comm/inst/@galois/deconv.m trunk/octave-forge/main/comm/inst/bchpoly.m trunk/octave-forge/main/comm/inst/comms.m trunk/octave-forge/main/comm/inst/cosets.m trunk/octave-forge/main/comm/inst/minpol.m trunk/octave-forge/main/comm/inst/rsgenpoly.m Removed Paths: ------------- trunk/octave-forge/main/comm/inst/gfft.m Modified: trunk/octave-forge/main/comm/inst/@galois/conv.m =================================================================== --- trunk/octave-forge/main/comm/inst/@galois/conv.m 2011-05-22 19:32:41 UTC (rev 8278) +++ trunk/octave-forge/main/comm/inst/@galois/conv.m 2011-05-23 20:56:18 UTC (rev 8279) @@ -51,10 +51,10 @@ ## Ensure that both vectors are row vectors. if (rows (a) > 1) - a = greshape (a, 1, la); + a = reshape (a, 1, la); endif if (rows (b) > 1) - b = greshape (b, 1, lb); + b = reshape (b, 1, lb); endif ## Use the shortest vector as the coefficent vector to filter. @@ -66,7 +66,7 @@ else x = b; endif - y = gfilter (a, 1, x); + y = filter (a, 1, x); else if(ly > la) ## Can't concatenate galois variables like this yet @@ -75,7 +75,7 @@ else x = a; endif - y = gfilter (b, 1, x); + y = filter (b, 1, x); endif endfunction Modified: trunk/octave-forge/main/comm/inst/@galois/deconv.m =================================================================== --- trunk/octave-forge/main/comm/inst/@galois/deconv.m 2011-05-22 19:32:41 UTC (rev 8278) +++ trunk/octave-forge/main/comm/inst/@galois/deconv.m 2011-05-23 20:56:18 UTC (rev 8279) @@ -18,13 +18,13 @@ ## Deconvolve two Galois vectors. ## ## @code{[b, r] = deconv (y, a)} solves for @var{b} and @var{r} such that -## @code{y = gconv (a, b) + r}. +## @code{y = conv (a, b) + r}. ## ## If @var{y} and @var{a} are polynomial coefficient vectors, @var{b} will ## contain the coefficients of the polynomial quotient and @var{r} will be ## a remander polynomial of lowest order. ## @end deftypefn -## @seealso{gconv,deconv,conv} +## @seealso{conv} function [b, r] = deconv (y, a) @@ -70,11 +70,11 @@ lc = la + length (b) - 1; if (ly == lc) - r = y - gconv (a, b); + r = y - conv (a, b); else ## Can't concatenate galois variables like this yet - ## r = [(zeros (1, lc - ly)), y] - gconv (a, b); - r = gf([(zeros (1, lc - ly)), y], y.m, y.prim_poly) - gconv (a, b); + ## r = [(zeros (1, lc - ly)), y] - conv (a, b); + r = gf([(zeros (1, lc - ly)), y], y.m, y.prim_poly) - conv (a, b); endif endfunction Modified: trunk/octave-forge/main/comm/inst/bchpoly.m =================================================================== --- trunk/octave-forge/main/comm/inst/bchpoly.m 2011-05-22 19:32:41 UTC (rev 8278) +++ trunk/octave-forge/main/comm/inst/bchpoly.m 2011-05-23 20:56:18 UTC (rev 8279) @@ -145,7 +145,7 @@ for t=1:floor(n(ni)/2) for i=1:nc if (fc(i) != 1) - cl = glog(c{i}); + cl = log(c{i}); for j=2*(t-1)+1:2*t if (find(cl == j)) f = [f, c{i}.x]; @@ -182,14 +182,14 @@ f0 = f1; for i=1:nc if (fc(i) != 1) - cl = glog(c{i}); + cl = log(c{i}); for j=2*(t-1)+1:2*t if (find(cl == j)) f1 = [f1, c{i}.x]; fc(i) = 1; ptmp = gf([c{i}(1), 1], m, prim); for l=2:length(c{i}) - ptmp = gconv(ptmp, [c{i}(l), 1]); + ptmp = conv(ptmp, [c{i}(l), 1]); end f = [f; [ptmp.x, zeros(1,m-length(ptmp)+1)]]; fl = fl + length(ptmp); @@ -216,7 +216,7 @@ p = gf([f0(1), 1], m, prim); for i=2:length(f0) - p = gconv(p, [f0(i), 1]); + p = conv(p, [f0(i), 1]); end p = p.x; Modified: trunk/octave-forge/main/comm/inst/comms.m =================================================================== --- trunk/octave-forge/main/comm/inst/comms.m 2011-05-22 19:32:41 UTC (rev 8278) +++ trunk/octave-forge/main/comm/inst/comms.m 2011-05-23 20:56:18 UTC (rev 8279) @@ -565,7 +565,7 @@ if (!isequal(y0,y1)) error("FAILED"); endif - roots1 = groots(poly1); + roots1 = roots(poly1); ck1 = polyval(poly1, roots1); if (any(ck1)) error("FAILED"); @@ -590,7 +590,7 @@ if (any(l*u-p*gmat)) error("FAILED"); endif - g1 = ginv(gmat); + g1 = inv(gmat); g2 = gmat ^ -1; if (any(g1*gmat != eye(matlen))) error("FAILED"); Modified: trunk/octave-forge/main/comm/inst/cosets.m =================================================================== --- trunk/octave-forge/main/comm/inst/cosets.m 2011-05-22 19:32:41 UTC (rev 8278) +++ trunk/octave-forge/main/comm/inst/cosets.m 2011-05-23 20:56:18 UTC (rev 8279) @@ -34,7 +34,7 @@ c{1} = gf(1,m,prim); found(1) = 1; nc = 2; - f = glog(gf(1:n,m,prim)); + f = log(gf(1:n,m,prim)); while ((!all(found))) t = find(!found); @@ -45,7 +45,7 @@ set =[set,r]; r = rem(r*2,n); end - c{nc} = gf(sort(gexp(gf(set,m,prim)).x),m,prim); + c{nc} = gf(sort(exp(gf(set,m,prim)).x),m,prim); found(c{nc}.x) = ones(1,length(c{nc})); nc = nc + 1; end Deleted: trunk/octave-forge/main/comm/inst/gfft.m =================================================================== --- trunk/octave-forge/main/comm/inst/gfft.m 2011-05-22 19:32:41 UTC (rev 8278) +++ trunk/octave-forge/main/comm/inst/gfft.m 2011-05-23 20:56:18 UTC (rev 8279) @@ -1,52 +0,0 @@ -## Copyright (C) 2002 David Bateman -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; If not, see ;. - -## -*- texinfo -*- -## @deftypefn {Function File} {} gfft (@var{x}) -## -## If @var{x} is a column vector, finds the FFT over the primitive element -## of the Galois Field of @var{x}. If @var{x} is in the Galois Field -## GF(2^@var{m}), then @var{x} must have @code{2^@var{m} - 1} elements. -## @end deftypefn -## @seealso{fft} - -## PKG_ADD: dispatch ("fft", "gfft", "galois"); -function y = gfft(x) - - if (nargin != 1) - error ("usage: y = gfft (x)"); - endif - - if (!isgalois(x)) - error("gfft: argument must be a galois variable"); - endif - - n = 2^x.m - 1; - if (n > 255) - error ([ "gfft: argument must be in Galois Field GF(2^m), where", ... - " m is not greater than 8"]); - endif - - alph = gf(2, x.m, x.prim_poly); - [nr,nc] = size(x); - if ((nc == 1) && (nr == n)) - y = gdftmtx(alph) * x; - elseif ((nc == n) && (nr == 1)) - y = (gdftmtx(alph) * x')'; - else - error ("gfft: argument must be a vector in GF(2^m) of length 2^m-1"); - endif - -endfunction Modified: trunk/octave-forge/main/comm/inst/minpol.m =================================================================== --- trunk/octave-forge/main/comm/inst/minpol.m 2011-05-22 19:32:41 UTC (rev 8278) +++ trunk/octave-forge/main/comm/inst/minpol.m 2011-05-23 20:56:18 UTC (rev 8279) @@ -61,7 +61,7 @@ ## Create the minimum polynomial from its roots ptmp = gf([1,rv(1)], m, prim_poly); for i=2:length(rv) - ptmp = gconv(ptmp, [1,rv(i)]); + ptmp = conv(ptmp, [1,rv(i)]); end ## Need to left-shift polynomial to divide by x while can Modified: trunk/octave-forge/main/comm/inst/rsgenpoly.m =================================================================== --- trunk/octave-forge/main/comm/inst/rsgenpoly.m 2011-05-22 19:32:41 UTC (rev 8278) +++ trunk/octave-forge/main/comm/inst/rsgenpoly.m 2011-05-23 20:56:18 UTC (rev 8279) @@ -145,7 +145,7 @@ g = gf(1, m, prim); for i= 1:2*t - g = gconv(g, gf([1,alph^((b+i-1)*s)], m, prim)); + g = conv(g, gf([1,alph^((b+i-1)*s)], m, prim)); end endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[10413] trunk/octave-forge/main/comm/inst From: - 2012-05-11 18:10:38 ```Revision: 10413 http://octave.svn.sourceforge.net/octave/?rev=10413&view=rev Author: jordigh Date: 2012-05-11 18:10:27 +0000 (Fri, 11 May 2012) Log Message: ----------- Fix whitespace in m-files Modified Paths: -------------- trunk/octave-forge/main/comm/inst/ademodce.m trunk/octave-forge/main/comm/inst/amdemod.m trunk/octave-forge/main/comm/inst/ammod.m trunk/octave-forge/main/comm/inst/amodce.m trunk/octave-forge/main/comm/inst/apkconst.m trunk/octave-forge/main/comm/inst/awgn.m trunk/octave-forge/main/comm/inst/bchpoly.m trunk/octave-forge/main/comm/inst/bi2de.m trunk/octave-forge/main/comm/inst/biterr.m trunk/octave-forge/main/comm/inst/compand.m trunk/octave-forge/main/comm/inst/convenc.m trunk/octave-forge/main/comm/inst/de2bi.m trunk/octave-forge/main/comm/inst/decode.m trunk/octave-forge/main/comm/inst/demodmap.m trunk/octave-forge/main/comm/inst/egolaydec.m trunk/octave-forge/main/comm/inst/egolayenc.m trunk/octave-forge/main/comm/inst/egolaygen.m trunk/octave-forge/main/comm/inst/encode.m trunk/octave-forge/main/comm/inst/eyediagram.m trunk/octave-forge/main/comm/inst/fibodeco.m Modified: trunk/octave-forge/main/comm/inst/ademodce.m =================================================================== --- trunk/octave-forge/main/comm/inst/ademodce.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/ademodce.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -133,11 +133,11 @@ y = y - offset; else if (min(size(y)) == 1) - y = y - mean(y); + y = y - mean(y); else - for i=1:size(y,2) - y(:,i) = y(:,i) - mean(y(:,i)); - end + for i=1:size(y,2) + y(:,i) = y(:,i) - mean(y(:,i)); + end endif endif elseif (strcmp(typ,"amdsb-sc")) @@ -178,7 +178,7 @@ y = filter(num,den, y); else for i=1:size(y,2) - y(:,i) = filter(num, den, y(:,i)); + y(:,i) = filter(num, den, y(:,i)); end endif endif Modified: trunk/octave-forge/main/comm/inst/amdemod.m =================================================================== --- trunk/octave-forge/main/comm/inst/amdemod.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/amdemod.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -1,4 +1,4 @@ -# Copyright (C) 2007 Sylvain Pelissier +## Copyright (C) 2007 Sylvain Pelissier ## ## This program is free software; you can redistribute it and/or modify it under ## the terms of the GNU General Public License as published by the Free Software @@ -21,10 +21,10 @@ ## @end deftypefn function [m] = amdemod(s,fc,fs) - if(nargin ~= 3) - usage("m = amdemod(s,fc,fs)"); - end - t = 0:1./fs:(length(s)-1)./fs; - e = s.*cos(2.*pi.*fc.*t); - [b a] = butter(5,fc.*2./fs); - m = filtfilt(b,a,e).*2; + if(nargin ~= 3) + usage("m = amdemod(s,fc,fs)"); + end + t = 0:1./fs:(length(s)-1)./fs; + e = s.*cos(2.*pi.*fc.*t); + [b a] = butter(5,fc.*2./fs); + m = filtfilt(b,a,e).*2; Modified: trunk/octave-forge/main/comm/inst/ammod.m =================================================================== --- trunk/octave-forge/main/comm/inst/ammod.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/ammod.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -21,10 +21,10 @@ function [y] = ammod(x,fc,fs) - if (nargin != 3) + if (nargin != 3) usage ("ammod(x,fs,fc)"); endif - l = length(x); - t=0:1./fs:(l-1)./fs; - y = x.*cos(2.*pi.*fc.*t); + l = length(x); + t=0:1./fs:(l-1)./fs; + y = x.*cos(2.*pi.*fc.*t); Modified: trunk/octave-forge/main/comm/inst/amodce.m =================================================================== --- trunk/octave-forge/main/comm/inst/amodce.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/amodce.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -146,7 +146,7 @@ elseif (strcmp(typ,"qam")) if (isreal(x)) if (floor(size(x,2)/2) != (size(x,2)/2)) - error ("amodce: QAM modulation must have an even number of columns for real signals"); + error ("amodce: QAM modulation must have an even number of columns for real signals"); endif y = (x(:,1:2:size(x,2)) + 1i * x(:,2:2:size(x,2))); else @@ -161,7 +161,7 @@ ## As x(t) is discrete and not a function, the only way to perform the ## above integration is with Simpson's rule. Note \Delta T = 2 * pi / Fs. pm = pi / Fs * dev * (cumsum([zeros(1,size(x,2));x(1:size(x,1)-1,:)]) ... - + cumsum(x)); + + cumsum(x)); y = exp(1i * (pm + iphs)); else error ("amodce: unknown modulation specified"); Modified: trunk/octave-forge/main/comm/inst/apkconst.m =================================================================== --- trunk/octave-forge/main/comm/inst/apkconst.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/apkconst.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -70,26 +70,26 @@ arg = varargin{i}; if (ischar(arg)) if (strcmp(arg,"n")) - try - text(); - printnums = 1; - catch - printnums = 0; - end + try + text(); + printnums = 1; + catch + printnums = 0; + end else - fmt = arg; + fmt = arg; endif else numargs++; switch (numargs) - case 1, - nsig = arg; - case 2, - amp = arg; - case 3, - phs = arg; - otherwise - error ("apkconst: too many numerical arguments"); + case 1, + nsig = arg; + case 2, + amp = arg; + case 3, + phs = arg; + otherwise + error ("apkconst: too many numerical arguments"); endswitch endif end @@ -121,7 +121,7 @@ error ("apkconst: must have at least one point in ASK radii"); endif y = [y; amp(i) * [cos(2*pi*[0:nsig(i)-1]'/nsig(i) + phs(i)) + ... - 1i*sin(2*pi*[0:nsig(i)-1]'/nsig(i) + phs(i))]]; + 1i*sin(2*pi*[0:nsig(i)-1]'/nsig(i) + phs(i))]]; end if (nargout == 0) @@ -134,7 +134,7 @@ if (printnums) xd = 0.05 * max(real(y)); for i=1:length(y) - text(real(y(i))+xd,imag(y(i)),num2str(i-1)); + text(real(y(i))+xd,imag(y(i)),num2str(i-1)); end endif plot (real(y), imag(y), fmt); Modified: trunk/octave-forge/main/comm/inst/awgn.m =================================================================== --- trunk/octave-forge/main/comm/inst/awgn.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/awgn.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -77,12 +77,12 @@ else narg++; switch (narg) - case 1, - p = arg; - case 2, - seed = arg; - otherwise - error ("wgn: too many arguments"); + case 1, + p = arg; + case 2, + seed = arg; + otherwise + error ("wgn: too many arguments"); endswitch endif end @@ -93,7 +93,7 @@ if (!isempty(seed)) if (!isscalar(seed) || !isreal(seed) || (seed < 0) || - ((seed-floor(seed)) != 0)) + ((seed-floor(seed)) != 0)) error ("awgn: random seed must be integer"); endif endif @@ -128,20 +128,20 @@ else np = p - snr; endif - + y = x + wgn (m, n, np, 1, seed, type, out); endfunction -%!shared x, y, noisy -%! x = [0:0.01:2*pi]; y = sin (x); -%! noisy = awgn (y, 20, "dB", "measured"); + %!shared x, y, noisy + %! x = [0:0.01:2*pi]; y = sin (x); + %! noisy = awgn (y, 20, "dB", "measured"); ## Test of noisy is pretty arbitrary, but should pickup most errors -%!error awgn (); -%!error awgn (1); -%!error awgn (1,1,1,1,1); -%!assert (isreal(noisy)); -%!assert (iscomplex(awgn(y+1i,20,"dB","measured"))); -%!assert (size(y) == size(noisy)) -%!assert (abs(10*log10(mean(y.^2)/mean((y-noisy).^ 2)) - 20) < 1); + %!error awgn (); + %!error awgn (1); + %!error awgn (1,1,1,1,1); + %!assert (isreal(noisy)); + %!assert (iscomplex(awgn(y+1i,20,"dB","measured"))); + %!assert (size(y) == size(noisy)) + %!assert (abs(10*log10(mean(y.^2)/mean((y-noisy).^ 2)) - 20) < 1); Modified: trunk/octave-forge/main/comm/inst/bchpoly.m =================================================================== --- trunk/octave-forge/main/comm/inst/bchpoly.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/bchpoly.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -112,19 +112,19 @@ if (ischar(arg)) probe = 1; if (nargout > 1) - error ("bchpoly: only one output argument allowed when probing valid codes"); + error ("bchpoly: only one output argument allowed when probing valid codes"); endif else if (prim != 0) - error ("bchpoly: primitive polynomial already defined"); + error ("bchpoly: primitive polynomial already defined"); endif prim = arg; if (!isscalar(prim)) - prim = bi2de(prim); + prim = bi2de(prim); endif if ((floor(prim) != prim) || (prim < 2^m) || (prim > 2^(m+1)) || ... - !isprimitive(prim)) - error ("bchpoly: prim must be a primitive polynomial of GF(2^m)"); + !isprimitive(prim)) + error ("bchpoly: prim must be a primitive polynomial of GF(2^m)"); endif endif end @@ -143,29 +143,29 @@ f = []; for t=1:floor(n(ni)/2) - for i=1:nc - if (fc(i) != 1) - cl = log(c{i}); - for j=2*(t-1)+1:2*t - if (find(cl == j)) - f = [f, c{i}.x]; - fc(i) = 1; - break; + for i=1:nc + if (fc(i) != 1) + cl = log(c{i}); + for j=2*(t-1)+1:2*t + if (find(cl == j)) + f = [f, c{i}.x]; + fc(i) = 1; + break; + endif + end + endif + end + + k = nn(ni) - length(f); + if (k < 2) + break; endif - end - endif - end - k = nn(ni) - length(f); - if (k < 2) - break; - endif - - if (!isempty(p) && (k == p(size(p,1),2))) - p(size(p,1),:) = [nn(ni), k, t]; - else - p = [p; [nn(ni), k, t]]; - endif + if (!isempty(p) && (k == p(size(p,1),2))) + p(size(p,1),:) = [nn(ni), k, t]; + else + p = [p; [nn(ni), k, t]]; + endif end end else @@ -181,22 +181,22 @@ t++; f0 = f1; for i=1:nc - if (fc(i) != 1) - cl = log(c{i}); - for j=2*(t-1)+1:2*t - if (find(cl == j)) - f1 = [f1, c{i}.x]; - fc(i) = 1; - ptmp = gf([c{i}(1), 1], m, prim); - for l=2:length(c{i}) - ptmp = conv(ptmp, [c{i}(l), 1]); - end - f = [f; [ptmp.x, zeros(1,m-length(ptmp)+1)]]; - fl = fl + length(ptmp); - break; - endif - end - endif + if (fc(i) != 1) + cl = log(c{i}); + for j=2*(t-1)+1:2*t + if (find(cl == j)) + f1 = [f1, c{i}.x]; + fc(i) = 1; + ptmp = gf([c{i}(1), 1], m, prim); + for l=2:length(c{i}) + ptmp = conv(ptmp, [c{i}(l), 1]); + end + f = [f; [ptmp.x, zeros(1,m-length(ptmp)+1)]]; + fl = fl + length(ptmp); + break; + endif + end + endif end until (length(f1) > nn - k) t--; @@ -216,17 +216,17 @@ p = gf([f0(1), 1], m, prim); for i=2:length(f0) - p = conv(p, [f0(i), 1]); + p = conv(p, [f0(i), 1]); end p = p.x; if (nargout > 3) - if (n > 64) - warning("bchpoly: can not create parity matrix\n"); - par = []; - else - par = cyclgen(n,p); - endif + if (n > 64) + warning("bchpoly: can not create parity matrix\n"); + par = []; + else + par = cyclgen(n,p); + endif endif endif endif Modified: trunk/octave-forge/main/comm/inst/bi2de.m =================================================================== --- trunk/octave-forge/main/comm/inst/bi2de.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/bi2de.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -75,22 +75,22 @@ endfunction -%!shared x -%! x = randi ([0 1], 100, 16); -%!assert (bi2de (0), 0) -%!assert (bi2de (1), 1) -%!assert (bi2de (ones (1, 8)), 255) -%!assert (bi2de ([7 7 7 7], 8), 4095) -%!assert (size (bi2de (x)), [100 1]) -%!assert (bi2de (x, "right-msb"), bi2de (x)) -%!assert (bi2de (x, "left-msb"), bi2de (fliplr (x))) + %!shared x + %! x = randi ([0 1], 100, 16); + %!assert (bi2de (0), 0) + %!assert (bi2de (1), 1) + %!assert (bi2de (ones (1, 8)), 255) + %!assert (bi2de ([7 7 7 7], 8), 4095) + %!assert (size (bi2de (x)), [100 1]) + %!assert (bi2de (x, "right-msb"), bi2de (x)) + %!assert (bi2de (x, "left-msb"), bi2de (fliplr (x))) %% Test input validation -%!error bi2de () -%!error bi2de (1, 2, 3, 4) -%!error bi2de (1, 2, 3) -%!error bi2de (1, 2, "invalid") -%!error bi2de (0.1) -%!error bi2de (-1) -%!error bi2de (2) -%!error bi2de (7, 6) + %!error bi2de () + %!error bi2de (1, 2, 3, 4) + %!error bi2de (1, 2, 3) + %!error bi2de (1, 2, "invalid") + %!error bi2de (0.1) + %!error bi2de (-1) + %!error bi2de (2) + %!error bi2de (7, 6) Modified: trunk/octave-forge/main/comm/inst/biterr.m =================================================================== --- trunk/octave-forge/main/comm/inst/biterr.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/biterr.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -116,24 +116,24 @@ arg = varargin{i}; if (ischar(arg)) if (strcmp(arg,"row-wise")) - if (strcmp(type,"column")) - error ("biterr: row-wise comparison not possible with column inputs"); - endif - flag = "row"; + if (strcmp(type,"column")) + error ("biterr: row-wise comparison not possible with column inputs"); + endif + flag = "row"; elseif (strcmp(arg,"column-wise")) - if (strcmp(type,"row")) - error ("biterr: column-wise comparison not possible with row inputs"); - endif - flag = "column"; + if (strcmp(type,"row")) + error ("biterr: column-wise comparison not possible with row inputs"); + endif + flag = "column"; elseif (strcmp(arg,"overall")) - flag = "overall"; + flag = "overall"; else - error ("biterr: unrecognized string argument"); + error ("biterr: unrecognized string argument"); endif else k = arg; if (k < m) - error ("biterr: the symbol size is too small for largest element"); + error ("biterr: the symbol size is too small for largest element"); endif endif end @@ -148,16 +148,16 @@ switch (flag) case 'row', if (strcmp(type,"matrix") && (ac == 1)) - num = ind; + num = ind; else num = sum(ind')'; endif rate = num / k / max(ac,bc); case 'column', if (strcmp(type,"matrix") && (ar == 1)) - num = ind; + num = ind; else - num = sum(ind); + num = sum(ind); endif rate = num / k / max(ar,br); case 'overall', Modified: trunk/octave-forge/main/comm/inst/compand.m =================================================================== --- trunk/octave-forge/main/comm/inst/compand.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/compand.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -113,4 +113,4 @@ endif endfunction - + Modified: trunk/octave-forge/main/comm/inst/convenc.m =================================================================== --- trunk/octave-forge/main/comm/inst/convenc.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/convenc.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -56,10 +56,10 @@ print_usage; endif - # Use conv2 to do repeated 1d convolutions of m with each row of G. - # rem is used to transform the standard convolution result to one - # which uses modulo-2 addition. Only cols with index a mult. of k - # are in the actual enc. output + # Use conv2 to do repeated 1d convolutions of m with each row of G. + # rem is used to transform the standard convolution result to one + # which uses modulo-2 addition. Only cols with index a mult. of k + # are in the actual enc. output x = rem(conv2(1, m(:)', G),2)(:,!rem(1:numel(m),k))(:)'; endfunction Modified: trunk/octave-forge/main/comm/inst/de2bi.m =================================================================== --- trunk/octave-forge/main/comm/inst/de2bi.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/de2bi.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -87,21 +87,21 @@ endfunction -%!shared x -%! x = randi ([0 2^16-1], 100, 1); -%!assert (de2bi (0), 0) -%!assert (de2bi (1), 1) -%!assert (de2bi (255), ones (1, 8)) -%!assert (de2bi (255, [], 256), 255) -%!assert (de2bi (1023, 8, 8), [7 7 7 1 0 0 0 0]) -%!assert (size (de2bi (x, 16)), [100 16]) -%!assert (de2bi (x, 16, "right-msb"), de2bi (x, 16)) -%!assert (de2bi (x, 16, "left-msb"), fliplr (de2bi (x, 16))) + %!shared x + %! x = randi ([0 2^16-1], 100, 1); + %!assert (de2bi (0), 0) + %!assert (de2bi (1), 1) + %!assert (de2bi (255), ones (1, 8)) + %!assert (de2bi (255, [], 256), 255) + %!assert (de2bi (1023, 8, 8), [7 7 7 1 0 0 0 0]) + %!assert (size (de2bi (x, 16)), [100 16]) + %!assert (de2bi (x, 16, "right-msb"), de2bi (x, 16)) + %!assert (de2bi (x, 16, "left-msb"), fliplr (de2bi (x, 16))) %% Test input validation -%!error de2bi () -%!error de2bi (1, 2, 3, 4, 5) -%!error de2bi (1, 2, 3, 4) -%!error de2bi (1, 2, 3, "invalid") -%!error de2bi (0.1) -%!error de2bi (-1) + %!error de2bi () + %!error de2bi (1, 2, 3, 4, 5) + %!error de2bi (1, 2, 3, 4) + %!error de2bi (1, 2, 3, "invalid") + %!error de2bi (0.1) + %!error de2bi (-1) Modified: trunk/octave-forge/main/comm/inst/decode.m =================================================================== --- trunk/octave-forge/main/comm/inst/decode.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/decode.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -123,31 +123,31 @@ else ## Why the hell did matlab decide on such an ugly way of passing 2 args! if (strcmp(typ,"linear") || strcmp(typ,"linear/binary")) - coding = "linear"; - msgtyp = "binary"; + coding = "linear"; + msgtyp = "binary"; elseif (strcmp(typ,"linear/decimal")) - coding = "linear"; - msgtyp = "decimal"; + coding = "linear"; + msgtyp = "decimal"; elseif (strcmp(typ,"cyclic") || strcmp(typ,"cyclic/binary")) - coding = "cyclic"; - msgtyp = "binary"; + coding = "cyclic"; + msgtyp = "binary"; elseif (strcmp(typ,"cyclic/decimal")) - coding = "cyclic"; - msgtyp = "decimal"; + coding = "cyclic"; + msgtyp = "decimal"; elseif (strcmp(typ,"bch") || strcmp(typ,"bch/binary")) - coding = "bch"; - msgtyp = "binary"; + coding = "bch"; + msgtyp = "binary"; elseif (strcmp(typ,"bch/decimal")) - coding = "bch"; - msgtyp = "decimal"; + coding = "bch"; + msgtyp = "decimal"; elseif (strcmp(typ,"hamming") || strcmp(typ,"hamming/binary")) - coding = "hamming"; - msgtyp = "binary"; + coding = "hamming"; + msgtyp = "binary"; elseif (strcmp(typ,"hamming/decimal")) - coding = "hamming"; - msgtyp = "decimal"; + coding = "hamming"; + msgtyp = "decimal"; else - error ("decode: unrecognized coding and/or message type"); + error ("decode: unrecognized coding and/or message type"); endif endif else @@ -201,50 +201,50 @@ else if (strcmp(coding,"linear")) if (nargin > 4) - gen = opt1; - if ((size(gen,1) != k) || (size(gen,2) != n)) - error ("decode: generator matrix is in incorrect form"); - endif - par = gen2par(gen); - if (nargin > 5) - st = opt2; - else - st = syndtable(par); - endif + gen = opt1; + if ((size(gen,1) != k) || (size(gen,2) != n)) + error ("decode: generator matrix is in incorrect form"); + endif + par = gen2par(gen); + if (nargin > 5) + st = opt2; + else + st = syndtable(par); + endif else - error ("decode: linear coding must supply the generator matrix"); + error ("decode: linear coding must supply the generator matrix"); endif elseif (strcmp(coding,"cyclic")) if (nargin > 4) - [par, gen] = cyclgen(n,opt1); + [par, gen] = cyclgen(n,opt1); else - [par, gen] = cyclgen(n,cyclpoly(n,k)); + [par, gen] = cyclgen(n,cyclpoly(n,k)); endif if (nargin > 5) - ## XXX FIXME XXX Should we check that the generator polynomial is - ## consistent with the syndrome table. Where is the acceleration in - ## this case??? - st = opt2; + ## XXX FIXME XXX Should we check that the generator polynomial is + ## consistent with the syndrome table. Where is the acceleration in + ## this case??? + st = opt2; else - st = syndtable(par); + st = syndtable(par); endif else m = log2(n + 1); if ((m != floor(m)) || (m < 3) || (m > 16)) - error ("decode: codeword length must be of the form '2^m-1' with integer m"); + error ("decode: codeword length must be of the form '2^m-1' with integer m"); endif if (k != (n-m)) - error ("decode: illegal message length for hamming code"); + error ("decode: illegal message length for hamming code"); endif if (nargin > 4) - [par, gen] = hammgen(m, opt1); + [par, gen] = hammgen(m, opt1); else - [par, gen] = hammgen(m); + [par, gen] = hammgen(m); endif if (nargin > 5) - error ("decode: illegal call for hamming coding"); + error ("decode: illegal call for hamming coding"); else - st = syndtable(par); + st = syndtable(par); endif endif Modified: trunk/octave-forge/main/comm/inst/demodmap.m =================================================================== --- trunk/octave-forge/main/comm/inst/demodmap.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/demodmap.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -98,13 +98,13 @@ if (nargin > 3) method = varargin{1}; if (!ischar(method) || (!strcmp(method,"ask") && ... - isempty(findstr(method,"msk")) && isempty(findstr(method,"fsk")) && ... - isempty(findstr(method,"samp")) && !strcmp(method,"psk") && ... - !strcmp(method,"qask") && !strcmp(method,"qam") && ... - !strcmp(method,"qsk") && !strcmp(method,"qask/cir") && ... - !strcmp(method,"qam/cir") && !strcmp(method,"qsk/cir") && ... - !strcmp(method,"qask/arb") && !strcmp(method,"qam/arb") && ... - !strcmp(method,"qsk/arb"))) + isempty(findstr(method,"msk")) && isempty(findstr(method,"fsk")) && ... + isempty(findstr(method,"samp")) && !strcmp(method,"psk") && ... + !strcmp(method,"qask") && !strcmp(method,"qam") && ... + !strcmp(method,"qsk") && !strcmp(method,"qask/cir") && ... + !strcmp(method,"qam/cir") && !strcmp(method,"qsk/cir") && ... + !strcmp(method,"qask/arb") && !strcmp(method,"qam/arb") && ... + !strcmp(method,"qsk/arb"))) error ("modmap: unknown mapping method"); endif else @@ -142,24 +142,24 @@ if (!isempty(findstr(method,"fsk")) || !isempty(findstr(method,"msk"))) if (findstr(method,"msk")) if (nargin > 4) - error ("demodmap: too many arguments"); + error ("demodmap: too many arguments"); endif M = 2; tone = fd/2; else if (nargin > 5) - tone = varargin{3}; + tone = varargin{3}; else - tone = fd; + tone = fd; endif if (nargin > 6) - error ("demodmap: too many arguments"); + error ("demodmap: too many arguments"); endif endif if (findstr(method,"/max")) if (size(y,2) != M) - error ("demodmap: when using correlation must have M columns"); + error ("demodmap: when using correlation must have M columns"); endif ## We have an M-column maximum from which with pick index of the maximum ## value in each row as the decoded value @@ -177,37 +177,37 @@ elseif (strcmp(method,"psk")) c = apkconst(M,[],[]); elseif (!isempty(findstr(method,"qask")) || ... - !isempty(findstr(method,"qsk")) || ... - !isempty(findstr(method,"qam"))) + !isempty(findstr(method,"qsk")) || ... + !isempty(findstr(method,"qam"))) if (findstr(method,"/cir")) nsig = 2; amp = []; phs = []; if (nargin > 4) - nsig = varargin{2}; - if (!isvector(nsig)) - error ("modmap: invalid number of constellation point in qask/cir"); - endif + nsig = varargin{2}; + if (!isvector(nsig)) + error ("modmap: invalid number of constellation point in qask/cir"); + endif endif if (nargin > 5) - amp = varargin{3}; + amp = varargin{3}; endif if (nargin > 6) - phs = varargin{4}; + phs = varargin{4}; endif c = apkconst(nsig,amp,phs); M = length(c); elseif (findstr(method,"/arb")) if (nargin == 4) - c = qaskenco(2); + c = qaskenco(2); elseif (nargin == 5) - c = varargin{2}; + c = varargin{2}; elseif (nargin == 6) - inphase = varargin{2}; - quadr = varargin{3}; - c = inphase + 1i*quadr; + inphase = varargin{2}; + quadr = varargin{3}; + c = inphase + 1i*quadr; elseif (nargin > 6) - error ("demodmap: too many arguments"); + error ("demodmap: too many arguments"); endif M = length(c); else @@ -229,8 +229,8 @@ z = (b - 1).'; else for i=1:size(y,1) - [a, b] = min(abs(repmat(y(i,:),M,1) - repmat(c,1,size(y,2)))); - z(i,:) = b - 1; + [a, b] = min(abs(repmat(y(i,:),M,1) - repmat(c,1,size(y,2)))); + z(i,:) = b - 1; end endif endif Modified: trunk/octave-forge/main/comm/inst/egolaydec.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolaydec.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/egolaydec.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -49,78 +49,78 @@ function [C,dec_error]=egolaydec(R) -if ( nargin < 1 ) + if ( nargin < 1 ) error('usage: C=egolaydec(R)'); -elseif ( columns(R) ~= 24 ) + elseif ( columns(R) ~= 24 ) error('extended golay code is (24,12), use rx codeword of 24 bit column size'); -end + end -I=eye(12); -%P is 12x12 matrix -P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; + I=eye(12); + %P is 12x12 matrix + P=[1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; -H=[I; P]; %partiy check matrix transpose. + H=[I; P]; %partiy check matrix transpose. -dec_error=[]; -C=zeros(size(R)); + dec_error=[]; + C=zeros(size(R)); -for rspn=1:rows(R) - RR=R(rspn,:); - S=mod(RR*H,2); -wt=sum(S); -done=0; -if (wt <= 3) - E=[S, zeros(1,12)]; - done=1; -else - SP = mod(repmat(S,[12, 1])+P,2); - idx = find( sum(SP,2) <= 2 ); - if ( idx ) + for rspn=1:rows(R) + RR=R(rspn,:); + S=mod(RR*H,2); + wt=sum(S); + done=0; + if (wt <= 3) + E=[S, zeros(1,12)]; + done=1; + else + SP = mod(repmat(S,[12, 1])+P,2); + idx = find( sum(SP,2) <= 2 ); + if ( idx ) idx=idx(1); %pick first of matches. Ui=zeros(1,12); Ui(idx)=1; E=[SP(idx,:),Ui]; done=1; + end end -end -if ( ~done ) - X=mod(S*P,2); - wt=sum(X); - if (wt==2 || wt==3) + if ( ~done ) + X=mod(S*P,2); + wt=sum(X); + if (wt==2 || wt==3) E=[zeros(1,12), X]; done=1; - else + else SP = mod(repmat(X,[12, 1])+P,2); idx = find( sum(SP,2) == 2 ); if ( idx ) - idx=idx(1); - Ui=zeros(1,12); Ui(idx)=1; - E=[Ui,SP(idx,:)]; - done=1; + idx=idx(1); + Ui=zeros(1,12); Ui(idx)=1; + E=[Ui,SP(idx,:)]; + done=1; end + end end -end -dec_error=[dec_error; 1-done]; -C(rspn,:)=mod(E+RR,2); -end + dec_error=[dec_error; 1-done]; + C(rspn,:)=mod(E+RR,2); + end -return; + return; end -%! -%!assert(egolaydec([1 1 1 zeros(1,21)]),zeros(1,24)) -%!assert(egolaydec([1 0 1 zeros(1,20) 1]),zeros(1,24)) -%! + %! + %!assert(egolaydec([1 1 1 zeros(1,21)]),zeros(1,24)) + %!assert(egolaydec([1 0 1 zeros(1,20) 1]),zeros(1,24)) + %! Modified: trunk/octave-forge/main/comm/inst/egolayenc.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolayenc.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/egolayenc.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -39,32 +39,32 @@ ## @seealso{egolaygen,egolaydec} function C=egolayenc(M) -if ( nargin < 1 ) + if ( nargin < 1 ) error('usage: C=egolayenc(M)'); -elseif ( columns(M) ~= 12 ) + elseif ( columns(M) ~= 12 ) error('extended golay code is (24,12), use message of column size 12'); -end + end -I=eye(12); -P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; -G=[P I]; %generator. + I=eye(12); + P=[1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; + G=[P I]; %generator. -##for rowi=1:rows(M) -## C(rowi,:)=mod(M(rowi,:)*G,2); %code. -##end + ##for rowi=1:rows(M) + ## C(rowi,:)=mod(M(rowi,:)*G,2); %code. + ##end -C=mod(M*repmat(G,[1,rows(M)]),2); -C=C(:,1:24); + C=mod(M*repmat(G,[1,rows(M)]),2); + C=C(:,1:24); end Modified: trunk/octave-forge/main/comm/inst/egolaygen.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolaygen.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/egolaygen.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -24,18 +24,18 @@ ## @seealso{egolaydec,egolayenc} function [G,P]=egolaygen() -I=eye(12); -P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; -G=[P I]; %generator. + I=eye(12); + P=[1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; + G=[P I]; %generator. end Modified: trunk/octave-forge/main/comm/inst/encode.m =================================================================== --- trunk/octave-forge/main/comm/inst/encode.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/encode.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -106,31 +106,31 @@ else ## Why the hell did matlab decide on such an ugly way of passing 2 args! if (strcmp(typ,"linear") || strcmp(typ,"linear/binary")) - coding = "linear"; - msgtyp = "binary"; + coding = "linear"; + msgtyp = "binary"; elseif (strcmp(typ,"linear/decimal")) - coding = "linear"; - msgtyp = "decimal"; + coding = "linear"; + msgtyp = "decimal"; elseif (strcmp(typ,"cyclic") || strcmp(typ,"cyclic/binary")) - coding = "cyclic"; - msgtyp = "binary"; + coding = "cyclic"; + msgtyp = "binary"; elseif (strcmp(typ,"cyclic/decimal")) - coding = "cyclic"; - msgtyp = "decimal"; + coding = "cyclic"; + msgtyp = "decimal"; elseif (strcmp(typ,"bch") || strcmp(typ,"bch/binary")) - coding = "bch"; - msgtyp = "binary"; + coding = "bch"; + msgtyp = "binary"; elseif (strcmp(typ,"bch/decimal")) - coding = "bch"; - msgtyp = "decimal"; + coding = "bch"; + msgtyp = "decimal"; elseif (strcmp(typ,"hamming") || strcmp(typ,"hamming/binary")) - coding = "hamming"; - msgtyp = "binary"; + coding = "hamming"; + msgtyp = "binary"; elseif (strcmp(typ,"hamming/decimal")) - coding = "hamming"; - msgtyp = "decimal"; + coding = "hamming"; + msgtyp = "decimal"; else - error ("encode: unrecognized coding and/or message type"); + error ("encode: unrecognized coding and/or message type"); endif endif else @@ -173,31 +173,31 @@ else if (strcmp(coding,"linear")) if (nargin > 4) - gen = opt; - if ((size(gen,1) != k) || (size(gen,2) != n)) - error ("encode: generator matrix is in incorrect form"); - endif + gen = opt; + if ((size(gen,1) != k) || (size(gen,2) != n)) + error ("encode: generator matrix is in incorrect form"); + endif else - error ("encode: linear coding must supply the generator matrix"); + error ("encode: linear coding must supply the generator matrix"); endif elseif (strcmp(coding,"cyclic")) if (nargin > 4) - [par, gen] = cyclgen(n,opt); + [par, gen] = cyclgen(n,opt); else - [par, gen] = cyclgen(n,cyclpoly(n,k)); + [par, gen] = cyclgen(n,cyclpoly(n,k)); endif else m = log2(n + 1); if ((m != floor(m)) || (m < 3) || (m > 16)) - error ("encode: codeword length must be of the form '2^m-1' with integer m"); + error ("encode: codeword length must be of the form '2^m-1' with integer m"); endif if (k != (n-m)) - error ("encode: illegal message length for hamming code"); + error ("encode: illegal message length for hamming code"); endif if (nargin > 4) - [par, gen] = hammgen(m, opt); + [par, gen] = hammgen(m, opt); else - [par, gen] = hammgen(m); + [par, gen] = hammgen(m); endif endif code = mod(msg * gen, 2); Modified: trunk/octave-forge/main/comm/inst/eyediagram.m =================================================================== --- trunk/octave-forge/main/comm/inst/eyediagram.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/eyediagram.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -106,7 +106,7 @@ if (isempty(_off)) off = 0; elseif (!isscalar(_off) || !isreal(_off) || (floor(_off) != _off) || ... - (_off < 0) || (_off > (n-1))) + (_off < 0) || (_off > (n-1))) error ("eyediagram: offset must be an integer between 0 and n"); else off = _off; Modified: trunk/octave-forge/main/comm/inst/fibodeco.m =================================================================== --- trunk/octave-forge/main/comm/inst/fibodeco.m 2012-05-11 18:08:42 UTC (rev 10412) +++ trunk/octave-forge/main/comm/inst/fibodeco.m 2012-05-11 18:10:27 UTC (rev 10413) @@ -36,44 +36,44 @@ ## @seealso{fiboenco} function num=fibodeco(code) - % - % generate fibonacci series table. - % - % f(1)=1; - % f(2)=1; - % - % while ((f(end-1)+f(end)) < 256) - % val=(f(end-1)+f(end)); - % f=[f val]; - % end - % f=f(2:end); - % - %all numbers terminate with 1 except 0 itself. - % - % - %f= [75025 46368 28657 17711 10946 6765 4181 2584 \ - % 1597 987 610 377 233 144 89 55 \ - % 34 21 13 8 5 3 2 1]; - % - %f= [ 233 144 89 55 34 21 13 8 5 3 2 1]; + ## + ## generate fibonacci series table. + ## + ## f(1)=1; + ## f(2)=1; + ## + ## while ((f(end-1)+f(end)) < 256) + ## val=(f(end-1)+f(end)); + ## f=[f val]; + ## end + ## f=f(2:end); + ## + ##all numbers terminate with 1 except 0 itself. + ## + ## + ##f= [75025 46368 28657 17711 10946 6765 4181 2584 \ + ## 1597 987 610 377 233 144 89 55 \ + ## 34 21 13 8 5 3 2 1]; + ## + ##f= [ 233 144 89 55 34 21 13 8 5 3 2 1]; - f= [ 1 2 3 5 8 13 21 34 55 89 144 233]; - L_C=length(code); + f= [ 1 2 3 5 8 13 21 34 55 89 144 233]; + L_C=length(code); - if (nargin < 1) - error("Usage:fibodec(cell-array vectors), where each vector is +ve sequence of numbers ... - either 1 or 0"); - end + if (nargin < 1) + error("Usage:fibodec(cell-array vectors), where each vector is +ve sequence of numbers ... + either 1 or 0"); + end - for j=1:L_C - word=code{j}; - %discard the terminating 1. - word=word(1:end-1); - L=length(word); - num(j)=sum(word.*f(1:L)); - end - - return + for j=1:L_C + word=code{j}; + ##discard the terminating 1. + word=word(1:end-1); + L=length(word); + num(j)=sum(word.*f(1:L)); + end + + return end %! %! assert(fibodeco({[1 1],[0 1 1],[0 0 1 1],[1 0 1 1]}),[1:4]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[10892] trunk/octave-forge/main/comm/inst From: - 2012-08-21 00:59:55 ```Revision: 10892 http://octave.svn.sourceforge.net/octave/?rev=10892&view=rev Author: carandraug Date: 2012-08-21 00:59:49 +0000 (Tue, 21 Aug 2012) Log Message: ----------- egolayenc/egolaydec/egolaygen: follow some Octave coding standards Modified Paths: -------------- trunk/octave-forge/main/comm/inst/egolaydec.m trunk/octave-forge/main/comm/inst/egolayenc.m trunk/octave-forge/main/comm/inst/egolaygen.m Modified: trunk/octave-forge/main/comm/inst/egolaydec.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolaydec.m 2012-08-21 00:32:36 UTC (rev 10891) +++ trunk/octave-forge/main/comm/inst/egolaydec.m 2012-08-21 00:59:49 UTC (rev 10892) @@ -14,23 +14,24 @@ ## this program; if not, see ;. ## -*- texinfo -*- -## @deftypefn {Function File} {} egolaydec (@var{R}) +## @deftypefn {Function File} {[@var{C}, @var{err}] =} egolaydec (@var{R}) +## Decode Extended Golay code. ## ## Given @var{R}, the received Extended Golay code, this function tries to -## decode @var{R} using the Extended Golay code parity check matrix. -## Extended Golay code (24,12) which can correct upto 3 errors. +## decode it using the Extended Golay code parity check matrix. +## Extended Golay code (24,12) which can correct up to 3 errors. ## ## The received code @var{R}, needs to be of length Nx24, for encoding. We can -## decode several codes at once, if they are stacked as a matrix of 24columns, +## decode several codes at once, if they are stacked as a matrix of 24 columns, ## each code in a separate row. ## -## The generator G used in here is same as obtained from the -## function egolaygen. +## The generator used in here is same as obtained from the function +## @code{egolaygen}. ## -## The function returns the error-corrected code word from the received -## word. If decoding failed, the second return value is 1, otherwise it is 0. +## The function returns @var{C}, the error-corrected code word from the received +## word. If decoding failed, @var{err} value is 1, otherwise it is 0. ## -## Extended Golay code (24,12) which can correct upto 3 +## Extended Golay code (24,12) which can correct up to 3 ## errors. Decoding algorithm follows from Lin & Costello. ## ## Ref: Lin & Costello, pg 128, Ch4, 'Error Control Coding', 2nd ed, Pearson. @@ -44,80 +45,82 @@ ## @end group ## @end example ## +## @seealso{egolaygen,egolayenc} ## @end deftypefn -## @seealso{egolaygen,egolayenc} -function [C,dec_error]=egolaydec(R) +function [C, dec_error] = egolaydec (R) - if ( nargin < 1 ) - error('usage: C=egolaydec(R)'); - elseif ( columns(R) ~= 24 ) - error('extended golay code is (24,12), use rx codeword of 24 bit column size'); - end + if (nargin != 1) + print_usage; + elseif (columns (R) != 24) + error ("extended golay code is (24,12), use rx codeword of 24 bit column size"); + endif - I=eye(12); + I = eye (12); %P is 12x12 matrix - P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; + P = [1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; - H=[I; P]; %partiy check matrix transpose. + H = [I; P]; %partiy check matrix transpose. - dec_error=[]; - C=zeros(size(R)); + dec_error = []; + C = zeros (size (R)); - for rspn=1:rows(R) - RR=R(rspn,:); - S=mod(RR*H,2); - wt=sum(S); - done=0; - E=[S, zeros(1,12)]; + for rspn = 1:rows (R) + RR = R(rspn,:); + S = mod (RR*H, 2); + wt = sum (S); + done = 0; + E = [S, zeros(1, 12)]; if (wt <= 3) - E=[S, zeros(1,12)]; - done=1; + E = [S, zeros(1, 12)]; + done = 1; else - SP = mod(repmat(S,[12, 1])+P,2); - idx = find( sum(SP,2) <= 2 ); - if ( idx ) - idx=idx(1); %pick first of matches. - Ui=zeros(1,12); Ui(idx)=1; - E=[SP(idx,:),Ui]; - done=1; - end - end + SP = mod (repmat (S, [12, 1]) + P, 2); + idx = find (sum (SP, 2) <= 2); + if (idx) + idx = idx(1); %pick first of matches. + Ui = zeros (1, 12); + Ui(idx) = 1; + E = [SP(idx, :), Ui]; + done = 1; + endif + endif - if ( ~done ) - X=mod(S*P,2); - wt=sum(X); + if (!done) + X = mod (S*P, 2); + wt = sum (X); if (wt==2 || wt==3) - E=[zeros(1,12), X]; - done=1; + E = [zeros(1, 12), X]; + done = 1; else - SP = mod(repmat(X,[12, 1])+P,2); - idx = find( sum(SP,2) == 2 ); - if ( idx ) - idx=idx(1); - Ui=zeros(1,12); Ui(idx)=1; - E=[Ui,SP(idx,:)]; - done=1; - end - end - end + SP = mod (repmat(X, [12, 1]) + P, 2); + idx = find (sum(SP, 2) == 2); + if (idx) + idx = idx(1); + Ui = zeros (1, 12); + Ui(idx) = 1; + E = [Ui, SP(idx, :)]; + done = 1; + endif + endif + endif - dec_error=[dec_error; 1-done]; - C(rspn,:)=mod(E+RR,2); - end + dec_error = [dec_error; 1-done]; + C(rspn, :) = mod (E+RR, 2); + endfor - return; -end +endfunction + %!assert(egolaydec([1 1 1 zeros(1,21)]),zeros(1,24)) %!assert(egolaydec([1 0 1 zeros(1,20) 1]),zeros(1,24)) Modified: trunk/octave-forge/main/comm/inst/egolayenc.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolayenc.m 2012-08-21 00:32:36 UTC (rev 10891) +++ trunk/octave-forge/main/comm/inst/egolayenc.m 2012-08-21 00:59:49 UTC (rev 10892) @@ -14,57 +14,51 @@ ## this program; if not, see ;. ## -*- texinfo -*- -## @deftypefn {Function File} {} egolayenc (@var{M}) +## @deftypefn {Function File} {@var{C} =} egolayenc (@var{M}) +## Encode with Extended Golay code. ## -## -## Given @var{M}, encode M using the Extended Golay code. -## ## The message @var{M}, needs to be of size Nx12, for encoding. ## We can encode several messages, into codes at once, if they ## are stacked in the order suggested. ## -## The generator G used in here is same as obtained from the -## function egolaygen. Extended Golay code (24,12) which can correct +## The generator used in here is same as obtained from the +## function @code{egolaygen}. Extended Golay code (24,12) which can correct ## upto 3 errors. ## ## @example ## @group ## M=(rand(10,12)>0.5); ## C=egolayenc(M) -## ## @end group ## @end example ## -## @end deftypefn ## @seealso{egolaygen,egolaydec} +## @end deftypefn -function C=egolayenc(M) - if ( nargin < 1 ) - error('usage: C=egolayenc(M)'); - elseif ( columns(M) ~= 12 ) - error('extended golay code is (24,12), use message of column size 12'); - end +function C = egolayenc (M) - I=eye(12); - P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; - G=[P I]; %generator. + if (nargin < 1) + print_usage; + elseif (columns (M) != 12) + error("extended golay code is (24,12), use message of column size 12"); + endif - ##for rowi=1:rows(M) - ## C(rowi,:)=mod(M(rowi,:)*G,2); %code. - ##end + I = eye (12); + P = [1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; + G = [P I]; %generator. - C=mod(M*repmat(G,[1,rows(M)]),2); - C=C(:,1:24); + C = mod (M * repmat (G, [1, rows(M)]), 2); + C = C(:, 1:24); -end +endfunction Modified: trunk/octave-forge/main/comm/inst/egolaygen.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolaygen.m 2012-08-21 00:32:36 UTC (rev 10891) +++ trunk/octave-forge/main/comm/inst/egolaygen.m 2012-08-21 00:59:49 UTC (rev 10892) @@ -14,28 +14,34 @@ ## this program; if not, see ;. ## -*- texinfo -*- -## @deftypefn {Function File} {} egolaygen () +## @deftypefn {Function File} {[@var{G}, @var{P}]} = egolaygen () +## Extended Golay code generator matrix. ## -## Returns the Extended Golay code (24,12) generator matrix, -## which can correct upto 3 errors. The second argument is the partiy +## Returns @var{G}, the Extended Golay code (24,12) generator matrix, +## which can correct up to 3 errors. @var{P} is the partiy ## check matrix, for this code. ## +## @seealso{egolaydec,egolayenc} ## @end deftypefn -## @seealso{egolaydec,egolayenc} -function [G,P]=egolaygen() - I=eye(12); - P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; - G=[P I]; %generator. -end +function [G, P] = egolaygen () + + if (nargin != 0) + print_usage; + endif + + I = eye (12); + P = [1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; + G = [P I]; %generator. +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[10893] trunk/octave-forge/main/comm/inst From: - 2012-08-21 01:12:27 ```Revision: 10893 http://octave.svn.sourceforge.net/octave/?rev=10893&view=rev Author: carandraug Date: 2012-08-21 01:12:21 +0000 (Tue, 21 Aug 2012) Log Message: ----------- egolaydec/egolayenc: use egolaygen and avoid repeating code Modified Paths: -------------- trunk/octave-forge/main/comm/inst/egolaydec.m trunk/octave-forge/main/comm/inst/egolayenc.m Modified: trunk/octave-forge/main/comm/inst/egolaydec.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolaydec.m 2012-08-21 00:59:49 UTC (rev 10892) +++ trunk/octave-forge/main/comm/inst/egolaydec.m 2012-08-21 01:12:21 UTC (rev 10893) @@ -56,25 +56,10 @@ error ("extended golay code is (24,12), use rx codeword of 24 bit column size"); endif - I = eye (12); - %P is 12x12 matrix - P = [1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; - - H = [I; P]; %partiy check matrix transpose. - dec_error = []; - C = zeros (size (R)); + [~, P] = egolaygen (); + H = [eye(12); P]; # parity check matrix transpose + C = zeros (size (R)); for rspn = 1:rows (R) RR = R(rspn,:); Modified: trunk/octave-forge/main/comm/inst/egolayenc.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolayenc.m 2012-08-21 00:59:49 UTC (rev 10892) +++ trunk/octave-forge/main/comm/inst/egolayenc.m 2012-08-21 01:12:21 UTC (rev 10893) @@ -43,20 +43,7 @@ error("extended golay code is (24,12), use message of column size 12"); endif - I = eye (12); - P = [1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; - G = [P I]; %generator. + G = egolaygen (); # generator C = mod (M * repmat (G, [1, rows(M)]), 2); C = C(:, 1:24); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[9304] trunk/octave-forge/main/comm/inst From: - 2011-12-07 18:08:05 ```Revision: 9304 http://octave.svn.sourceforge.net/octave/?rev=9304&view=rev Author: carandraug Date: 2011-12-07 18:07:57 +0000 (Wed, 07 Dec 2011) Log Message: ----------- huffmandict/huffmandeco/huffmanenco: * almost complete rewrite of huffmandeco by Ferran Mesas to use binary tree instead of a brute-force O(n^3) or O(n^4) * improved help text * more test cases for huffmandeco * better input checking and default setting * updated licenses to GPLv3+ Modified Paths: -------------- trunk/octave-forge/main/comm/inst/huffmandeco.m trunk/octave-forge/main/comm/inst/huffmandict.m trunk/octave-forge/main/comm/inst/huffmanenco.m Modified: trunk/octave-forge/main/comm/inst/huffmandeco.m =================================================================== --- trunk/octave-forge/main/comm/inst/huffmandeco.m 2011-12-07 16:05:56 UTC (rev 9303) +++ trunk/octave-forge/main/comm/inst/huffmandeco.m 2011-12-07 18:07:57 UTC (rev 9304) @@ -1,8 +1,9 @@ ## Copyright (C) 2006 Muthiah Annamalai +## Copyright (C) 2011 Ferran Mesas Garcia ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or +## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, @@ -12,130 +13,90 @@ ## ## You should have received a copy of the GNU General Public License ## along with this program; If not, see ;. -## ## -*- texinfo -*- -## @deftypefn {Function File} {@var{sig} = } huffmandeco (@var{hcode}, @var{dict}) +## @deftypefn {Function File} {@var{sig} =} huffmandeco (@var{hcode}, @var{dict}) +## Decode signal encoded by @code{huffmanenco}. ## -## Returns the original signal that was Huffman encoded signal using -## @code{huffmanenco}. This function uses a dict built from the +## This function uses a dict built from the ## @code{huffmandict} and uses it to decode a signal list into a huffman ## list. A restriction is that @var{hcode} is expected to be a binary code -## The returned signal set that strictly belongs in the range @code{[1,N]} +## +## The returned @var{sig} set that strictly belongs in the range @code{[1,N]} ## with @code{N = length(@var{dict})}. Also @var{dict} can only be from the ## @code{huffmandict} routine. Whenever decoding fails, those signal values a -## re indicated by @code{-1}, and we successively try to restart decoding -## from the next bit that hasn't failed in decoding, ad-infinitum. An exmaple -## of the use of @code{huffmandeco} is +## re indicated by @code{-1}, and we successively try to restart decoding +## from the next bit that hasn't failed in decoding, ad-infinitum. An example +## of the use of @code{huffmandeco} is: ## ## @example ## @group -## hd = huffmandict(1:4,[0.5 0.25 0.15 0.10]) -## hcode = huffmanenco(1:4,hd) # [ 1 0 1 0 0 0 0 0 1 ] -## huffmandeco(hcode,h d) # [1 2 3 4] +## hd = huffmandict (1:4, [0.5 0.25 0.15 0.10]); +## hcode = huffmanenco (1:4, hd); +## back = huffmandeco (hcode, hd) +## @result{} [1 2 3 4] ## @end group ## @end example -## @end deftypefn ## @seealso{huffmandict, huffmanenco} +## @end deftypefn -function sig=huffmandeco(hcode,dict) - if ( nargin < 2 || strcmp(class(dict),"cell")~=1 ) - error('usage: huffmanenco(sig,dict)'); - end - if (max(hcode) > 1 || min(hcode) < 0) - error("hcode has elements that are outside alphabet set ... - Cannot decode."); - end - -# TODO: -# O(log(N)) algorithms exist, but we need some effort to implement those -# Maybe sometime later, it would be a nice 1-day project -# Ref: A memory efficient Huffman Decoding Algorithm, AINA 2005, IEEE -# +function symbols = huffmandeco (hcode, dict) -# TODO: Somebody can implement a 'faster' algorithm than O(N^3) at present -# Decoding Algorithm O(N+k*log(N)) which is approximately O(N+Nlog(N)) -# -# 1. Separate the dictionary by the lengths -# and knows symbol correspondence. -# -# 2. Find the symbol in the dict of lengths l,h where -# l = smallest cw length ignoring 0 length CW, and -# h = largest cw length , with k=h-l+1; -# -# 3. Match the k codewords to the dict using binary -# search, and then you can declare decision. -# -# 4. In case of non-decodable words skip the start-bit -# used in the previous case, and then restart the same -# procedure from the next bit. -# - L=length(dict); - lenL=length(dict{1}); - lenH=0; - -# -# Know the ranges of operation -# - for itr=1:L - t=length(dict{itr}); - if(t < lenL) - lenL=t; - end - if(t > lenH) - lenH=t; - end + if (nargin != 2) + print_usage(); + elseif (!all((hcode == 1) + (hcode == 0)) || !isvector(hcode)) + error ("first argument must be a binary array"); + elseif (!strcmp (class (dict), "cell")) + error ("second argument must be of the class dict (from `huffmandict')"); end -# -# Now do a O(N^4) algorithm -# - itr=0; #offset into the hcode - sig=[]; #output - CL=length(hcode); + ## Convert the Huffman Dictionary to a Huffman Tree represented by + ## an array. + tree = dict2tree(dict); - %whole decoding loop. - while ( itr < CL ) - %decode one element (or just try to). - for itr_y=lenL:lenH - %look for word in dictionary. - %with flag to indicate found - %or not found. Detect end of buffer. - - if ( (itr+itr_y) > CL ) - break; - end + ## Traverse the tree and store the symbols. + symbols = []; + pointer = 1; # a pointer to a node of the tree. + for i = 1:length (hcode); + if (tree(pointer) != -1) + symbols = [symbols, tree(pointer)]; + pointer = 1; + endif + pointer = 2 * pointer + hcode(i); + endfor - word=hcode(itr+1:itr+itr_y); - flag=0; - - %word + ## Check if decodification was successful + if (tree(pointer) == -1) + warning ("could not decode last symbol.") + endif + symbols = [symbols, tree(pointer)]; +endfunction - %search loop. - for itr_z=1:L - if(isequal(dict{itr_z},word)) - itr=itr+itr_y; - sig=[sig itr_z]; - flag=1; - break; - end - end %for_ loop breaker +function tree = dict2tree (dict) + L = length(dict); + lengths = zeros(1,L); - if( flag == 1 ) - break; %also need to break_ above then. - end + ## the depth of the tree is limited by the maximum word length. + for i = 1:L + lengths(i) = length (dict{i}); + endfor + m = max (lengths); - end %for_ loop + tree = zeros(1,2^(m+1)-1)-1; + for i = 1:L + pointer = 1; + word = dict{i}; + for bit = word + pointer = 2 * pointer + bit; + endfor + tree(pointer) = i; + endfor +endfunction - #could not decode - if( flag == 0 ) - itr=itr+1; - sig=[sig -1]; - end - - end %while_ loop -end -%! -%! assert(huffmandeco(huffmanenco(1:4, huffmandict(1:4,[0.5 0.25 0.15 0.10])), huffmandict(1:4,[0.5 0.25 0.15 0.10])), [1:4],0) -%! +%!assert(huffmandeco(huffmanenco(1:4, huffmandict(1:4,[0.5 0.25 0.15 0.10])), huffmandict(1:4,[0.5 0.25 0.15 0.10])), [1:4],0) +%!assert(huffmandeco(huffmanenco([1:100 100:-1:1], huffmandict(1:100,ones(1,100)/100)), huffmandict(1:100,ones(1,100)/100)), [1:100 100:-1:1],0) +%!assert(huffmandeco([huffmanenco(1:4, huffmandict(1:4,[0.5 0.25 0.15 0.10])) 0], huffmandict(1:4,[0.5 0.25 0.15 0.10])), [1:4 -1],0) +%!fail('huffmandeco([huffmanenco(1:4, huffmandict(1:4,[0.5 0.25 0.15 0.10])) 0], huffmandict(1:4,[0.5 0.25 0.15 0.10]))','warning') +%!fail('huffmandeco(''this is not a code'',huffmandict(1:4,[0.5 0.25 0.15 0.10]))') +%!fail('huffmandeco([1 0 1 0],''this is not a dictionary'')') Modified: trunk/octave-forge/main/comm/inst/huffmandict.m =================================================================== --- trunk/octave-forge/main/comm/inst/huffmandict.m 2011-12-07 16:05:56 UTC (rev 9303) +++ trunk/octave-forge/main/comm/inst/huffmandict.m 2011-12-07 18:07:57 UTC (rev 9304) @@ -2,7 +2,7 @@ ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or +## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, @@ -49,8 +49,8 @@ ## @end example ## ## Reference: Dr.Rao's course EE5351 Digital Video Coding, at UT-Arlington. -## @end deftypefn ## @seealso{huffmandeco, huffmanenco} +## @end deftypefn ## Huffman code algorithm. ## while (uncombined_symbols_remain) @@ -69,18 +69,11 @@ ## reverse each symbol, and dump it out. ## -function cw_list=huffmandict(sym,source_prob,togglecode,minvar) +function cw_list = huffmandict (sym, source_prob, togglecode = 0, minvar = 0) if nargin < 2 - error("Usage: huffman_dict(source_prob,{togglecode 1-0 in code});") - elseif nargin < 3 - togglecode=0; - minvar=0; - elseif nargin < 4 - minvar=0; - end - - %need to compare to 1 - if((sum(source_prob)-1.0) > 1e-7 ) + print_usage; + ## need to compare to 1 + elseif((sum(source_prob)-1.0) > 1e-7 ) error("source probabilities must add up to 1.0"); end @@ -103,19 +96,19 @@ for itr1=1:L for itr2=itr1:L if(source_prob(itr1) < source_prob(itr2)) - t=source_prob(itr1); - source_prob(itr1)=source_prob(itr2); - source_prob(itr2)=t; + t=source_prob(itr1); + source_prob(itr1)=source_prob(itr2); + source_prob(itr2)=t; - t=index(itr1); - index(itr1)=index(itr2); - index(itr2)=t; + t=index(itr1); + index(itr1)=index(itr2); + index(itr2)=t; end end end - stage_list={}; - cw_list{1:L}=[]; + stage_list = {}; + cw_list = cell(1,L); stage_curr={}; stage_curr.prob_list=source_prob; @@ -145,8 +138,8 @@ % for i=1:(L-2) if((minvar && stage_curr.prob_list(i)<=nprob) || \ - stage_curr.prob_list(i) < nprob) - break; + stage_curr.prob_list(i) < nprob) + break; end end @@ -202,7 +195,7 @@ %disp('Before resorting') %cw_list - nw_list{1:L}=[]; + nw_list = cell(1,L); % % Re-sort the indices according to the probability list. % @@ -224,8 +217,7 @@ return end -%! + %!assert(huffmandict(1:4,[0.5 0.25 0.15 0.1],1), {[0],[1 0],[1 1 1],[1 1 0]},0) %!assert(huffmandict(1:4,0.25*ones(1,4),1),{[1 1],[1 0],[0 1],[0 0]},0) %!assert(huffmandict(1:4,[1 0 0 0 ]),{[1],[0 1],[0 0 0],[0 0 1]},0) -%! Modified: trunk/octave-forge/main/comm/inst/huffmanenco.m =================================================================== --- trunk/octave-forge/main/comm/inst/huffmanenco.m 2011-12-07 16:05:56 UTC (rev 9303) +++ trunk/octave-forge/main/comm/inst/huffmanenco.m 2011-12-07 18:07:57 UTC (rev 9304) @@ -2,7 +2,7 @@ ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or +## the Free Software Foundation; either version 3 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, @@ -26,24 +26,22 @@ ## ## @example ## @group -## hd = huffmandict(1:4,[0.5 0.25 0.15 0.10]) -## huffmanenco(1:4,hd) # [ 1 0 1 0 0 0 0 0 1 ] +## hd = huffmandict (1:4, [0.5 0.25 0.15 0.10]); +## huffmanenco (1:4, hd); +## @result{} [1 0 1 0 0 0 0 0 1] ## @end group ## @end example -## @end deftypefn ## @seealso{huffmandict, huffmandeco} +## @end deftypefn -function hcode=huffmanenco(sig,dict) - if ( nargin < 2 || strcmp(class(dict),"cell")~=1 ) - error('usage: huffmanenco(sig,dict)'); - end - if (max(sig) > length(dict)) || ( min(sig) < 1) - error("signal has elements that are outside alphabet set ... - Cannot encode."); - end - hcode=[dict{sig}]; +function hcode = huffmanenco (sig, dict) + if (nargin != 2 || strcmp (class (dict),"cell") != 1) + print_usage; + elseif (max (sig) > length (dict) || min (sig) < 1) + error("signal has elements that are outside alphabet set. Cannot encode."); + endif + hcode = [dict{sig}]; return end -%! -%! assert(huffmanenco(1:4, huffmandict(1:4,[0.5 0.25 0.15 0.10])), [ 1 0 1 0 0 0 0 0 1 ],0) -%! + +%!assert(huffmanenco(1:4, huffmandict(1:4,[0.5 0.25 0.15 0.10])), [ 1 0 1 0 0 0 0 0 1 ],0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[9848] trunk/octave-forge/main/comm/inst From: - 2012-03-13 03:43:34 ```Revision: 9848 http://octave.svn.sourceforge.net/octave/?rev=9848&view=rev Author: carandraug Date: 2012-03-13 03:43:28 +0000 (Tue, 13 Mar 2012) Log Message: ----------- prbs_generator, prbs_iterator, prbs_sequence: added copyright notice Modified Paths: -------------- trunk/octave-forge/main/comm/inst/prbs_generator.m trunk/octave-forge/main/comm/inst/prbs_iterator.m trunk/octave-forge/main/comm/inst/prbs_sequence.m Modified: trunk/octave-forge/main/comm/inst/prbs_generator.m =================================================================== --- trunk/octave-forge/main/comm/inst/prbs_generator.m 2012-03-13 03:05:35 UTC (rev 9847) +++ trunk/octave-forge/main/comm/inst/prbs_generator.m 2012-03-13 03:43:28 UTC (rev 9848) @@ -1,6 +1,18 @@ -## -## (C) 2006 Muthiah Annamalai +## Copyright (C) 2006 Muthiah Annamalai ## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see ;. + ## Implement book keeping for a Pseudo-Random Binary Sequence ( PRBS ) ## also called as a Linear Feedback Shift Register. ## @@ -39,12 +51,11 @@ ## ## See Also: This function is to be used along with functions ## prbs_iterator, and prbs_sequence. -## + function prbs=prbs_generator(polynomial,connections,initstate) prbs.reglen=max(polynomial); prbs.polynomial=polynomial; prbs.sregs=initstate; prbs.connections=connections; prbs.conlen=length(connections); - return end Modified: trunk/octave-forge/main/comm/inst/prbs_iterator.m =================================================================== --- trunk/octave-forge/main/comm/inst/prbs_iterator.m 2012-03-13 03:05:35 UTC (rev 9847) +++ trunk/octave-forge/main/comm/inst/prbs_iterator.m 2012-03-13 03:43:28 UTC (rev 9848) @@ -1,6 +1,18 @@ -## -## (C) 2006 Muthiah Annamalai -## +## Copyright (C) 2006 Muthiah Annamalai +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see ;. + ## This function generates the output bits from the PRBS ## state, for the number of iterations specified. ## @@ -34,7 +46,7 @@ ## ## See Also: This function is to be used along with functions ## prbs_iterator, prbs_generator and prbs_sequence. -## + function [outputseq,prbs]=prbs_iterator(prbs,iterations) if ( nargin < 2 ) iterations=2^(prbs.reglen)-1; @@ -68,7 +80,6 @@ end end - return; end ## Modified: trunk/octave-forge/main/comm/inst/prbs_sequence.m =================================================================== --- trunk/octave-forge/main/comm/inst/prbs_sequence.m 2012-03-13 03:05:35 UTC (rev 9847) +++ trunk/octave-forge/main/comm/inst/prbs_sequence.m 2012-03-13 03:43:28 UTC (rev 9848) @@ -1,6 +1,18 @@ -## -## (C) 2006 Muthiah Annamalai -## +## Copyright (C) 2006 Muthiah Annamalai +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see ;. + ## Implement book keeping for a Pseudo-Random Binary Sequence ( PRBS ) ## also called as a Linear Feedback Shift Register. ## @@ -25,10 +37,10 @@ ## prbs=prbs_generator([1 3 4],{[1 3 4]},[1 0 1 1]); ## x = prbs_sequence(prbs) #gives 15 ## - +## ## See Also: This function is to be used along with functions ## prbs_generator. -## + function [itrs,seq]=prbs_sequence(prbs) if nargin < 1 error("usage: prbs_sequence(prbs struct ); \ @@ -69,6 +81,4 @@ break; end end - - return; end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[9849] trunk/octave-forge/main/comm/inst From: - 2012-03-13 03:51:12 ```Revision: 9849 http://octave.svn.sourceforge.net/octave/?rev=9849&view=rev Author: carandraug Date: 2012-03-13 03:51:05 +0000 (Tue, 13 Mar 2012) Log Message: ----------- prbs_iterator, prbs_sequence: use print_usage, tabs per spaces, and specify end blocks Modified Paths: -------------- trunk/octave-forge/main/comm/inst/prbs_iterator.m trunk/octave-forge/main/comm/inst/prbs_sequence.m Modified: trunk/octave-forge/main/comm/inst/prbs_iterator.m =================================================================== --- trunk/octave-forge/main/comm/inst/prbs_iterator.m 2012-03-13 03:43:28 UTC (rev 9848) +++ trunk/octave-forge/main/comm/inst/prbs_iterator.m 2012-03-13 03:51:05 UTC (rev 9849) @@ -47,10 +47,11 @@ ## See Also: This function is to be used along with functions ## prbs_iterator, prbs_generator and prbs_sequence. -function [outputseq,prbs]=prbs_iterator(prbs,iterations) - if ( nargin < 2 ) - iterations=2^(prbs.reglen)-1; - end +function [outputseq, prbs] = prbs_iterator (prbs, iterations = 2^(prbs.reglen)-1) + + if ( nargin < 1 || nargin > 2 ) + print_usage; + endif outputseq=zeros(1,iterations); nstate=zeros(1,prbs.reglen); @@ -65,10 +66,10 @@ val=0; L=length(prbs.connections{itr2}); for itr3=2:L - val=bitxor(val,prbs.sregs(prbs.connections{itr2}(itr3))); - end + val=bitxor(val,prbs.sregs(prbs.connections{itr2}(itr3))); + endfor nstate(prbs.connections{itr2}(1))=val; - end + endfor ## rotate the output discarding the last output. prbs.sregs=[0 prbs.sregs(1:prbs.reglen-1)]; @@ -77,10 +78,10 @@ for itr2=1:prbs.conlen prbs.sregs(itr2)=nstate(itr2); nstate(itr2)=0; # reset. - end + endfor - end -end + endfor +endfunction ## ## TEST CASES FOR PRBS. Modified: trunk/octave-forge/main/comm/inst/prbs_sequence.m =================================================================== --- trunk/octave-forge/main/comm/inst/prbs_sequence.m 2012-03-13 03:43:28 UTC (rev 9848) +++ trunk/octave-forge/main/comm/inst/prbs_sequence.m 2012-03-13 03:51:05 UTC (rev 9849) @@ -42,13 +42,10 @@ ## prbs_generator. function [itrs,seq]=prbs_sequence(prbs) - if nargin < 1 - error("usage: prbs_sequence(prbs struct ); \ - create the prbs sequence using prbs_generator() function. \ - This function generates the ML length sequence of 1 period\ - and returns to the user.") - end - nstate=zeros(1,prbs.reglen); + if nargin != 1 + print_usage; + endif + nstate=zeros(1,prbs.reglen); itrs=0; seq = []; inits = prbs.sregs; @@ -62,10 +59,10 @@ val=0; L=length(prbs.connections{itr2}); for itr3=2:L - val=bitxor(val,prbs.sregs(prbs.connections{itr2}(itr3))); - end + val=bitxor(val,prbs.sregs(prbs.connections{itr2}(itr3))); + endfor nstate(prbs.connections{itr2}(1))=val; - end + endfor ## rotate the output discarding the last output. seq = [seq, prbs.sregs(end)]; @@ -75,10 +72,10 @@ for itr2=1:prbs.conlen prbs.sregs(itr2)=nstate(itr2); nstate(itr2)=0; # reset. - end + endfor if(isequal(prbs.sregs,inits)) - break; - end - end + break + endif + endwhile end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Octave-cvsupdate] SF.net SVN: octave:[10453] trunk/octave-forge/main/comm/inst From: - 2012-05-17 03:49:42 ```Revision: 10453 http://octave.svn.sourceforge.net/octave/?rev=10453&view=rev Author: jordigh Date: 2012-05-17 03:49:35 +0000 (Thu, 17 May 2012) Log Message: ----------- Unindent (and thus re-enable) some tests in comm package Modified Paths: -------------- trunk/octave-forge/main/comm/inst/awgn.m trunk/octave-forge/main/comm/inst/bi2de.m trunk/octave-forge/main/comm/inst/de2bi.m trunk/octave-forge/main/comm/inst/egolaydec.m Modified: trunk/octave-forge/main/comm/inst/awgn.m =================================================================== --- trunk/octave-forge/main/comm/inst/awgn.m 2012-05-16 16:26:13 UTC (rev 10452) +++ trunk/octave-forge/main/comm/inst/awgn.m 2012-05-17 03:49:35 UTC (rev 10453) @@ -133,15 +133,15 @@ endfunction - %!shared x, y, noisy - %! x = [0:0.01:2*pi]; y = sin (x); - %! noisy = awgn (y, 20, "dB", "measured"); +%!shared x, y, noisy +%! x = [0:0.01:2*pi]; y = sin (x); +%! noisy = awgn (y, 20, "dB", "measured"); ## Test of noisy is pretty arbitrary, but should pickup most errors - %!error awgn (); - %!error awgn (1); - %!error awgn (1,1,1,1,1); - %!assert (isreal(noisy)); - %!assert (iscomplex(awgn(y+1i,20,"dB","measured"))); - %!assert (size(y) == size(noisy)) - %!assert (abs(10*log10(mean(y.^2)/mean((y-noisy).^ 2)) - 20) < 1); +%!error awgn (); +%!error awgn (1); +%!error awgn (1,1,1,1,1); +%!assert (isreal(noisy)); +%!assert (iscomplex(awgn(y+1i,20,"dB","measured"))); +%!assert (size(y) == size(noisy)) +%!assert (abs(10*log10(mean(y.^2)/mean((y-noisy).^ 2)) - 20) < 1); Modified: trunk/octave-forge/main/comm/inst/bi2de.m =================================================================== --- trunk/octave-forge/main/comm/inst/bi2de.m 2012-05-16 16:26:13 UTC (rev 10452) +++ trunk/octave-forge/main/comm/inst/bi2de.m 2012-05-17 03:49:35 UTC (rev 10453) @@ -75,22 +75,22 @@ endfunction - %!shared x - %! x = randi ([0 1], 100, 16); - %!assert (bi2de (0), 0) - %!assert (bi2de (1), 1) - %!assert (bi2de (ones (1, 8)), 255) - %!assert (bi2de ([7 7 7 7], 8), 4095) - %!assert (size (bi2de (x)), [100 1]) - %!assert (bi2de (x, "right-msb"), bi2de (x)) - %!assert (bi2de (x, "left-msb"), bi2de (fliplr (x))) +%!shared x +%! x = randi ([0 1], 100, 16); +%!assert (bi2de (0), 0) +%!assert (bi2de (1), 1) +%!assert (bi2de (ones (1, 8)), 255) +%!assert (bi2de ([7 7 7 7], 8), 4095) +%!assert (size (bi2de (x)), [100 1]) +%!assert (bi2de (x, "right-msb"), bi2de (x)) +%!assert (bi2de (x, "left-msb"), bi2de (fliplr (x))) %% Test input validation - %!error bi2de () - %!error bi2de (1, 2, 3, 4) - %!error bi2de (1, 2, 3) - %!error bi2de (1, 2, "invalid") - %!error bi2de (0.1) - %!error bi2de (-1) - %!error bi2de (2) - %!error bi2de (7, 6) +%!error bi2de () +%!error bi2de (1, 2, 3, 4) +%!error bi2de (1, 2, 3) +%!error bi2de (1, 2, "invalid") +%!error bi2de (0.1) +%!error bi2de (-1) +%!error bi2de (2) +%!error bi2de (7, 6) Modified: trunk/octave-forge/main/comm/inst/de2bi.m =================================================================== --- trunk/octave-forge/main/comm/inst/de2bi.m 2012-05-16 16:26:13 UTC (rev 10452) +++ trunk/octave-forge/main/comm/inst/de2bi.m 2012-05-17 03:49:35 UTC (rev 10453) @@ -87,21 +87,21 @@ endfunction - %!shared x - %! x = randi ([0 2^16-1], 100, 1); - %!assert (de2bi (0), 0) - %!assert (de2bi (1), 1) - %!assert (de2bi (255), ones (1, 8)) - %!assert (de2bi (255, [], 256), 255) - %!assert (de2bi (1023, 8, 8), [7 7 7 1 0 0 0 0]) - %!assert (size (de2bi (x, 16)), [100 16]) - %!assert (de2bi (x, 16, "right-msb"), de2bi (x, 16)) - %!assert (de2bi (x, 16, "left-msb"), fliplr (de2bi (x, 16))) +%!shared x +%! x = randi ([0 2^16-1], 100, 1); +%!assert (de2bi (0), 0) +%!assert (de2bi (1), 1) +%!assert (de2bi (255), ones (1, 8)) +%!assert (de2bi (255, [], 256), 255) +%!assert (de2bi (1023, 8, 8), [7 7 7 1 0 0 0 0]) +%!assert (size (de2bi (x, 16)), [100 16]) +%!assert (de2bi (x, 16, "right-msb"), de2bi (x, 16)) +%!assert (de2bi (x, 16, "left-msb"), fliplr (de2bi (x, 16))) %% Test input validation - %!error de2bi () - %!error de2bi (1, 2, 3, 4, 5) - %!error de2bi (1, 2, 3, 4) - %!error de2bi (1, 2, 3, "invalid") - %!error de2bi (0.1) - %!error de2bi (-1) +%!error de2bi () +%!error de2bi (1, 2, 3, 4, 5) +%!error de2bi (1, 2, 3, 4) +%!error de2bi (1, 2, 3, "invalid") +%!error de2bi (0.1) +%!error de2bi (-1) Modified: trunk/octave-forge/main/comm/inst/egolaydec.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolaydec.m 2012-05-16 16:26:13 UTC (rev 10452) +++ trunk/octave-forge/main/comm/inst/egolaydec.m 2012-05-17 03:49:35 UTC (rev 10453) @@ -118,9 +118,9 @@ return; end - %! - %!assert(egolaydec([1 1 1 zeros(1,21)]),zeros(1,24)) - %!assert(egolaydec([1 0 1 zeros(1,20) 1]),zeros(1,24)) - %! +%! +%!assert(egolaydec([1 1 1 zeros(1,21)]),zeros(1,24)) +%!assert(egolaydec([1 0 1 zeros(1,20) 1]),zeros(1,24)) +%! This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```