]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/helintrlv.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / helintrlv.m
1 ## Copyright (C) 2010 Mark Borgerding <mark@borgerding.net>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{outdata} =} helintrlv (@var{data}, @var{col}, @var{ngrp},@var{stp})
18 ## @var{col}-by-@var{ngrp}.
19 ## @seealso{heldeintrlv}
20 ## @end deftypefn
21
22 function [outdata,outstate] = helintrlv(data,col,ngrp,stp,init_state)
23
24         if (nargin < 4  ||nargin>5)
25                 error('usage : interlvd = helintrlv(data,col,ngrp,stp)');
26         end
27
28         if(~isscalar(col) || ~isscalar(ngrp))
29                 error("col and ngrp must be integers");
30         end
31         
32         if( col ~= floor(col)|| ngrp ~= floor(ngrp))
33                 error("col and ngrp must be integers");
34         end
35
36         didTranspose=0;
37         if ( isvector(data) && columns(data) > rows(data) )
38                 data = data.';
39                 didTranspose=1;
40         end
41
42         s = size(data);
43
44         if s(1) ~= col*ngrp
45                 error("The length of data must be equals to ngrp*col");
46         end
47
48         if nargin==4
49                 init_state = zeros(stp*col*(col-1)/2,s(2));
50         end
51
52         outstate =[];
53         # for each column
54         for k = 1:s(2)
55                 tmp = reshape( data(:,k) , ngrp, col );
56                 instate = init_state(:,k);
57                 outstateCol=[];
58                 for k1=2:col
59                         curStepSize = (k1-1)*stp;
60                         tmpCol= [instate(1:curStepSize) ;tmp(:,k1)];
61                         tmp(:,k1) = tmpCol(1:ngrp);
62                         outstateCol=[outstateCol;tmpCol(end+1-curStepSize:end)];
63                         instate = instate(curStepSize+1:end);
64                 end
65                 outdata(:,k) = reshape(tmp.',s(1),1);
66                 outstate =  [outstate outstateCol];
67         end
68
69         if didTranspose
70                 outdata = outdata.';
71         end