3 * Copyright 2002 Free Software Foundation, Inc.
\r
5 * This file is part of GNU Radio
\r
7 * GNU Radio is free software; you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License as published by
\r
9 * the Free Software Foundation; either version 2, or (at your option)
\r
10 * any later version.
\r
12 * GNU Radio is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with GNU Radio; see the file COPYING. If not, write to
\r
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
\r
20 * Boston, MA 02111-1307, USA.
\r
26 #include <stdexcept>
\r
28 #include "quicksort_index.h"
\r
29 #include "interleaver.h"
\r
31 interleaver::interleaver()
\r
35 d_DEINTER.resize(0);
\r
38 interleaver::interleaver(const interleaver &INTERLEAVER)
\r
40 d_K=INTERLEAVER.K();
\r
41 d_INTER=INTERLEAVER.INTER();
\r
42 d_DEINTER=INTERLEAVER.DEINTER();
\r
45 interleaver::interleaver(const int K, const std::vector<int> &INTER)
\r
49 d_DEINTER.resize(d_K);
\r
51 // generate DEINTER table
\r
52 for(int i=0;i<d_K;i++) {
\r
53 d_DEINTER[d_INTER[i]]=i;
\r
57 //######################################################################
\r
58 //# Read an INTERLEAVER specification from a file.
\r
59 //# Format (hopefully will become more flexible in the future...):
\r
62 //# list of space separated K integers from 0 to K-1 in appropriate order
\r
63 //# optional comments
\r
64 //######################################################################
\r
65 interleaver::interleaver(const char *name)
\r
67 FILE *interleaverfile;
\r
69 if((interleaverfile=fopen(name,"r"))==NULL)
\r
70 throw std::runtime_error ("file open error in interleaver()");
\r
71 //printf("file open error in interleaver()\n");
\r
73 fscanf(interleaverfile,"%d\n",&d_K);
\r
74 d_INTER.resize(d_K);
\r
75 d_DEINTER.resize(d_K);
\r
77 for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));
\r
79 // generate DEINTER table
\r
80 for(int i=0;i<d_K;i++) {
\r
81 d_DEINTER[d_INTER[i]]=i;
\r
85 //######################################################################
\r
86 //# Generate a random interleaver
\r
87 //######################################################################
\r
88 interleaver::interleaver(const int K, unsigned int seed)
\r
91 d_INTER.resize(d_K);
\r
92 d_DEINTER.resize(d_K);
\r
95 std::vector<int> tmp(d_K);
\r
96 for(int i=0;i<d_K;i++) {
\r
100 //quicksort_index <int> (tmp,d_INTER,0,d_K-1); got to resolve this...
\r
101 quicksort_index1 (tmp,d_INTER,0,d_K-1);
\r
103 // generate DEINTER table
\r
104 for(int i=0;i<d_K;i++) {
\r
105 d_DEINTER[d_INTER[i]]=i;
\r