summaryrefslogtreecommitdiff
path: root/macros/gfrepcov.sci
blob: 35a9cb61ad3e1c2b2b8b16185562771e968b080f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function q = gfrepcov(p)
//   This function represents a binary polynomial in standard ascending order format.
//
//   Calling Sequence
//   Q = GFREPCOV(P)
//
//   Description
//   Q = GFREPCOV(P) converts vector (P) to standard ascending
//   order format vector (Q), which is a vector that lists the coefficients in 
//   order of ascending exponents,  if P represents a binary polynomial 
//   as a vector of exponents with non-zero coefficients.
//
//   Examples
//   The matrix below represents the binary polynomial $1 + s + s^2 + s^4$
//   Implies output vector should be [1 1 1 0 1]
//   A=[0 1 2 4 ]
//   B=gfrepcov(A)
//   disp(B)
//   
//
//   Authors
//   Pola Lakshmi Priyanka, IIT Bombay

//*************************************************************************************************************************************//

//Input arguments 
[out_a,inp_a]=argn(0)

[row_p, col_p] = size(p);

// Error checking 
if ( isempty(p) | ndims(p)>2 | row_p > 1 )
    error('comm:gfrepcov: P should be a vector');
end
for j=1:col_p
if (floor(p(1,j))~=p(1,j) | abs(p(1,j))~=p(1,j)  )
    error('comm:gfrepcov: Elements of the vector should be non negative integers');
end
end

// Check if the given vector is in ascending order format, if not convert //
if max(p) > 1

// Check if P has any repetative elements.
    
    if (length(unique(p))~=length(p))
        error('comm:gfrepcov: Repeated elements in Vector');
    end
    q = zeros(1,max(p)+1);
    q(p+1) = 1;

else
    
    q = p;
    
end
endfunction