00001 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 #ifndef DECODER_HEADER
00029 #define DECODER_HEADER
00030 
00031 #include <iostream>
00032 #include <string>
00033 #include <complex>
00034 #include <memory>
00035 
00036 #include <misc.h>
00037 #include <signals.h>
00038 #include <basicdevice.h>
00039 
00040 #include "viterbi.h"
00041 #include "trellis.h"
00042 #include "trellisdecoding.h"
00043 
00044 
00045 
00046 namespace simthlib{ 
00047 
00048 class Decoder;
00049 class Encoder;
00050 
00051 
00052 std::ostream& operator<<(std::ostream &os, const Decoder &cod);
00053 
00054 
00060 class Decoder : public simth::Device
00061 {
00062   private:
00063 
00064     simth::SequenceType inputType_;
00065 
00066   protected:
00067 
00068     simth::SequenceType inputType() const {return inputType_;}
00069 
00070   public:
00071     Decoder(int deviceID, simth::DeviceSystemIntf* system,
00072         const simth::PropertyList& pl, 
00073         simth::SequenceType inType);
00074 
00077     virtual ~Decoder(){};
00078 
00081     virtual void decode(const simth::BitSeq &bsin,simth::BitSeq& bsout) = 0;
00082 
00083 
00084 
00089     virtual void decode(const simth::LlvSeq &llv, simth::BitSeq& bsout) = 0;
00090 
00095     virtual void decode(const simth::LlrSeq &llr, simth::BitSeq& bsout) = 0;
00096 
00102     virtual int getDataLength(int codedLength) const =0;
00103 
00109     virtual int getCodeLength(int rawLength) const =0;
00110 
00114     virtual void process();
00115 
00116     
00117     
00118     virtual void print(std::ostream &os) const;
00119 
00120     static void init(const std::string& fileName, simth::Device** dev, simth::DeviceSystemIntf* sysPtr, int ID,
00121                  const std::string& regionQualifier = "");
00122 
00125     void startOfSimulation();
00126 };
00127 
00128 
00129 
00130 
00131 
00132 
00139 class StreamDecoder : public Decoder
00140 {
00141 
00142   public:
00143 
00144     StreamDecoder(int deviceID, simth::DeviceSystemIntf* system,
00145           const simth::PropertyList& pl, 
00146           simth::SequenceType inType);
00147 
00152     virtual int dataBitsPerStep() const = 0;
00157     virtual int codedBitsPerStep() const = 0;
00158 
00170     virtual void process();
00171   
00172     virtual void updateInputLengths();
00173     virtual void updateOutputLengths();
00174 
00175   protected:
00176     
00177     
00178     
00179     size_t llrInputLength;
00180 };
00181 
00182 
00190 class TrellisDecoder : public StreamDecoder
00191 {
00192   private:
00193 
00194     TrellisDecodingAlgorithm* usedAlgorithm;
00195 
00196   protected:
00197 
00198   public:
00199 
00207     TrellisDecoder(int deviceID, simth::DeviceSystemIntf* system,
00208            const simth::PropertyList& pl, 
00209            std::auto_ptr<TrellisDecodingAlgorithm> algorithm_ptr,
00210                    simth::SequenceType inType);
00211                    
00212     virtual ~TrellisDecoder();
00213 
00214     
00215     virtual void decode(const simth::BitSeq & bsin, simth::BitSeq& bsout);
00216 
00217     
00218 
00219 
00220     virtual void decode(const simth::LlvSeq &llv, simth::BitSeq& bsout);
00221 
00222     
00223 
00224 
00225     virtual void decode(const simth::LlrSeq &llr, simth::BitSeq& bsout);
00226 
00227 
00228     
00229 
00230 
00231 
00232     virtual int getDataLength(int codedLength) const;
00233 
00234     
00235 
00236 
00237     virtual int getCodeLength(int rawLength) const;
00238 
00243     virtual int dataBitsPerStep() const {return usedAlgorithm->trellis()->numInbits();}
00248     virtual int codedBitsPerStep() const {return usedAlgorithm->trellis()->numOutbits();}
00249 
00250 
00251     
00252 
00253 
00254 
00255     virtual void print(std::ostream &os) const;
00256 };
00257 
00258 inline int TrellisDecoder::getCodeLength(int rawLength) const
00259 {
00260   return usedAlgorithm->trellis()->getCodeLength(rawLength);
00261 }
00262 
00263 
00264 inline int TrellisDecoder::getDataLength(int codeLength) const
00265 {
00266   return usedAlgorithm->trellis()->getDataLength(codeLength);
00267 }
00268 
00269 
00270 
00283 class ConvDecoder : public TrellisDecoder
00284 {
00285 
00286    public:
00287       
00314       ConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00315           const simth::PropertyList& pl, 
00316           int mem, int inbits, int outbits, 
00317           simth::SequenceType inType,
00318           trellisdecoding::DecodingAlgorithmMode decodingMode);
00319 
00325       ConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00326           const simth::PropertyList& pl, 
00327           int inSymbolsPerStep, 
00328           const simth::checkedVector<int>& polynomials, 
00329           simth::SequenceType inType,
00330           trellisdecoding::DecodingAlgorithmMode decodingMode);
00331 
00335       ConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00336           const simth::PropertyList& pl, 
00337           int inSymbolsPerStep, 
00338           const simth::checkedVector<int>& polynomials, 
00339           int recursivePolynomial, bool systematic,
00340           simth::SequenceType inType, 
00341           trellisdecoding::DecodingAlgorithmMode decodingMode);
00342 
00347       ConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00348           const simth::PropertyList& pl);
00349                 
00354       ConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00355           const simth::PropertyList& pl, 
00356           int inSymbolsPerStep, int bitsPerSymbol, 
00357           ConvCodeTrellis::StartingMode startingMode, 
00358           map_type mappMode, 
00359           const simth::checkedVector<int>& polynomials, 
00360           int recursivePolynomial, bool systematic,
00361           simth::SequenceType inType,
00362           trellisdecoding::DecodingAlgorithmMode decodingMode);
00363                 
00364 };
00365 
00366 
00367 class Puncturing;
00368 
00377 class PunctConvDecoder : public TrellisDecoder
00378 {
00379   private:
00380 
00381   protected:
00382   
00383     Puncturing* usedPuncturing;
00384 
00385   public:
00386 
00398     PunctConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00399              const simth::PropertyList& pl, 
00400              int codeRateNumerator,
00401              int codeRateDenumerator, 
00402              int mem, 
00403              int inbits, 
00404              int outbits);
00405 
00406 
00407     PunctConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00408              const simth::PropertyList& pl, 
00409              int codeRateNumerator, 
00410              int codeRateDenumerator, int inbitsPerStep,
00411                      const simth::checkedVector<int>& polynomials,
00412                      const int recursivePolynomial, bool systematic);
00413 
00415     PunctConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00416              const simth::PropertyList& pl);
00417 
00418     PunctConvDecoder(int deviceID, simth::DeviceSystemIntf* system,
00419              const simth::PropertyList& pl, 
00420              const std::string& puncturingPattern, int inbitsPerStep,
00421                      const simth::checkedVector<int>& polynomials,
00422                      const int recursivePolynomial, bool systematic);
00423 
00424     virtual ~PunctConvDecoder();
00425 
00426 
00427     virtual void updateInputLengths();
00428     virtual void updateOutputLengths();
00429 
00430 
00431     
00432 
00433 
00434     virtual int getDataLength(int codedLength) const;
00435 
00436     
00437 
00438 
00439     virtual int getCodeLength(int rawLength) const;
00440 
00443     virtual void decode(const simth::LlrSeq &llr, simth::BitSeq& bsout);
00444 
00445     
00446     virtual void decode(const simth::BitSeq & bsin, simth::BitSeq& bsout);
00447 
00448     
00449     virtual void decode(const simth::LlvSeq &llv, simth::BitSeq& bsout);
00450 
00451     void setPuncturing(const std::string& newPuncturePattern);
00452 };
00453 
00454 
00455 }
00456 
00457 #endif