summaryrefslogtreecommitdiff
path: root/viterbi_generator/utils/lower_utils/lower_utils/complex_vect2number.m
blob: f0d6d25755555f663e30ba4fc3e2d117258d210b (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
function [ number ] = complex_vect2number(vector)
 
 ###########################################################################
 #   Copyright (C) 2008 by Piotr Krysik                                    #
 #   pkrysik@stud.elka.pw.edu.pl                                           #
 #                                                                         #
 #   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, write to the                         #
 #   Free Software Foundation, Inc.,                                       #
 #   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             #
 ###########################################################################

% Change complex vector of values: 1,-1 or j,-j 
% into a integer number.

  number=0;
  [r,Lh] = size(vector);
  for l=1:Lh,
    position=2**(l-1);
    if(vector(l)==1),
      number=number+position*(1);
    elseif(vector(l)==-1),
      number=number+position*(-1);
    elseif(vector(l)==-j),
      number=number+position*(1);      
    elseif(vector(l)==j),
      number=number+position*(-1);      
    end    
  end
  if number < 0,
    number=floor(number/2);
  else
    number=ceil(number/2);
  end
personal git repositories of Harald Welte. Your mileage may vary