]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/helscanintrlv.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / helscanintrlv.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} =} helscanintrlv (@var{data}, @var{nrows}, @var{ncols},@var{Nshift})
18 ## @var{nrows}-by-@var{ncols}.
19 ## @seealso{helscandeintrlv}
20 ## @end deftypefn
21
22 function outdata = helscanintrlv(data,Nrows,Ncols,Nshift)
23         
24         if(nargin ~= 4 )
25                 error('usage : interlvd = helscanintrlv(data,Nrows,Ncols,Nshift)');
26         end
27
28         if(~isscalar(Nrows) || ~isscalar(Ncols))
29                 error("Nrows and Ncols must be integers");
30         end
31         
32         if( Nrows ~= floor(Nrows)|| Ncols ~= floor(Ncols))
33                 error("Nrows and Ncols 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 size(data,1) ~= Nrows*Ncols
45                 error("The length of data must be equals to Ncols*Nrows");
46         end
47
48         # create the interleaving indices 
49         idx0 = 0:Nrows*Ncols-1; 
50         idxMod = rem(idx0,Ncols); 
51         idxFlr = idx0 - idxMod;
52         inds = 1+rem(idxFlr + idxMod * Ncols * Nshift + idxMod,Nrows*Ncols);
53
54         # for each column
55         for k = 1:s(2)
56                 outdata(:,k) = data(inds,k);
57         end
58
59         if didTranspose
60                 outdata = outdata.';
61         end