-/* -*- c++ -*- */\r
-/*\r
- * Copyright 2002 Free Software Foundation, Inc.\r
- *\r
- * This file is part of GNU Radio\r
- *\r
- * GNU Radio is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2, or (at your option)\r
- * any later version.\r
- *\r
- * GNU Radio is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GNU Radio; see the file COPYING. If not, write to\r
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
- * Boston, MA 02111-1307, USA.\r
- */\r
-\r
-#include <cstdio>\r
-#include <stdexcept>\r
-#include <cmath>\r
-#include "base.h"\r
-\r
-\r
-bool dec2base(unsigned int num, int base, std::vector<int> &s)\r
-{\r
- int l = s.size();\r
- unsigned int n=num;\r
- for(int i=0;i<l;i++) {\r
- s[l-i-1] = n % base; //MSB first\r
- n /= base;\r
- }\r
- if(n!=0) {\r
- printf("Number %d requires more than %d digits.",num,l);\r
- return false;\r
- }\r
- else\r
- return true;\r
-}\r
-\r
-\r
-unsigned int base2dec(const std::vector<int> &s, int base)\r
-{\r
- int l = s.size();\r
- unsigned int num=0;\r
- for(int i=0;i<l;i++)\r
- num=num*base+s[i];\r
- return num;\r
-}\r
-\r
-\r
-bool dec2bases(unsigned int num, const std::vector<int> &bases, std::vector<int> &s)\r
-{\r
- int l = s.size();\r
- unsigned int n=num;\r
- for(int i=0;i<l;i++) {\r
- s[l-i-1] = n % bases[l-i-1];\r
- n /= bases[l-i-1];\r
- }\r
- if(n!=0) {\r
- printf("Number %d requires more than %d digits.",num,l);\r
- return false;\r
- }\r
- else\r
- return true;\r
-}\r
-\r
-\r
-\r
-unsigned int bases2dec(const std::vector<int> &s, const std::vector<int> &bases)\r
-{\r
- int l = s.size();\r
- unsigned int num=0;\r
- for(int i=0;i<l;i++)\r
- num = num * bases[i] + s[i];\r
- return num;\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <cstdio>
+#include <stdexcept>
+#include <cmath>
+#include "base.h"
+
+
+bool dec2base(unsigned int num, int base, std::vector<int> &s)
+{
+ int l = s.size();
+ unsigned int n=num;
+ for(int i=0;i<l;i++) {
+ s[l-i-1] = n % base; //MSB first
+ n /= base;
+ }
+ if(n!=0) {
+ printf("Number %d requires more than %d digits.",num,l);
+ return false;
+ }
+ else
+ return true;
+}
+
+
+unsigned int base2dec(const std::vector<int> &s, int base)
+{
+ int l = s.size();
+ unsigned int num=0;
+ for(int i=0;i<l;i++)
+ num=num*base+s[i];
+ return num;
+}
+
+
+bool dec2bases(unsigned int num, const std::vector<int> &bases, std::vector<int> &s)
+{
+ int l = s.size();
+ unsigned int n=num;
+ for(int i=0;i<l;i++) {
+ s[l-i-1] = n % bases[l-i-1];
+ n /= bases[l-i-1];
+ }
+ if(n!=0) {
+ printf("Number %d requires more than %d digits.",num,l);
+ return false;
+ }
+ else
+ return true;
+}
+
+
+
+unsigned int bases2dec(const std::vector<int> &s, const std::vector<int> &bases)
+{
+ int l = s.size();
+ unsigned int num=0;
+ for(int i=0;i<l;i++)
+ num = num * bases[i] + s[i];
+ return num;
+}
+
+
+
+
+
+
+
+
+
+
+
-/* -*- c++ -*- */\r
-/*\r
- * Copyright 2002 Free Software Foundation, Inc.\r
- *\r
- * This file is part of GNU Radio\r
- *\r
- * GNU Radio is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2, or (at your option)\r
- * any later version.\r
- *\r
- * GNU Radio is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GNU Radio; see the file COPYING. If not, write to\r
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
- * Boston, MA 02111-1307, USA.\r
- */\r
-\r
-#ifndef INCLUDED_TRELLIS_BASE_H\r
-#define INCLUDED_TRELLIS_BASE_H\r
-\r
-#include <vector>\r
-\r
-/*!\r
- * \brief change base\r
- */\r
-\r
-\r
-bool dec2base(unsigned int num, int base, std::vector<int> &s);\r
-bool dec2bases(unsigned int num, const std::vector<int> &bases, std::vector<int> &s);\r
-unsigned int base2dec(const std::vector<int> &s, int base);\r
-unsigned int bases2dec(const std::vector<int> &s, const std::vector<int> &bases);\r
-\r
-#endif\r
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_TRELLIS_BASE_H
+#define INCLUDED_TRELLIS_BASE_H
+
+#include <vector>
+
+/*!
+ * \brief change base
+ */
+
+
+bool dec2base(unsigned int num, int base, std::vector<int> &s);
+bool dec2bases(unsigned int num, const std::vector<int> &bases, std::vector<int> &s);
+unsigned int base2dec(const std::vector<int> &s, int base);
+unsigned int bases2dec(const std::vector<int> &s, const std::vector<int> &bases);
+
+#endif
-/* -*- c++ -*- */\r
-/*\r
- * Copyright 2002 Free Software Foundation, Inc.\r
- *\r
- * This file is part of GNU Radio\r
- *\r
- * GNU Radio is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2, or (at your option)\r
- * any later version.\r
- *\r
- * GNU Radio is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GNU Radio; see the file COPYING. If not, write to\r
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
- * Boston, MA 02111-1307, USA.\r
- */\r
-\r
-#include <cstdio>\r
-#include <stdexcept>\r
-#include <cmath>\r
-#include "base.h"\r
-#include "fsm.h"\r
-\r
-\r
-fsm::fsm()\r
-{\r
- d_I=0;\r
- d_S=0;\r
- d_O=0;\r
- d_NS.resize(0);\r
- d_OS.resize(0);\r
- d_PS.resize(0);\r
- d_PI.resize(0);\r
- d_TMi.resize(0);\r
- d_TMl.resize(0);\r
-}\r
-\r
-fsm::fsm(const fsm &FSM)\r
-{\r
- d_I=FSM.I();\r
- d_S=FSM.S();\r
- d_O=FSM.O();\r
- d_NS=FSM.NS();\r
- d_OS=FSM.OS();\r
- d_PS=FSM.PS();\r
- d_PI=FSM.PI();\r
- d_TMi=FSM.TMi();\r
- d_TMl=FSM.TMl();\r
-}\r
-\r
-fsm::fsm(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS)\r
-{\r
- d_I=I;\r
- d_S=S;\r
- d_O=O;\r
- d_NS=NS;\r
- d_OS=OS;\r
- \r
- generate_PS_PI();\r
- generate_TM();\r
-}\r
-\r
-//######################################################################\r
-//# Read an FSM specification from a file.\r
-//# Format (hopefully will become more flexible in the future...):\r
-//# I S O (in the first line)\r
-//# blank line\r
-//# Next state matrix (S lines, each with I integers separated by spaces)\r
-//# blank line\r
-//# output symbol matrix (S lines, each with I integers separated by spaces)\r
-//# optional comments\r
-//######################################################################\r
-fsm::fsm(const char *name) \r
-{\r
- FILE *fsmfile;\r
-\r
- if((fsmfile=fopen(name,"r"))==NULL) \r
- throw std::runtime_error ("fsm::fsm(const char *name): file open error\n");\r
- //printf("file open error in fsm()\n");\r
- \r
- fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O);\r
- d_NS.resize(d_I*d_S);\r
- d_OS.resize(d_I*d_S);\r
-\r
- for(int i=0;i<d_S;i++) {\r
- for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_NS[i*d_I+j]));\r
- }\r
- for(int i=0;i<d_S;i++) {\r
- for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_OS[i*d_I+j]));\r
- }\r
- \r
- generate_PS_PI();\r
- generate_TM();\r
-}\r
-\r
-\r
-\r
-\r
-//######################################################################\r
-//# Automatically generate the FSM from the generator matrix\r
-//# of a (n,k) binary convolutional code\r
-//######################################################################\r
-fsm::fsm(int k, int n, const std::vector<int> &G)\r
-{\r
-\r
- // calculate maximum memory requirements for each input stream\r
- std::vector<int> max_mem_x(k,-1);\r
- int max_mem = -1;\r
- for(int i=0;i<k;i++) {\r
- for(int j=0;j<n;j++) {\r
- int mem = -1;\r
- if(G[i*n+j]!=0)\r
- mem=(int)(log(G[i*n+j])/log(2.0));\r
- if(mem>max_mem_x[i])\r
- max_mem_x[i]=mem;\r
- if(mem>max_mem)\r
- max_mem=mem;\r
- }\r
- }\r
- \r
-//printf("max_mem_x\n");\r
-//for(int j=0;j<max_mem_x.size();j++) printf("%d ",max_mem_x[j]); printf("\n");\r
-\r
- // calculate total memory requirements to set S\r
- int sum_max_mem = 0;\r
- for(int i=0;i<k;i++)\r
- sum_max_mem += max_mem_x[i];\r
-\r
-//printf("sum_max_mem = %d\n",sum_max_mem);\r
-\r
- d_I=1<<k;\r
- d_S=1<<sum_max_mem;\r
- d_O=1<<n;\r
- \r
- // binary representation of the G matrix\r
- std::vector<std::vector<int> > Gb(k*n);\r
- for(int j=0;j<k*n;j++) {\r
- Gb[j].resize(max_mem+1);\r
- dec2base(G[j],2,Gb[j]);\r
-//printf("Gb\n");\r
-//for(int m=0;m<Gb[j].size();m++) printf("%d ",Gb[j][m]); printf("\n");\r
- }\r
-\r
- // alphabet size of each shift register \r
- std::vector<int> bases_x(k);\r
- for(int j=0;j<k ;j++) \r
- bases_x[j] = 1 << max_mem_x[j];\r
-//printf("bases_x\n");\r
-//for(int j=0;j<max_mem_x.size();j++) printf("%d ",max_mem_x[j]); printf("\n");\r
-\r
- d_NS.resize(d_I*d_S);\r
- d_OS.resize(d_I*d_S);\r
-\r
- std::vector<int> sx(k);\r
- std::vector<int> nsx(k);\r
- std::vector<int> tx(k);\r
- std::vector<std::vector<int> > tb(k);\r
- for(int j=0;j<k;j++)\r
- tb[j].resize(max_mem+1);\r
- std::vector<int> inb(k);\r
- std::vector<int> outb(n);\r
-\r
-\r
- for(int s=0;s<d_S;s++) {\r
- dec2bases(s,bases_x,sx); // split s into k values, each representing on of the k shift registers\r
-//printf("state = %d \nstates = ",s);\r
-//for(int j=0;j<sx.size();j++) printf("%d ",sx[j]); printf("\n");\r
- for(int i=0;i<d_I;i++) {\r
- dec2base(i,2,inb); // input in binary\r
-//printf("input = %d \ninputs = ",i);\r
-//for(int j=0;j<inb.size();j++) printf("%d ",inb[j]); printf("\n");\r
-\r
- // evaluate next state\r
- for(int j=0;j<k;j++)\r
- nsx[j] = (inb[j]*bases_x[j]+sx[j])/2; // next state (for each shift register) MSB first\r
- d_NS[s*d_I+i]=bases2dec(nsx,bases_x); // collect all values into the new state\r
-\r
- // evaluate transitions\r
- for(int j=0;j<k;j++)\r
- tx[j] = inb[j]*bases_x[j]+sx[j]; // transition (for each shift register)MSB first\r
- for(int j=0;j<k;j++) {\r
- dec2base(tx[j],2,tb[j]); // transition in binary\r
-//printf("transition = %d \ntransitions = ",tx[j]);\r
-//for(int m=0;m<tb[j].size();m++) printf("%d ",tb[j][m]); printf("\n");\r
- }\r
-\r
- // evaluate outputs\r
- for(int nn=0;nn<n;nn++) {\r
- outb[nn] = 0;\r
- for(int j=0;j<k;j++) {\r
- for(int m=0;m<max_mem+1;m++)\r
- outb[nn] = (outb[nn] + Gb[j*n+nn][m]*tb[j][m]) % 2; // careful: polynomial 1+D ir represented as 110, not as 011\r
-//printf("output %d equals %d\n",nn,outb[nn]);\r
- }\r
- }\r
- d_OS[s*d_I+i] = base2dec(outb,2);\r
- }\r
- }\r
-\r
- generate_PS_PI();\r
- generate_TM();\r
-}\r
-\r
-\r
-\r
-\r
-//######################################################################\r
-//# Automatically generate an FSM specification describing the \r
-//# ISI for a channel\r
-//# of length ch_length and a modulation of size mod_size\r
-//######################################################################\r
-fsm::fsm(int mod_size, int ch_length)\r
-{\r
- d_I=mod_size;\r
- d_S=(int) (pow(1.0*d_I,1.0*ch_length-1)+0.5);\r
- d_O=d_S*d_I;\r
-\r
- d_NS.resize(d_I*d_S);\r
- d_OS.resize(d_I*d_S);\r
-\r
- for(int s=0;s<d_S;s++) {\r
- for(int i=0;i<d_I;i++) { \r
- int t=i*d_S+s;\r
- d_NS[s*d_I+i] = t/d_I;\r
- d_OS[s*d_I+i] = t;\r
- }\r
- }\r
- \r
- generate_PS_PI();\r
- generate_TM();\r
-}\r
-\r
-\r
-//######################################################################\r
-//# generate the PS and PI tables for later use\r
-//######################################################################\r
-void fsm::generate_PS_PI()\r
-{\r
- d_PS.resize(d_I*d_S);\r
- d_PI.resize(d_I*d_S);\r
-\r
- for(int i=0;i<d_S;i++) {\r
- int j=0;\r
- for(int ii=0;ii<d_S;ii++) for(int jj=0;jj<d_I;jj++) {\r
- if(d_NS[ii*d_I+jj]!=i) continue;\r
- d_PS[i*d_I+j]=ii;\r
- d_PI[i*d_I+j]=jj;\r
- j++;\r
- }\r
- }\r
-}\r
-\r
-\r
-//######################################################################\r
-//# generate the termination matrices TMl and TMi for later use\r
-//######################################################################\r
-void fsm::generate_TM()\r
-{\r
- d_TMi.resize(d_S*d_S);\r
- d_TMl.resize(d_S*d_S);\r
-\r
- for(int i=0;i<d_S*d_S;i++) {\r
- d_TMi[i] = -1; // no meaning\r
- d_TMl[i] = d_S; //infinity: you need at most S-1 steps\r
- if (i/d_S == i%d_S)\r
- d_TMl[i] = 0;\r
- }\r
-\r
- for(int s=0;s<d_S;s++) {\r
- bool done = false;\r
- int attempts = 0;\r
- while (done == false && attempts < d_S-1) {\r
- done = find_es(s);\r
- attempts ++;\r
- }\r
- if (done == false)\r
- //throw std::runtime_error ("fsm::generate_TM(): FSM appears to be disconnected\n");\r
- printf("fsm::generate_TM(): FSM appears to be disconnected\n");\r
- }\r
-}\r
-\r
-\r
-// find a path from any state to the ending state "es"\r
-bool fsm::find_es(int es)\r
-{\r
- bool done = true;\r
- for(int s=0;s<d_S;s++) {\r
- if(d_TMl[s*d_S+es] < d_S) \r
- continue;\r
- int minl=d_S;\r
- int mini=-1;\r
- for(int i=0;i<d_I;i++) {\r
- if( 1 + d_TMl[d_NS[s*d_I+i]*d_S+es] < minl) {\r
- minl = 1 + d_TMl[d_NS[s*d_I+i]*d_S+es];\r
- mini = i;\r
- }\r
- }\r
- if (mini != -1) {\r
- d_TMl[s*d_S+es]=minl;\r
- d_TMi[s*d_S+es]=mini;\r
- }\r
- else\r
- done = false;\r
- }\r
- return done;\r
-}\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <cstdio>
+#include <stdexcept>
+#include <cmath>
+#include "base.h"
+#include "fsm.h"
+
+
+fsm::fsm()
+{
+ d_I=0;
+ d_S=0;
+ d_O=0;
+ d_NS.resize(0);
+ d_OS.resize(0);
+ d_PS.resize(0);
+ d_PI.resize(0);
+ d_TMi.resize(0);
+ d_TMl.resize(0);
+}
+
+fsm::fsm(const fsm &FSM)
+{
+ d_I=FSM.I();
+ d_S=FSM.S();
+ d_O=FSM.O();
+ d_NS=FSM.NS();
+ d_OS=FSM.OS();
+ d_PS=FSM.PS();
+ d_PI=FSM.PI();
+ d_TMi=FSM.TMi();
+ d_TMl=FSM.TMl();
+}
+
+fsm::fsm(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS)
+{
+ d_I=I;
+ d_S=S;
+ d_O=O;
+ d_NS=NS;
+ d_OS=OS;
+
+ generate_PS_PI();
+ generate_TM();
+}
+
+//######################################################################
+//# Read an FSM specification from a file.
+//# Format (hopefully will become more flexible in the future...):
+//# I S O (in the first line)
+//# blank line
+//# Next state matrix (S lines, each with I integers separated by spaces)
+//# blank line
+//# output symbol matrix (S lines, each with I integers separated by spaces)
+//# optional comments
+//######################################################################
+fsm::fsm(const char *name)
+{
+ FILE *fsmfile;
+
+ if((fsmfile=fopen(name,"r"))==NULL)
+ throw std::runtime_error ("fsm::fsm(const char *name): file open error\n");
+ //printf("file open error in fsm()\n");
+
+ fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O);
+ d_NS.resize(d_I*d_S);
+ d_OS.resize(d_I*d_S);
+
+ for(int i=0;i<d_S;i++) {
+ for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_NS[i*d_I+j]));
+ }
+ for(int i=0;i<d_S;i++) {
+ for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_OS[i*d_I+j]));
+ }
+
+ generate_PS_PI();
+ generate_TM();
+}
+
+
+
+
+//######################################################################
+//# Automatically generate the FSM from the generator matrix
+//# of a (n,k) binary convolutional code
+//######################################################################
+fsm::fsm(int k, int n, const std::vector<int> &G)
+{
+
+ // calculate maximum memory requirements for each input stream
+ std::vector<int> max_mem_x(k,-1);
+ int max_mem = -1;
+ for(int i=0;i<k;i++) {
+ for(int j=0;j<n;j++) {
+ int mem = -1;
+ if(G[i*n+j]!=0)
+ mem=(int)(log(G[i*n+j])/log(2.0));
+ if(mem>max_mem_x[i])
+ max_mem_x[i]=mem;
+ if(mem>max_mem)
+ max_mem=mem;
+ }
+ }
+
+//printf("max_mem_x\n");
+//for(int j=0;j<max_mem_x.size();j++) printf("%d ",max_mem_x[j]); printf("\n");
+
+ // calculate total memory requirements to set S
+ int sum_max_mem = 0;
+ for(int i=0;i<k;i++)
+ sum_max_mem += max_mem_x[i];
+
+//printf("sum_max_mem = %d\n",sum_max_mem);
+
+ d_I=1<<k;
+ d_S=1<<sum_max_mem;
+ d_O=1<<n;
+
+ // binary representation of the G matrix
+ std::vector<std::vector<int> > Gb(k*n);
+ for(int j=0;j<k*n;j++) {
+ Gb[j].resize(max_mem+1);
+ dec2base(G[j],2,Gb[j]);
+//printf("Gb\n");
+//for(int m=0;m<Gb[j].size();m++) printf("%d ",Gb[j][m]); printf("\n");
+ }
+
+ // alphabet size of each shift register
+ std::vector<int> bases_x(k);
+ for(int j=0;j<k ;j++)
+ bases_x[j] = 1 << max_mem_x[j];
+//printf("bases_x\n");
+//for(int j=0;j<max_mem_x.size();j++) printf("%d ",max_mem_x[j]); printf("\n");
+
+ d_NS.resize(d_I*d_S);
+ d_OS.resize(d_I*d_S);
+
+ std::vector<int> sx(k);
+ std::vector<int> nsx(k);
+ std::vector<int> tx(k);
+ std::vector<std::vector<int> > tb(k);
+ for(int j=0;j<k;j++)
+ tb[j].resize(max_mem+1);
+ std::vector<int> inb(k);
+ std::vector<int> outb(n);
+
+
+ for(int s=0;s<d_S;s++) {
+ dec2bases(s,bases_x,sx); // split s into k values, each representing on of the k shift registers
+//printf("state = %d \nstates = ",s);
+//for(int j=0;j<sx.size();j++) printf("%d ",sx[j]); printf("\n");
+ for(int i=0;i<d_I;i++) {
+ dec2base(i,2,inb); // input in binary
+//printf("input = %d \ninputs = ",i);
+//for(int j=0;j<inb.size();j++) printf("%d ",inb[j]); printf("\n");
+
+ // evaluate next state
+ for(int j=0;j<k;j++)
+ nsx[j] = (inb[j]*bases_x[j]+sx[j])/2; // next state (for each shift register) MSB first
+ d_NS[s*d_I+i]=bases2dec(nsx,bases_x); // collect all values into the new state
+
+ // evaluate transitions
+ for(int j=0;j<k;j++)
+ tx[j] = inb[j]*bases_x[j]+sx[j]; // transition (for each shift register)MSB first
+ for(int j=0;j<k;j++) {
+ dec2base(tx[j],2,tb[j]); // transition in binary
+//printf("transition = %d \ntransitions = ",tx[j]);
+//for(int m=0;m<tb[j].size();m++) printf("%d ",tb[j][m]); printf("\n");
+ }
+
+ // evaluate outputs
+ for(int nn=0;nn<n;nn++) {
+ outb[nn] = 0;
+ for(int j=0;j<k;j++) {
+ for(int m=0;m<max_mem+1;m++)
+ outb[nn] = (outb[nn] + Gb[j*n+nn][m]*tb[j][m]) % 2; // careful: polynomial 1+D ir represented as 110, not as 011
+//printf("output %d equals %d\n",nn,outb[nn]);
+ }
+ }
+ d_OS[s*d_I+i] = base2dec(outb,2);
+ }
+ }
+
+ generate_PS_PI();
+ generate_TM();
+}
+
+
+
+
+//######################################################################
+//# Automatically generate an FSM specification describing the
+//# ISI for a channel
+//# of length ch_length and a modulation of size mod_size
+//######################################################################
+fsm::fsm(int mod_size, int ch_length)
+{
+ d_I=mod_size;
+ d_S=(int) (pow(1.0*d_I,1.0*ch_length-1)+0.5);
+ d_O=d_S*d_I;
+
+ d_NS.resize(d_I*d_S);
+ d_OS.resize(d_I*d_S);
+
+ for(int s=0;s<d_S;s++) {
+ for(int i=0;i<d_I;i++) {
+ int t=i*d_S+s;
+ d_NS[s*d_I+i] = t/d_I;
+ d_OS[s*d_I+i] = t;
+ }
+ }
+
+ generate_PS_PI();
+ generate_TM();
+}
+
+
+//######################################################################
+//# generate the PS and PI tables for later use
+//######################################################################
+void fsm::generate_PS_PI()
+{
+ d_PS.resize(d_I*d_S);
+ d_PI.resize(d_I*d_S);
+
+ for(int i=0;i<d_S;i++) {
+ int j=0;
+ for(int ii=0;ii<d_S;ii++) for(int jj=0;jj<d_I;jj++) {
+ if(d_NS[ii*d_I+jj]!=i) continue;
+ d_PS[i*d_I+j]=ii;
+ d_PI[i*d_I+j]=jj;
+ j++;
+ }
+ }
+}
+
+
+//######################################################################
+//# generate the termination matrices TMl and TMi for later use
+//######################################################################
+void fsm::generate_TM()
+{
+ d_TMi.resize(d_S*d_S);
+ d_TMl.resize(d_S*d_S);
+
+ for(int i=0;i<d_S*d_S;i++) {
+ d_TMi[i] = -1; // no meaning
+ d_TMl[i] = d_S; //infinity: you need at most S-1 steps
+ if (i/d_S == i%d_S)
+ d_TMl[i] = 0;
+ }
+
+ for(int s=0;s<d_S;s++) {
+ bool done = false;
+ int attempts = 0;
+ while (done == false && attempts < d_S-1) {
+ done = find_es(s);
+ attempts ++;
+ }
+ if (done == false)
+ //throw std::runtime_error ("fsm::generate_TM(): FSM appears to be disconnected\n");
+ printf("fsm::generate_TM(): FSM appears to be disconnected\n");
+ }
+}
+
+
+// find a path from any state to the ending state "es"
+bool fsm::find_es(int es)
+{
+ bool done = true;
+ for(int s=0;s<d_S;s++) {
+ if(d_TMl[s*d_S+es] < d_S)
+ continue;
+ int minl=d_S;
+ int mini=-1;
+ for(int i=0;i<d_I;i++) {
+ if( 1 + d_TMl[d_NS[s*d_I+i]*d_S+es] < minl) {
+ minl = 1 + d_TMl[d_NS[s*d_I+i]*d_S+es];
+ mini = i;
+ }
+ }
+ if (mini != -1) {
+ d_TMl[s*d_S+es]=minl;
+ d_TMi[s*d_S+es]=mini;
+ }
+ else
+ done = false;
+ }
+ return done;
+}
+
+
+
+
+
+
+
+
+
+
+
+
-/* -*- c++ -*- */\r
-/*\r
- * Copyright 2002 Free Software Foundation, Inc.\r
- *\r
- * This file is part of GNU Radio\r
- *\r
- * GNU Radio is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2, or (at your option)\r
- * any later version.\r
- *\r
- * GNU Radio is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GNU Radio; see the file COPYING. If not, write to\r
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
- * Boston, MA 02111-1307, USA.\r
- */\r
-\r
-#ifndef INCLUDED_TRELLIS_FSM_H\r
-#define INCLUDED_TRELLIS_FSM_H\r
-\r
-#include <vector>\r
-\r
-/*!\r
- * \brief FSM class\r
- */\r
-class fsm {\r
-private:\r
- int d_I;\r
- int d_S;\r
- int d_O;\r
- std::vector<int> d_NS;\r
- std::vector<int> d_OS;\r
- std::vector<int> d_PS;\r
- std::vector<int> d_PI;\r
- std::vector<int> d_TMi;\r
- std::vector<int> d_TMl;\r
- void generate_PS_PI ();\r
- void generate_TM ();\r
- bool find_es(int es);\r
-public:\r
- fsm();\r
- fsm(const fsm &FSM);\r
- fsm(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS);\r
- fsm(const char *name);\r
- fsm(int k, int n, const std::vector<int> &G);\r
- fsm(int mod_size, int ch_length);\r
- int I () const { return d_I; }\r
- int S () const { return d_S; }\r
- int O () const { return d_O; }\r
- const std::vector<int> & NS () const { return d_NS; }\r
- const std::vector<int> & OS () const { return d_OS; }\r
- const std::vector<int> & PS () const { return d_PS; }\r
- const std::vector<int> & PI () const { return d_PI; }\r
- const std::vector<int> & TMi () const { return d_TMi; }\r
- const std::vector<int> & TMl () const { return d_TMl; }\r
-};\r
-\r
-#endif\r
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_TRELLIS_FSM_H
+#define INCLUDED_TRELLIS_FSM_H
+
+#include <vector>
+
+/*!
+ * \brief FSM class
+ */
+class fsm {
+private:
+ int d_I;
+ int d_S;
+ int d_O;
+ std::vector<int> d_NS;
+ std::vector<int> d_OS;
+ std::vector<int> d_PS;
+ std::vector<int> d_PI;
+ std::vector<int> d_TMi;
+ std::vector<int> d_TMl;
+ void generate_PS_PI ();
+ void generate_TM ();
+ bool find_es(int es);
+public:
+ fsm();
+ fsm(const fsm &FSM);
+ fsm(int I, int S, int O, const std::vector<int> &NS, const std::vector<int> &OS);
+ fsm(const char *name);
+ fsm(int k, int n, const std::vector<int> &G);
+ fsm(int mod_size, int ch_length);
+ int I () const { return d_I; }
+ int S () const { return d_S; }
+ int O () const { return d_O; }
+ const std::vector<int> & NS () const { return d_NS; }
+ const std::vector<int> & OS () const { return d_OS; }
+ const std::vector<int> & PS () const { return d_PS; }
+ const std::vector<int> & PI () const { return d_PI; }
+ const std::vector<int> & TMi () const { return d_TMi; }
+ const std::vector<int> & TMl () const { return d_TMl; }
+};
+
+#endif
-/* -*- c++ -*- */\r
-/*\r
- * Copyright 2002 Free Software Foundation, Inc.\r
- *\r
- * This file is part of GNU Radio\r
- *\r
- * GNU Radio is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2, or (at your option)\r
- * any later version.\r
- *\r
- * GNU Radio is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GNU Radio; see the file COPYING. If not, write to\r
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
- * Boston, MA 02111-1307, USA.\r
- */\r
-\r
-#include <cstdlib> \r
-#include <cstdio>\r
-#include <iostream>\r
-#include <stdexcept>\r
-#include <cmath>\r
-#include "quicksort_index.h"\r
-#include "interleaver.h"\r
-\r
-interleaver::interleaver()\r
-{\r
- d_K=0;\r
- d_INTER.resize(0);\r
- d_DEINTER.resize(0);\r
-}\r
-\r
-interleaver::interleaver(const interleaver &INTERLEAVER)\r
-{\r
- d_K=INTERLEAVER.K();\r
- d_INTER=INTERLEAVER.INTER();\r
- d_DEINTER=INTERLEAVER.DEINTER();\r
-}\r
-\r
-interleaver::interleaver(int K, const std::vector<int> &INTER)\r
-{\r
- d_K=K;\r
- d_INTER=INTER;\r
- d_DEINTER.resize(d_K);\r
- \r
- // generate DEINTER table\r
- for(int i=0;i<d_K;i++) {\r
- d_DEINTER[d_INTER[i]]=i;\r
- }\r
-}\r
-\r
-//######################################################################\r
-//# Read an INTERLEAVER specification from a file.\r
-//# Format (hopefully will become more flexible in the future...):\r
-//# K\r
-//# blank line\r
-//# list of space separated K integers from 0 to K-1 in appropriate order\r
-//# optional comments\r
-//######################################################################\r
-interleaver::interleaver(const char *name) \r
-{\r
- FILE *interleaverfile;\r
-\r
- if((interleaverfile=fopen(name,"r"))==NULL) \r
- throw std::runtime_error ("file open error in interleaver()");\r
- //printf("file open error in interleaver()\n");\r
- \r
- fscanf(interleaverfile,"%d\n",&d_K);\r
- d_INTER.resize(d_K);\r
- d_DEINTER.resize(d_K);\r
-\r
- for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));\r
- \r
- // generate DEINTER table\r
- for(int i=0;i<d_K;i++) {\r
- d_DEINTER[d_INTER[i]]=i;\r
- }\r
-}\r
-\r
-//######################################################################\r
-//# Generate a random interleaver\r
-//######################################################################\r
-interleaver::interleaver(int K, unsigned int seed)\r
-{\r
- d_K=K;\r
- d_INTER.resize(d_K);\r
- d_DEINTER.resize(d_K);\r
-\r
- srand(seed); \r
- std::vector<int> tmp(d_K);\r
- for(int i=0;i<d_K;i++) {\r
- d_INTER[i]=i;\r
- tmp[i] = rand(); \r
- }\r
- //quicksort_index <int> (tmp,d_INTER,0,d_K-1); got to resolve this...\r
- quicksort_index1 (tmp,d_INTER,0,d_K-1);\r
-\r
- // generate DEINTER table\r
- for(int i=0;i<d_K;i++) {\r
- d_DEINTER[d_INTER[i]]=i;\r
- }\r
-}\r
-\r
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <cstdlib>
+#include <cstdio>
+#include <iostream>
+#include <stdexcept>
+#include <cmath>
+#include "quicksort_index.h"
+#include "interleaver.h"
+
+interleaver::interleaver()
+{
+ d_K=0;
+ d_INTER.resize(0);
+ d_DEINTER.resize(0);
+}
+
+interleaver::interleaver(const interleaver &INTERLEAVER)
+{
+ d_K=INTERLEAVER.K();
+ d_INTER=INTERLEAVER.INTER();
+ d_DEINTER=INTERLEAVER.DEINTER();
+}
+
+interleaver::interleaver(int K, const std::vector<int> &INTER)
+{
+ d_K=K;
+ d_INTER=INTER;
+ d_DEINTER.resize(d_K);
+
+ // generate DEINTER table
+ for(int i=0;i<d_K;i++) {
+ d_DEINTER[d_INTER[i]]=i;
+ }
+}
+
+//######################################################################
+//# Read an INTERLEAVER specification from a file.
+//# Format (hopefully will become more flexible in the future...):
+//# K
+//# blank line
+//# list of space separated K integers from 0 to K-1 in appropriate order
+//# optional comments
+//######################################################################
+interleaver::interleaver(const char *name)
+{
+ FILE *interleaverfile;
+
+ if((interleaverfile=fopen(name,"r"))==NULL)
+ throw std::runtime_error ("file open error in interleaver()");
+ //printf("file open error in interleaver()\n");
+
+ fscanf(interleaverfile,"%d\n",&d_K);
+ d_INTER.resize(d_K);
+ d_DEINTER.resize(d_K);
+
+ for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));
+
+ // generate DEINTER table
+ for(int i=0;i<d_K;i++) {
+ d_DEINTER[d_INTER[i]]=i;
+ }
+}
+
+//######################################################################
+//# Generate a random interleaver
+//######################################################################
+interleaver::interleaver(int K, unsigned int seed)
+{
+ d_K=K;
+ d_INTER.resize(d_K);
+ d_DEINTER.resize(d_K);
+
+ srand(seed);
+ std::vector<int> tmp(d_K);
+ for(int i=0;i<d_K;i++) {
+ d_INTER[i]=i;
+ tmp[i] = rand();
+ }
+ //quicksort_index <int> (tmp,d_INTER,0,d_K-1); got to resolve this...
+ quicksort_index1 (tmp,d_INTER,0,d_K-1);
+
+ // generate DEINTER table
+ for(int i=0;i<d_K;i++) {
+ d_DEINTER[d_INTER[i]]=i;
+ }
+}
+
-/* -*- c++ -*- */\r
-/*\r
- * Copyright 2002 Free Software Foundation, Inc.\r
- *\r
- * This file is part of GNU Radio\r
- *\r
- * GNU Radio is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2, or (at your option)\r
- * any later version.\r
- *\r
- * GNU Radio is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GNU Radio; see the file COPYING. If not, write to\r
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\r
- * Boston, MA 02111-1307, USA.\r
- */\r
-\r
-#ifndef INCLUDED_TRELLIS_INTERLEAVER_H\r
-#define INCLUDED_TRELLIS_INTERLEAVER_H\r
-\r
-#include <vector>\r
-\r
-/*!\r
- * \brief INTERLEAVER class\r
- */\r
-class interleaver {\r
-private:\r
- int d_K;\r
- std::vector<int> d_INTER;\r
- std::vector<int> d_DEINTER;\r
-public:\r
- interleaver();\r
- interleaver(const interleaver & INTERLEAVER);\r
- interleaver(int K, const std::vector<int> & INTER);\r
- interleaver(const char *name);\r
- interleaver(int K, unsigned int seed);\r
- int K () const { return d_K; }\r
- const std::vector<int> & INTER () const { return d_INTER; }\r
- const std::vector<int> & DEINTER () const { return d_DEINTER; }\r
-};\r
-\r
-#endif\r
+/* -*- c++ -*- */
+/*
+ * Copyright 2002 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef INCLUDED_TRELLIS_INTERLEAVER_H
+#define INCLUDED_TRELLIS_INTERLEAVER_H
+
+#include <vector>
+
+/*!
+ * \brief INTERLEAVER class
+ */
+class interleaver {
+private:
+ int d_K;
+ std::vector<int> d_INTER;
+ std::vector<int> d_DEINTER;
+public:
+ interleaver();
+ interleaver(const interleaver & INTERLEAVER);
+ interleaver(int K, const std::vector<int> & INTER);
+ interleaver(const char *name);
+ interleaver(int K, unsigned int seed);
+ int K () const { return d_K; }
+ const std::vector<int> & INTER () const { return d_INTER; }
+ const std::vector<int> & DEINTER () const { return d_DEINTER; }
+};
+
+#endif