libwireless 源碼解析

libwireless 源碼的解析,擴展 和 使用

注:工程主體部分採用了抽象工廠模式,我們按照工程目錄的結構,自頂向下地分析代碼

源碼可以在 Jonathan Perry 的 github 上面下載:https://github.com/yonch/wireless

代碼在Ubuntu14.04版本上面的安裝步驟可參考:http://blog.csdn.net/baobao3456810/article/details/50955788


1 python

說明:頂層 python 代碼

1.1 python/codes

說明:只有 python 版本的 Spinal Codes ,C++版本的 Spinal Codes 以工廠的形式呈現

1.2 python/protocols

說明:protocol 共包括,
1 Spinal Codes 的 protocol(C++)
2 One Try protocol(C++)
3 Multiple Try protocol(Python)
4 Rate Approximate protocol(C++)

文件包含:
protocols/MultipleTryProtocol.pypython/simulator/factories/ProtocolFactory.py的第三種

1.3 python/simulator

說明:抽象工廠,根據給定的參數構造具體工廠,各個具體工廠根據參數生產具體產品

文件包含:
simulator/factories 給出了一些具體的工廠,包括:

  • Channel_Factory
  • Demap_Factory
  • Detector_Factory
  • Map_Factory
  • PacketGen_Factory
  • Protocol_Factory:除了 Spinal Codes 外所使用的 protocol
  • Statistics_Factory:調用 python/statistics 中的內容
  • Codes_Factory: 包含幾種信道編碼的具體工廠,下面詳細展開

simulator/factories/codes/*.py 給出了幾種信道編碼的具體工廠,包括:

  • Fading_Strider_Factory
  • LDPC_Factory
  • LT_Factory
  • Multiplexed_Factory
  • Null_Factory
  • Raptor_Factory
  • Spinal_Factory

    • public:
      • make_encoder:最終返回 MultiToSingleStreamEncoder 構造的編碼器,以及符號數組類型,如 wireless.vectorus=vector< unsigned short>=16-bit
      • make_decoder
      • make_protocol
    • private:

      圍繞着include/codes/spinal/CodeFactory.h 的編譯碼的實現,其中的三個模塊是相互遞進的關係。
      CodeFactory 爲Spinal編譯碼的主工廠,返回一種具體的哈希函數編碼方案,包括:salsa,lookup3,oneAtATime。
      IEncoderFactory Spinal 信道選擇工廠,返回針對特定信道下的編碼方案,包括:linear,soft,gaussian,bitwise,coherence。
      ISearchFactory Spinal 譯碼算法選擇工廠,在樓上的基礎上選擇一種譯碼方案,包括:beamDecoder,lookaheadBeamDecoder,並返回譯碼器和信道符號類型。

      • _make_unpunctured_encoder:選擇一種哈希編碼方案,使用CodeFactory.encoder()方法構造編碼器。
      • _make_unpunctured_decoder:選擇一種信道模式,以及譯碼算法(regular,lookahead,parallel)
      • _get_punctured_decoder_type:返回與信道對應打孔後的符號類型,使用了MultiToSingleStreamDecoder類,符號的表示不清楚可以參考bindings/codes/codes.i 的類型的重命名(即python與C++版本的對應關係)
      • _get_num_blocks:=n/k
      • _get_puncturing:選擇一種打孔機制(8-way-v2,static),以及是否要重複打孔(encoderToSymbolRate)
  • Strider_Factory
  • Turbo_Factory

simulator/default_configuration.py 返回一個列表,爲仿真組建提供了可以訪問的工廠,參考 simulator/factories/ 中實現的工廠。
simulator/FactoryCollection.py 工廠類,使仿真組建可以聚合多個具體工廠,也就是生產工廠的工廠

  • self._factories:字典,Key=’make_pre_packet_manipulator’, ‘make_packet_generator’, ‘make_encoder’, ‘make_mapper’, ‘make_channel’, ‘make_demapper’, ‘make_decoder’, ‘make_detector’, make_protocol’, ‘make_statistics’,Value=[defaulte_configuration中工廠類中所有名爲 Key 值的工廠方法]
  • self._cache:字典,Key同上,Value爲一個元組(工廠方法的參數,工廠方法返回的值“產品”)
  • add_factory(self, factory):輸入 factory 爲 defaulte_configuration 的 get_factory_list() 方法返回的各種工廠之一(如 ChannelFactory),功能是爲 _factories 添加 Value
  • make(self, func_name, *args):需要注意的是,工廠方法接收到“不認識”的參數時,會返回None,遍歷_factories[某工廠方法名],即同名的所有方法,當參數不滿足時返回None,也就是說只要傳給工廠方法的參數滿足某個工廠方法的輸入要求,就會返回該工廠的“產品”

simulator/SanityTest.py 包含了多個測試程序,配合 simulator/Simlator.py 使用,包括:

  • Spinal Codes:

    • run_Test:random packet,spinal,linear map,AWGN,no demap,regular beamSearch decode,oracle detect,sequential protocol,errors statistics
    • run_ParallelK_Test:parallel k beamSearch decode,其他同“1”
    • run_Coherence_FadingTest:soft map,coherence-fading channel,其他同“1”
    • run_Rate_Approx_ProtocolTest:rate-approx protocol,其他同“1”
    • run_Gaussian_Test:trunc-norm-v2 map,其他同“1”
    • run_Lookahead_Test:lookahead decode,其他同“1”
    • run_Crc_Test:crc16 packet,crc16 detector,其他同“1”
    • run_First_Error_Statistics_Test:first-error,其他同“1”
  • LDPC:

    • run_LDPC_Test:random packet,ldpc,gray map,AWGN,ml-gray demap,ldpc-float-bp decode,oracle detector,one-try protocol,errors statistics
    • run_Itpp_Qam_LDPC_Test:QAM map,AWGN_c(),QAM demap,其他同“2”
    • run_Bsc_LDPC_Test:linear map,BSC,BSC demap,其他同“2”
  • Turbo:

    • run_Itpp_Qam_Turbo_Test:random packet,Turbo,AWGN_c,QAM map,regular demap,oracle detector,one-try protocol,errors statistics
  • LT codes

    • run_LT_Test:random packet,LT codes,QAM map,AWGN_c,LT decode,oracle detector,rate-approx protocol,errors statistics
  • Raptor codes

    • run_Raptor_Test:raptor codes,raptor decode,其他同“3”
  • Strider codes

    • run_Strider_Test:strider codes,null map,null demap,strider decode,multiple-try protocol,其他同“3”
    • run_Short_Strider_Test:與上面長度不同
    • run_Strider_Transparent_Fading_Test:transparent-coherence_c channel,其他同上strider
    • run_Strider_Fading_Test:coherence-fading_c channel,strider-fading decode,其他同上
  • Null 無編碼

    • run_Null_Decoder_Test:random packet,null code,AWGN_c,QAM map,null decode,oracle detector,one-try protocol,errors statistics

simulator/Simulator.py 具體類,實現了一個完整的數據包的發送過程,適用於所有的編碼方案,包括:

  • getComponents (experiment): 由 exper_spec 給出的參數方案 make 組件(由工廠生產產品)
  • seed (seed): 爲用到 random 的組件的提供“種子”
  • runPacket (): 針對單個數據包 模擬傳輸機制,當統計結果中 isFinish==True 或者 nextNumChannelSymbols == 0 時,停止對當前數據包的發送,轉向下一個數據包。
  • runExperiment(experiment, initialSeed, numPackets): 運行實驗的過程

1.4 python/statistics

說明:給出收集統計信息的方式,Jonathan實現了三種方式,這裏給出的是python實現,被 StatisticsFactory() 工廠類調用
三種統計方式的區別還有待於研究

文件包含:
statistics/ErrorLocationStatistics.py :對應 StatisticsFactory 中的 bit-statistics 模式。Collected statistics on location of errors

  • ErrorLocationStatisticsResult:(被下者調用的):記錄單條信息的錯誤模式(error pattern)
  • ErrorLocationStatistics(被工廠使用的):在譯碼結束時記錄統計信息,並統計錯誤出現次數

statistics/ErrorRateStatistics.py :對應 StatisticsFactory 中的 error 模式。Collected statistics on number of errors

  • Error_Rate_Statistics_Result(被下者調用的):針對某一個 packet,將譯碼後的 packet 與發送的 packet 做比較,統計當前 packet 的譯碼正確率
  • Error_Rate_Statistics(被工廠使用的):在譯碼結束時記錄統計信息,並統計錯誤出現次數

statistics/FirstErrorStatistics.py:對應 StatisticsFactory 中的 first-error 模式。 Collected statistics on bit-index of first bit error ,包括以下幾類:

  • First_Error_Statistics_Result(被下者調用的):記錄單條信息的錯誤模式(error pattern)
  • First_Error_Statistics(被工廠使用的):在譯碼結束時記錄統計信息,並統計錯誤出現次數

1.5 python/util

說明:Google Protocol Buffer,

util/serialization/results.proto 不太明確,只知道被ErrorRateStatistics.py 調用


2 bindings

說明:python API from C++,在閱讀或修改 binding 代碼時最好對應着 ./include 中的內容
補充:在 SWIG 中,不是所有頭文件以及輔助文件中被包含的模塊都要封裝到 binding codes 中,所以在 SWIG 中使用 %include 來導入模塊,且 %include 的內容在預編譯時只編譯一次,同時把不需要預編譯的模塊放入 %{ ... %} 中。
注意:該工程中多處定義了各種不同功能的智能指針,這些將留在指針的定義中詳細介紹,SWIG 使用只能指針的方法是 %shared_ptr(T) ;另外,binding 中的所有註釋有 numpy 的地方請見 Numpy.i SWIG 文檔

2.1 bindings/codes

說明:顧名思義,該模塊實現了幾種仿真需要的信道編碼的 Python 接口

codes/spinal

  • codes/spinal/spinal.i :實現了 include/codes/spinal 中的模塊的接口

codes/codes_workaround.i :輔助下面的 codes.i
codes/codes.i 封裝幾乎所有跟差錯控制編碼有關的智能指針,幷包含 include/codes 中所有跟代碼有關的功能模塊,如 編碼指針/解碼指針/打孔/碼流控制 等

codes/fountain.i 封裝了 LT 碼 和 Raptor 碼 相關的模塊和智能指針,對應 include/codes/fountain

codes/ldpc.i 封裝了LDPC模塊,對應 include/codes/ldpc
codes/null.i 對應 include/codes/null ,無編碼
codes/strider.i 封裝了 strider 模塊,對應 include/codes/strider
codes/turbo.i 封裝了 turbo 模塊,對應 include/codes/turbo

2.2 bindings/itpp

說明:雖然 IT++ 中實現了大部分通信仿真所需要的功能,但該工程中並沒有使用 IT++ 中的規則,而只是使用了 IT++ 中個別的模塊,詳細請見下文

包括:

  • base_sparse.i
  • base_vec.i
  • ldpc.i
  • llr.i
  • modulator.i

2.3 bindings/util

說明:對應實現了include/util/ 中的部分模塊的接口

包括:(基本與 include 目錄下的模塊對應,詳細功能去 include 中查找)

  • config.i
  • hashes.i
  • inference.i

2.4 bindings/*.i

bindings/numpy.i :binding 的節頭注意中有表述

bindings/common.i 包括 Exception handling,numpy,Smart pointers,SWIG 對 exception 和 Smart pointers 有相應的擴展,故這裏可以直接 %include,另外若要了解 SWIG 使用 shared_ptr 的詳細用法請參考 SWIG 的官方文檔,簡單地說就是定義一個宏變量,幷包含 %include < std_shared_ptr.i>,至於 numpy.i 在前面介紹過

bindings/general.i :STL模板的實例化,以及數據類型的轉換,其中所使用到的模板的定義在C++聲明中,留意各個數據類型的定義即可,比較複雜,故這裏一一列出,以便查找

  • Symbol = int
  • SoftSymbol = float
  • N0_t = float
  • FadingMagnitude = float
  • LLRValue = float
  • ComplexSymbol = complex
  • FadingSymbol == FadingSymbolTuple< SoftSymbol>
  • FadingComplexSymbol == FadingSymbolTuple< ComplexSymbol>
  • vectori == vector< int>
  • vectorcf == vector< std::complex< float> >
  • vectorcd == vector< std::complex< double> >
  • vectorui == vector< unsigned int>
  • vectorus == vector< unsigned short>
  • vectors == vector< short>
  • vectorul == vector< unsigned long>
  • vectorull == vector< unsigned long long>
  • vectorb == vector< bool>
  • vectorf == vector< float>
  • vectorstr == vector< string>
  • vector_fadingsymbol == vector< FadingSymbol>
  • vector_fading_csymbol == vector< FadingComplexSymbol>
  • vector_csymbol = vectorcd
  • vector_symbol = vectori
  • vector_softsymbol = vectorf
  • vector_llr = vectorf

bindings/channels.i :主要包括 下面模塊(詳細請見代碼),比較複雜,故這裏一一列出,以便查找

  • SymbolAwgnChannel == AwgnChannel< Symbol>
  • ComplexAwgnChannel == AwgnChannel< ComplexSymbol>
  • SoftAwgnChannel == AwgnChannel< SoftSymbol>
  • FadingAwgnChannel == AwgnChannel< FadingSymbol>
  • FadingComplexAwgnChannel == AwgnChannel< FadingComplexSymbol>
  • SoftCoherenceFading == CoherenceFading< SoftSymbol>
  • ComplexCoherenceFading == CoherenceFading< ComplexSymbol>
  • MimoAwgnChannel == CompositeChannel< MimoChannel ,ComplexAwgnChannel>
  • AwgnCoherenceFadingChannel == CompositeChannel< SoftCoherenceFading, FadingAwgnChannel>
  • AwgnCoherenceComplexFadingChannel == CompositeChannel< ComplexCoherenceFading, FadingComplexAwgnChannel>
  • ComplexTransparentFadingChannel == TransparentCoherenceFading< ComplexSymbol>
  • SoftTransparentFadingChannel == TransparentCoherenceFading< SoftSymbol>
  • SymbolTransparentFadingChannel == TransparentCoherenceFading< Symbol>

bindings/mappers_workaround.i:輔助下面的 mappers.i ,但據觀察,下文並沒有包含這個文件

bindings/mappers.i:封裝了只能指針 IMapper,QPSKMapper,QamMapper,LinearMapper,幷包含了 include/mappers 中的內容

bindings/demappers_workaround.i:輔助下面的 demappers.i ,但據觀察,下文並沒有包含這個文件

bindings/demappers.i:包含了 include/mappers 中的部分內容,封裝並實例化了 IDemapper 智能指針,分別爲 template_IDemapper_Symbol,template_IDemapper_ComplexSymbol,GrayDemapper,ItppComplexDemapper

bindings/misc.i

bindings/protocols.i:實現了對應 include/protocol 中的模塊的接口,即 OneTryProtocol 和 RateApproxProtocol


3 include

說明:大部分功能模塊的聲明(.h),個別功能模塊的實現(.hh)。本人C++不是很好,只能先這樣理解,在這裏具體的類往往聲明和實現是分開的,而模板類中方法的實現是定義在模板類的聲明文件中

3.1 include/channels

AwgnChannel.h:實現了 AWGN 信道的仿真,其中 N0_t 爲 float 類型,名稱規則要與channel.i 一致

  • AwgnChannel(N0_t n0):定義噪聲的功率譜密度
  • void seed(unsigned int* const seed, int seedSize):所有的僞隨機數生成器都要有種子
  • void process(const std::vector& inSymbols, std::vector& outSymbols):將噪聲加到 inSymbols 上,生成 outSymbols
  • unsigned int forecast(unsigned int numOutputs):騙人的,沒實現啥
  • double getStddevPerDimension():返回噪聲的標準差
  • ChannelSymbol noisify(ChannelSymbol x, double stddevPerDimension):見AwgnNoiseGenerator.h
  • AwgnChannel.hhAwgnChannel.h 中方法的實現

AwgnNoiseGenerator.h:實現了將噪聲加到符號上
BscChannel.h:BSC 信道的仿真,結構跟 AWGN 差不多,但實現起來要簡單多了
CoherenceFading.h:瑞利衰減信道實現(接收端知道衰減係數

  • CoherenceFading.hh
  • CoherenceCoeffGenerator.h:可以根據相干時間計算衰減係數

TransparentCoherenceFading.h:瑞利衰減信道實現(接收端不知道衰減係數

  • TransparentCoherenceFading.hh

CompositeChannel.h:通過合併兩個信道成爲一個新的信道

  • CompositeChannel.hh

MimoChannel.h:MIMO 信道的仿真

3.2 include/codes

說明:該模塊給出了編碼器和譯碼器的實現結構,以及多種編碼譯碼方法(這裏用“方法”是爲了與util中的“算法想區分”),由於該部分是本工程的主體,故這裏對主要的類的組成結構也做詳細介紹,雖然只是把內容從代碼中摘出來,但這樣看起來對功能的理解會很有幫助。特別要注意的是虛基類的使用。

注意:代碼中的“I”開頭的類表示接口(interface),實現上都是採用虛基類,且與 shared_ptr 指針一同使用,下文不一一雷述。而我們使用的都是“非接口”模塊,所以對所有的模塊都要好好的理解。

另外,值得注意的是,對 Spinal Codes 來說,打孔(puncturing)的方法可能與傳統上有些差別,涉及到將一個碼流(Code Stream)分解(divide)爲多個子碼流,故這裏Jonathan(代碼作者)在包含打孔的編碼器和譯碼器的命名上採用 MultiStream××× 的形式,這裏爲了方便理解單獨指出。

include/codes/archive

說明: 顧名思義,編碼過程中的所有的內存管理。

  • CachedEncoder.h還有待於研究,繼承自 IEncoder,符號輸出前在 pass 中的內存管理類,以通道(passes)爲單位成批地生產編碼符號,代碼結構如下:
    • public:
      • CachedEncoder( Encoder encoder, unsigned int numPackets, unsigned int numCachedSymbolsPerPacket):指定編碼器,數據包的數量,每個 batch 中的符號數量
      • ~CachedEncoder()
      • void setPacket(unsigned int packetInd, const string& packet)
      • void removePacket(unsigned int packetInd):Removes the packet from the cache
      • bool hasPacket(unsigned int packetInd):True if packet exists, False otherwise.
      • void getSymbols( unsigned int packetInd, unsigned int firstSymbolToEmit, unsigned int lastSymbolToEmit, std::vector< Symbol>& outSymbols):從指定的 pass 中取出輸出符號到 outSymbol 中
    • private:
      • CachedEncoder(const CachedEncoder&)
      • CachedEncoder& operator=(const CachedEncoder&)
      • void getAndCacheSymbolBlock(unsigned int packetInd, unsigned int blockIndex):爲每個 symbol block 分配內存
      • Encoder m_encoder:指定的編碼器
      • unsigned int m_numPackets:實例所提供的數據包數量
      • unsigned int m_numCachedSymbolsPerPacket:每個數據包所分配的 cache 數量
      • vector< string> m_packets:待編碼的數據包,下面的成員數組中的序號應該是數據包的編號
      • vector< bool> m_hasPacket:是否指定了數據包
      • vector< int> m_cachedBlockIndex不是很明確,packet 的數量往往不是正好的,故有多少 cache 需要額外補償呢?
  • CachedEncoder.hh:樓上的實現
  • IMultiEncoder.h:虛基類,功能更多的 IEncoder,但大部分用的都是 IEncoder,結構如下:

    • virtual ~IMultiEncoder() {}
    • virtual void setPacket(unsigned int packetInd, const std::string& packet) = 0
    • virtual void removePacket(unsigned int packetInd) = 0
    • virtual bool hasPacket(unsigned int packetInd) = 0
    • virtual void encode( unsigned int packetInd, unsigned int numSymbols, std::vector< uint16_t>& outSymbols) = 0
  • IMultiDecoder.h:結構如下:

    • virtual ~IMultiDecoder() {}
    • virtual void resetPacket(unsigned int packetInd) = 0
    • virtual void addSymbols( unsigned int packetInd, const std::vector< ChannelSymbol>& symbols) = 0
    • virtual void decode(unsigned int packetInd) = 0
    • virtual DecodeResult getDecodeResult(unsigned int packetInd) = 0
  • CachedMultiDecoder.h:繼承自 IMultiDecoder ,功能不是很明確
  • CachedMultiDecoder.hh :樓上的實現
  • LinearCheckNodeUpdater.h:結合 BP 使用,參考 include/util/inference/bp/NodeUpdater.h
    • class LogPmQ
    • class LinearCheckNodeUpdater : public NodeUpdater< float>
  • LinearCheckNodeUpdater.cpp:樓上的實現

include/codes/fountain

說明:主要實現了 LT 和 Raptor 噴泉碼的算法

  • LT Codes:
    • LTParityNeighborGenerator.h:生成 LT 的節點分佈,並選擇使用哪些 bit 進行 XOR
    • ParityEncoder.h:LT 碼編碼器,只是被抽象成了根據給定的節點分佈的圖編碼
      • public:
        • ParityEncoder( unsigned int numMessageBits, const NeighborGenerator& neighborGenerator, const SymbolFunction& symbolFunction):其中 neighborGenerator 由樓上的模塊產生
        • virtual ~ParityEncoder() {}
        • virtual void setPacket(const std::string& packet)
        • virtual void encode( unsigned int numSymbols, std::vector< uint16_t>& outSymbols)
      • private:
        • uint16_t next()
        • const unsigned int m_numMessageBits
        • NeighborGenerator m_neighborGenerator
        • SymbolFunction m_symbolFunction
        • unsigned int m_nextSymbolIndex
        • std::vector< bool> m_packetVector
        • std::vector< unsigned int> m_neighbors
    • LTDecoder.h:繼承自 ILLRDecoder,LT 碼的譯碼器,
      • public:
        • LTDecoder(uint32_t numVariables, uint32_t llrBufferSize, uint32_t numIterations)
        • virtual ~LTDecoder() {}
        • virtual void reset()
        • virtual void add(const std::vector< LLRValue>& llrs):爲譯碼器添加似然信息,注意譯碼器只支持連續的似然信息
        • virtual DecodeResult decode():根據給定的接受符號解碼出數據包
        • virtual void softDecode(std::vector< LLRValue>& llrs):軟判決譯碼方法,
      • private:
        • const uint32_t m_numVariables:可變節點的數量
        • std::vector< LLRValue> m_llrs
        • LTParityNeighborGenerator m_neighborGenerator:存儲度分佈
  • Raptor Codes:
    • RaptorEncoder.h:外碼(預編碼) LDPC(取自 itpp 庫),內碼 LT,而 Raptor Codes 真正生成的函數位於python/simulator/factories/codes/RaptorFactory.py 中 。注意:在級聯碼的概念中,預編碼稱爲外碼(首先操作),與之級聯的碼稱爲內碼(在預編碼之後操作)
      • public:
        • RaptorEncoder(const std::string& ldpcFilename):ldpcFilename 位於 ./data/ldpc 中,爲 itpp 生成的 *.it 文件,data 中的數據是如何產生的???
        • virtual void setPacket(const std::string& packet):(這個函數很講究),其中首先將 數據包轉換成 itpp::bvec 類型,然後使用 itpp::ldpc 編碼,得到 ldpcCodeword,轉爲 string 後,在將 ldpc 的編碼結果傳遞給 LT 碼編碼器
        • virtual void encode( unsigned int numSymbols, std::vector< uint16_t>& outSymbols):必須結合 setPacket 方法,因爲這一步只進行 LT 編碼,但 LT 的輸入爲 ldpc 碼字
      • private:
        • static BitwiseXorSymbolFunction getSymbolFunction()
        • static LTParityNeighborGenerator getNeighborGenerator(uint32_t codewordSize)
        • itpp::LDPC_Generator_Systematic m_G
        • itpp::LDPC_Code m_ldpc
        • ParityEncoder< BitwiseXorSymbolFunction, LTParityNeighborGenerator> m_lt
        • itpp::bvec m_packetBits
        • itpp::bvec m_encodedBits
        • std::vector< uint16_t> m_encodedVec
    • RaptorDecoder.h:繼承自 ILLRDecoder ,先 LT 解外碼,然後用 itpp::ldpc 解內碼
      • public:
        • RaptorDecoder(const std::string& ldpcFilename, uint32_t numLtIterations)
        • virtual ~RaptorDecoder() {}
        • virtual void reset()
        • virtual void add(const std::vector< LLRValue>& llrs)
        • virtual DecodeResult decode()
      • private:
        • itpp::LDPC_Generator_Systematic m_G
        • itpp::LDPC_Code m_ldpc
        • LTDecoder m_lt
        • std::vector< LLRValue> m_llrs
        • itpp::vec m_itppLlrs
        • itpp::bvec m_decodedBits

include/codes/ldpc

說明: 沒有仔細看,自己實現的 LDPC 碼,有一些擴展功能

include/codes/null

說明: 繼承了 IEncoder,基本就是一個空殼,不對輸入做任何修改

  • NullDecoder.h
  • NullEncoder.h

include/codes/puncturing

說明:實現了各種打孔機制

  • IPuncturingSchedule.h:打孔機制的接口
    • virtual ~IPuncturingSchedule() {}
    • virtual void reset() = 0
    • virtual void batchNext(unsigned int numSymbols, std::vector< uint16_t>& streamIndices) = 0:產生輸出碼流
  • RepeatingPuncturingSchedule.h:Splits the symbols stream to 8 sub-groups, then sends symbols from each sub-group
  • RoundRobinPuncturingSchedule.h:Gets symbols from index 0 to last index and wraps around,一種調度機制
  • StaticPuncturingSchedule.h:Punctures according to a given vector,傳統的打孔
  • StridedPuncturingSchedule.h:Splits the symbols stream to 8 sub-groups, then sends symbols from each sub-group,strider 的打孔方式

include/codes/spinal (重點!故換顏色!)

說明:重點中的重點,整個工程的核心編碼算法,實現部分最好也要搞明白

IMultiStreamEncoderIMultiStreamDecoder

圖注:從上面兩幅層次結構圖可以看出 IMultiStreamEncoder 和 IMultiStreamDecoder 基本就是爲 Spinal Codes 這樣的編碼設計的,因爲兩者都包含碼流結構的打孔方法。

  • protocols

    說明:爲 Spinal Codes 提供傳輸協議

    • SequentialProtocol.h:pinal protocol, transmits one pass after another,一個 pass 接一個 pass 發送
      • SequentialProtocol.hh:樓上的實現
    • StridedProtocol.h超級重要!!! Spinal Codes 的 Strided 傳輸協議,配合 Strided 打孔使用。 Spinal protocol, suited for StridedPuncturingSchedule (“8-way puncturing”).
      • public:
        • StridedProtocol(unsigned int numPackets,
          unsigned int spineLength,
          unsigned int maxSymbols,
          unsigned int numLastStepSymbolsPerPass,
          unsigned int numRepetitions)
        • unsigned int numSymbolsNextDecode(unsigned int packetInd)
        • void setResult(unsigned int packetInd,
          unsigned int numSymbols,
          bool isFinished):起到記錄當前譯碼結果的作用。如果本次譯碼成功,則記錄所發送的符號數,如果本次譯碼失敗,則使用 maxSymbol 作爲下一次譯碼的 推薦符號數
        • void resetPacket(unsigned int packetInd)
      • private:
        • const unsigned int m_maxSymbols:閾值,譯碼器用來嘗試譯碼的最大的符號數,超過這個值就放棄譯碼。
        • vector< unsigned int> m_numSymbolsPerSubpass
        • vector< unsigned int> m_lastSubpassInd
        • vector< unsigned int> m_lastOutputNumSymbols:numSymbolsNextDecode的返回值。
        • vector< unsigned int> m_lastActualNumSymbols:上一次譯碼使用到的符號的數量。
  • IHashDecoder.h
    • struct SpinalDecodeResult : public DecodeResult:Spinal Codes 譯碼結果保存形式,多了一個 weight 參數
    • class IHashDecoder : public IMultiStreamDecoder< ChannelSymbol>
  • CodeFactory.h:針對 Spinal Codes 的編解碼的各個工廠模塊,包括:
    • class CodeFactory:編解碼主工廠,選擇一種編碼方式(IEncoderFactory),包括:salsa/lookup3/oneAtATime
    • class IEncoderFactory:選擇一種信道模式,也就是接收端接收到的信道的符號格式(ISymbolSearchFactory),包括:linear/soft/gaussian/bitwise/coherence
    • class ISearchFactory:選擇一種譯碼時使用到的搜索方式,包括:beamDecoder/lookaheadBeamDecoder
  • FlatSymbolStorage.h:symbol 的存儲,使用 Spine 值作爲索引
    • FlatSymbolStorage.hh:樓上的實現
  • HashEncoder.h:Spinal Codes 的編碼器,class HashEncoder : public IMultiStreamEncoder
    • public:
      • HashEncoder(unsigned int k, unsigned int spineLength):Encodes the packet “packet” into real symbols in [-1,1].
      • virtual void setPacket(const std::string& packet)
      • virtual void encode( const std::vector< uint16_t>& spineValueIndices, std::vector< uint16_t>& outSymbols)
    • private:
      • const unsigned int m_k:“K”值
      • const unsigned int m_numMessageBits:信息序列的比特數
      • const unsigned int m_spineLength:Spine 的比特長度
      • std::vector< SpineValueType> m_spine:用於存儲 spine 值的數組
    • HashEncoder.hh:樓上的實現
  • SpinalBranchEvaluator.h:用於 Spinal Codes Bubble decode 譯碼樹上的分支度量的計算,包括:
    • IntegerEuclidianDistance.dist(Symbol x, Symbol y):計算整數符號 x 和 y 的歐式距離
    • SoftEuclidianDistance.dist(SoftSymbol x, SoftSymbol y):計算符號 x 和 y 的歐式距離
    • HammingDistance.dist(Symbol x, Symbol y):計算整數符號 x 和 y 的漢明距離
    • FadingEuclidianDistance.dist(Symbol x, Symbol y):計算衰減後的軟符號 x 和 y 的歐式距離
    • struct SpinalNode:存儲了 Spinal Codes 譯碼樹的節點結構
      • bool operator<(const SpinalNode& other) const
      • WeightType getWeight()
      • WeightType getLikelihood
      • WeightType likelihood
      • WeightType lastCodeStepLikelihood
      • SpineValueSeed hash
    • struct SymbolCollection:用於存儲接收符號
    • class SpinalBranchEvaluator:用於估計譯碼樹上的分支最大似然值
      • public:
        • SpinalBranchEvaluator(const ChannelTransformation& xform, uint32_t k)
        • void branch(Node& parent, unsigned int edge, BranchData& syms, Node& child)
        • void initNode(Node& node)
      • private:
        • const uint32_t m_k
        • const uint32_t m_mask:低 k 比特的 mask
        • ChannelTransformation m_xform:ChannelTransformation from bits to symbols,不明覺歷
        • typename std::vector< uint16_t> m_encodedSymbols:重新編碼後的符號
        • std::vector< typename ChannelTransformation::OutputType> m_candidateSymbols:序列譯碼的候選符號
        • std::vector< typename ChannelTransformation::OutputType> m_observedSymbols:被計算過分支度量的符號
      • 個別模板類的實現,其他的實現在 src/codes/spinal/ 中
  • HashDecoder.h:Spinal Codes 的譯碼
    • struct SpinalIntermediateResult:保存了譯碼的中間狀態
    • class HashDecoder : public IHashDecoder < typename Search::Evaluator::ChannelSymbol>:真正的譯碼器部分
    • HashDecoder.hh:實現
  • StubHashDecoder.h:譯碼器的輸入被保存起來,可訪問,用於測試用的譯碼器
  • Composites.h:typedef SequentialProtocol< StridedPuncturingSchedule> StridedSequentialProtocol,沒有別的內容了

include/codes/strider

說明: strider 編碼的實現,沒有對這個編碼有詳細的研究

  • LayeredDecoder.h
  • LayeredEncoder.h
  • LayerManipulator.h
  • LayerSuperposition.h StriderFactory.h
  • StriderGeneratorMatrix.h StriderInterleaver.h
  • StriderTurboCode.h

include/codes/turbo

說明: 基於 itpp 的 turbo 編碼

  • TurboCodec.h:Turbo 交織器
  • TurboEncoder.h:Turbo 編碼器
  • TurboDecoder.h:Turbo 譯碼器

注意:下面給出的編碼器和譯碼器一部分是提供了頂層的接口,一方便用戶使用,另一部分是爲 Spinal Codes 提供編碼和譯碼,繼承關係如下圖所示

IEcoder

codes/IEncoder.h:虛基類,編碼器的接口,同 shared_ptr 一同使用,大部分的編碼器都繼承自 IEncoder 類,因此可以理解爲編碼器的框架,包括:

  • virtual ~IEncoder() {}
  • virtual void setPacket(const std::string& packet) = 0:讀入將被編碼的數據包
  • virtual void encode(unsigned int numSymbols, std::vector< uint16_t>& outSymbols) = 0:將第numSymbols個編碼符號存入outSymbols

codes/IMultiStreamEncoder.h:提供打孔功能的編碼器的接口,貌似處理 location 和 stream 能夠實現打孔功能,包括:

  • virtual ~IMultiStreamEncoder() {}
  • virtual void setPacket(const std::string& packet) = 0
  • virtual void encode( const std::vector< uint16_t>& streamIndices, std::vector< uint16_t>& outSymbols) = 0

codes/EncoderMultiplexer.h:繼承自 IEcoder,負責將源信息分別分給不同的編碼器,並用 round-robins 方法調度不同的編碼器

  • public:
    • typedef std::tr1::shared_ptr< EncoderMultiplexer> Ptr
    • EncoderMultiplexer(const std::vector< IEncoderPtr>& encoders, const std::vector< uint32_t>& messageLengthsBits)
    • virtual ~EncoderMultiplexer() {}
    • virtual void setPacket(const std::string& packet)
    • virtual void encode( unsigned int numSymbols, std::vector< uint16_t>& outSymbols)
  • private:
    • const std::vector< IEncoderPtr> m_encoders
    • const std::vector< uint32_t> m_messageLengthsBits
    • uint32_t m_next
    • std::vector< uint16_t> m_symbolBuffer

codes/InterleavedEncoder.h:繼承自 IEcoder,首先使用指定的編碼器進行編碼,然後根據給定的交織序列隨機打亂(shuffle)編碼器的輸出符號,以實現交織,實現部分位於 src/codes/InterleavedEncoder.cpp

  • public:
    • InterleavedEncoder(IEncoderPtr& encoder, const std::vector< uint16_t>& interleaveSequence)
    • virtual ~InterleavedEncoder() {}
    • virtual void setPacket(const std::string& packet)
    • virtual void encode( unsigned int numSymbols, std::vector< uint16_t>& outSymbols)
  • private:
    • IEncoderPtr m_encoder:給定的編碼器
    • const std::vector< uint16_t> m_interleavingSequence:交織序列
    • const uint16_t m_maxIndex:交織序列中的最大的序號
    • std::vector< uint16_t> m_encoded:編碼後的數據包
    • unsigned int m_next:下一個輸出的符號

codes/MultiToSingleStreamEncoder.h:繼承自 IEncoder,使用指定的編碼器對數據包進行編碼,並採用“分流法”對編好的碼字打孔,產生一系列的碼流的過程。其實現位於 src/codes/MultiToSingleStreamEncoder.cpp 中,代碼結構如下:

  • MultiToSingleStreamEncoder(IMultiStreamEncoder::Ptr& encoder, IPuncturingSchedulePtr& puncturing):指定編碼器 與 打孔機制。
  • -

IDecoder< ChannelSymbol >

ILLRDecoder

codes/DecodeResult.h:譯碼後結果的結構,包括:

  • std::string packet:(string)某數據包的譯碼結果
  • float logProbError:(float)經過譯碼處理後表現出來的差錯概率的 log 值。

codes/IDecoder.h:虛基類,譯碼器接口,同 shared_ptr 一同使用,包括:

  • virtual ~IDecoder() {}
  • virtual void reset() = 0:Resets the decoder, so a different packet can be decoded
  • virtual void add(const std::vector< ChannelSymbol>& symbols, N0_t n0) = 0:假設噪聲功率對不同的信息符號是相同的,爲譯碼器添加符號
  • virtual void add(const std::vector< ChannelSymbol>& symbols, const std::vector< FadingMagnitude>& fadingMagnitude, N0_t n0) = 0:假設數據包傳輸在衰減信道中,其中噪聲功率是恆定的,但接收到的噪聲功率發生了變化,同樣是爲譯碼器添加符號
  • virtual DecodeResult decode() = 0:譯碼函數,返回譯碼結果 DecodeResult

codes/ILLRDecoder.h:在譯碼時,基於對數似然比估計信息比特,結果與 IDecoder 很像,包括

  • virtual ~**ILLRDecoder**() {}
  • virtual void reset() = 0
  • virtual void add(const std::vector< LLRValue>& llrs) = 0:爲譯碼器加入最大似然信息
  • virtual DecodeResult decode() = 0:譯碼函數

codes/IMultiStreamDecoder.h:爲打孔碼字(punctured codes)提供譯碼器的接口,包括:

  • virtual ~IMultiStreamDecoder() {}
  • virtual void reset() = 0
  • virtual void add(const std::vector< uint16_t>& streamIndices, const std::vector< ChannelSymbol>& symbols, N0_t n0) = 0:爲譯碼器添加符號,其中 streamIndices 爲當前 symbol 所屬的 stream 編號
  • virtual DecodeResult decode() = 0

codes/InterleavedDecoder.h:繼承自 ILLRDecoder ,解交織,再譯碼

  • public:
    • InterleavedDecoder(const Decoder& decoder, const std::vector< uint16_t>& interleaveSequence)
    • virtual ~InterleavedDecoder() {}
    • virtual void reset()
    • virtual void add(const std::vector< float>& symbols)
    • virtual DecodeResult decode()
  • private:
    • Decoder m_decoder
    • std::vector< uint16_t> m_interleavingSequence:有交織功能,就要有交織序列存儲在譯碼器中
  • codes/InterleavedDecoder.hh:InterleavedDecoder 中方法的實現

codes/MultiToSingleStreamDecoder.h:繼承自 IDecoder< ChannelSymbol>,通過對接收符號進行重新排序(或者稱之爲組合跟容易理解),以實現對打孔後的接收序列的譯碼

  • public:
    • typedef std::tr1::shared_ptr< MultiToSingleStreamDecoder< ChannelSymbol> > Ptr
    • MultiToSingleStreamDecoder(typename IMultiStreamDecoder< ChannelSymbol>::Ptr& decoder, IPuncturingSchedulePtr& puncturing)
    • virtual void reset()
    • virtual void add(const std::vector< ChannelSymbol>& symbols, N0_t n0)
    • virtual void add(const std::vector< ChannelSymbol>& symbols, const std::vector< FadingMagnitude>& fadingMagnitude, N0_t n0)
    • virtual DecodeResult decode()
  • private:
    • typename IMultiStreamDecoder< ChannelSymbol>::Ptr m_decoder
    • IPuncturingSchedulePtr m_puncturing
    • std::vector< uint16_t> m_streamIndicesWorkArr
  • codes/MultiToSingleStreamDecoder.hh:MultiToSingleStreamDecoder 的實現

codes/RandomPermutationGenerator.h:隨機排列(permutation)生成,不知作者在這裏爲什麼用排列,而不用序列,沒遇到使用這個模塊的其他模塊,等遇到了再好好研究這個模塊的功能

codes/SymbolToLLRDecoderAdaptor.h:將指定的 demaper 和 LLRdecoder 結合起來
codes/SymbolToLLRDecoderAdaptor.hh:樓上的實現部分

3.3 include/mappers

說明: 實現了調製過程,因爲在定義工廠時,調製也會有詳細的使用,所以這裏儘量列出代碼結構。

IMapper.h:映射的接口,包括:

  • virtual ~IMapper() {}
  • virtual void process(const std::vector< uint16_t>& inSymbols, std::vector< ChannelSymbol>& outSymbols) = 0
  • virtual float getAveragePower() = 0
  • virtual unsigned int forecast(unsigned int numOutputs) = 0

ComplexLinearMapper.h:把一個整數映射到 I-Q 域上,代碼結構如下:

  • public:
    • ComplexLinearMapper(unsigned int numBitsPerDim)
    • void process(const std::vector< uint16_t>& inSymbols, std::vector< ComplexSymbol>& outSymbols):Maps symbols to the complex domain. 規則是 LSB’s taken for real part, next bits for imaginary
    • ComplexSymbol map(uint16_t sym):Maps a single symbol to the complex domain
    • float getAveragePower():假設 Spinal 編碼的結果是均勻分佈的,求出了信號的平均功率
    • unsigned int forecast(unsigned int numOutputs):
  • private:
    • const unsigned int m_numBitsPerDim:單維度上,每個符號的比特數
    • const uint16_t m_symbolMask:取符號的 LSB 作爲一個維度,如:Mask(I-Q) = 0x00FF

GaussianMapper.h:將符號映射到 truncated Gaussian 分佈上,代碼結構:

  • public:
    • GaussianMapper(unsigned int inputNumBits, unsigned int precisionBits, float numStandardDevs): inputNumBits 爲輸入數據的比特數,precisionBits 信道支持的比特數,numStandardDevs 爲高斯分佈的標準差
    • GaussianMapper(const GaussianMapper& other)
    • ~GaussianMapper()
    • void process(const std::vector< uint16_t>& inSymbols, std::vector< Symbol>& outSymbols):將符號線性映射成較大的精度
    • Symbol map(uint16_t sym):Maps a single symbol to the (larger) precision, linearly
    • float getAveragePower()
    • unsigned int forecast(unsigned int numOutputs)
  • private:
    • uint16_t m_highestInput:模塊支持的最大的輸入值
    • Symbol* m_mappingTable:[(1 << inputNumBits) - 1] 長的數組,構造位於構造函數中
    • float m_variance:輸出符號的方差

NormalDistribution.h:被 TruncatedNormalDistribution.cpp 包含,幫忙實現正太分佈

  • static double pdf(double u):Probability Density Function
  • static double cdf(double u):Cumulative Distribution Function
  • static double ppf(double p):Percentage Point Function

TruncatedNormalDistribution.h:被 GaussianMapper.cpp 包含,生成一個(a,b)截斷區間的高斯分佈

  • public:
    • TruncatedNormalDistribution(double a, double b)
    • double ppf(double p)
    • double variance()
  • private:
    • double m_a
    • double m_b
    • double m_cdfOfA:The CDF of point a on a standard normal variable

GrayMapper.h:使用 Gray code 將比特序列映射到 constellation,換湯不換藥,不做詳細介紹了
LinearMapper.h:Maps integers to fixed-precision symbols,個人對 precision 的理解不是很好

  • LinearMapper(unsigned int symbolSizeBits, unsigned int precisionBits):輸入符號的精度,和信道要求的精度
  • 其他部分同上

QamMapper.h:使用了 IMapper,但程序中使用了 itpp::QAM,參考 binding 中的內容,此處可以作爲了解
QPSKMapper.h:使用了IMapper ,但程序中使用了 itpp::QPSK,參考 binding 中的內容,此處可以作爲了解
SoftMapper.h不明確,參考 simulation 中的實驗再回頭看看。

3.4 include/demappers

說明:需要了解一些 map 和 demap 的方法

IDemapper.h:Demapper 的接口模塊,代碼結構:

  • virtual ~IDemapper() {}
  • virtual void process(const std::vector< ChannelSymbol>& symbols, N0_t n0, std::vector< LLRValue>& llrs) = 0:將接受符號解調爲 soft bit values,理解不是很好
  • virtual void process(const std::vector< ChannelSymbol>& symbols, const std::vector< FadingMagnitude>& fadingMagnitude, N0_t n0, std::vector< LLRValue>& llrs) = 0:將接受符號解調爲 soft bit values,且每個符號有不同的噪聲值
  • virtual unsigned int forecast(unsigned int numOutputs) = 0

BitwiseDemapper.h:通過枚舉星座圖上的點,來解星座映射,找到最大似然的點解調

  • BitwiseDemapper.hh:樓上的實現函數

BscDemapper.h:比特翻轉 BSC 信道解調
ItppDemapper.h:繼承 IDemapper,相比之下只有參數不太一樣 ,IT++ Modulator 和 IDemapper 之間的適配器

  • public:
    • ItppDemapper(ModulatorPtr& modulator, unsigned int forecastFactor, bool useApprox):
    • virtual ~ItppDemapper() {}
    • virtual void process(const std::vector< ChannelSymbol>& symbols, N0_t n0, std::vector< LLRValue>& llrs)
    • virtual void process(const std::vector< ChannelSymbol>& symbols, const std::vector< FadingMagnitude>& fadingMagnitude, N0_t n0, std::vector< LLRValue>& llrs):
    • virtual unsigned int forecast(unsigned int numOutputs)
  • private:
    • ModulatorPtr m_modulator
    • const unsigned int m_forecastFactor
    • itpp::Soft_Method m_softMethod
  • ItppDemapper.hh:樓上的實現

NullDemapper.h:不調製,不解調

3.5 include/protocols

說明:給出了兩種編碼符號的傳輸方案,回頭仿真時時再好好研究每個函數的功能
注意:還有第三種傳輸方案,位於 pythonprotocols/MultipleTryProtocol.py 中。
另外:Spinal Codes 的 protocol 定義在 Spinal Codes 本身中,當使用 Simulator 做仿真時,只要定義了 Spinal,protocol 就會使用 Spinal 中的,位於 include/codes/spinal/protocols 中

OneTryProtocol.h:一次性發送所有的編碼符號

  • public:
    • OneTryProtocol(unsigned int numPackets, unsigned int numSymbols)
    • unsigned int numSymbolsNextDecode(unsigned int packetInd)
    • void setResult(unsigned int packetInd, unsigned int numSymbols, bool isFinished)
    • void resetPacket(unsigned int packetInd)
  • private:
    • unsigned int m_numSymbols
    • vector< unsigned int> m_nextDecode

RateApproxProtocol.h:自適應碼率傳輸,怕理解不好,直接引用原文:

Attempts a sequence of rates, to find a rate up to (1+delta) factor from the minimal possible rate for the channel.
A protocol that tries rates such that the spacing between rates is at most a given constant factor ‘delta’. This means that if a system achieves a rate R, then the protocol will at the worst case try rate R * delta.

  • public:
    • RateApproxProtocol( unsigned int numPackets, unsigned int maxSymbols, float delta, uint32_t minSymbols)
    • unsigned int numSymbolsNextDecode(unsigned int packetInd)
    • void setResult(unsigned int packetInd, unsigned int numSymbols, bool isFinished)
    • void resetPacket(unsigned int packetInd)
  • private:
    • const unsigned int m_maxSymbols
    • const float m_oneOverDelta
    • const unsigned int m_minSymbols
    • std::vector< unsigned int> m_nextNumSymbols

3.6 include/util

說明很重要,給出了差錯控制編碼和信道的實現的基礎函數,實現了工程中大部分的基礎算法
Spinal Codes 說明:基於 hash 函數算法的差錯控制編碼,在使用是請注意區分 symbol,state,hash digest 的概念

include/util 結構圖

util/hashes

說明:分爲三個部分介紹,一部分是 hash 函數 的“生產”方式;另一種是,hash 函數算法的具體實現;然後是,hash 函數的 Python 接口

hash 函數的頂層模板類:

  • UnlimitedHash.h重要):較爲常用的類,實現一個可以生成 16-bit 的 stream 的 hash 函數
    • UnlimitedHash.hh:IMPLEMENTATION OF UnlimitedHash.h INLINE FUNCTIONS.
    • UnlimitedHash(const Seed prevSeed, uint32_t data):初始化
    • void hash(uint32_t data):Hash the internal seed with an external 32-bit word is done with hash().
    • Seed getSeed():The internal state (the “seed”) can be retrieved using getSeed().
    • uint16_t next():The stream of 16-bit values is produced by iteratively calling nextBits().
  • SingleSymbolFunction.h:從當前的 hash digest 中取出編碼符號,相當與一個小型的生產 hash 函數的工廠,可以讓用戶不必知道內部算法而直接使用
  • ShiftRegisterAdaptorHash.h:An adaptor class that allows updates bit-by-bit, then hashes the entire state.(沒有用到,沒有細看)

hash 函數的實現:

  • BitwiseXor.h :32-bit-state 的 XOR 更新操作,類聲明,實現位於文件src/util/hashes/BitwiseXor.cpp
  • Lookup3Hash.h:實現了Bob Jenkin’s lookup3 算法,此處爲類聲明,實現位於 src/util/hash/Lookup3Hash.cpp 中,包括:
    • Lookup3Hash 類:Implementation of Bob Jenkin’s lookup3 hash function.
    • Lookup3SymbolFunction 類:Produces symbols from the digest of a Lookup3Hash,相當於Spinal Codes中提到的 RNG 的作用,即取 32-bit-state 的 16-bit 移位
  • OneAtATimeHash.h:實現了Bob Jenkin’s one-at-a-time 算法,實現部分位於 src/util/hashes/OneAtATimeHash.cpp
  • salsa20.h:Salsa20 算法中使用到的類型和函數的定義
  • SalsaHash.h:Salsa20 算法的實現類,結構基本與Lookup3Hash.h 相同
  • ecrypt-config.h:源自於 Salsa20 算法,請勿改動
  • ecrypt-machine.h:源自於 Salsa20 算法,請勿改動
  • ecrypt-portable.h:源自於 Salsa20 算法,請勿改動

hash 函數的 Python 接口:

  • SWIGHash.h:配合 bindings/util/hashes.i%pythoncode %{ %}使用,使用方法爲,在 Python 環境下按如下方式,即可調用封裝好的 hash 函數:
import wireless.util.hashes as hash
hash_func = hash.OneAtATimeHash_init()

util/inference

說明:給出了兩種譯碼時用到的推到方式,一種是基於置信度的 BP 法,另一種是基於狀態圖的搜索算法。

  • bp:LDPC 譯碼中使用,這裏先不做介紹
    • BipartiteBP.h
    • BipartiteGraph.h
    • BPMessage.h
    • ElementHeap.h
    • LinearVariableNodeUpdater.h
    • MessagePassingDecoder.h
    • MessagePassingDecoder.hh
    • MultiStack.h
    • MultiVector.h
    • NodeUpdater.h
  • hmm:廣義來說這些搜索方法是可以算作是 HMM 的,作者這樣命名也不無道理

    • LookaheadBeamSearch.h:A beam search, with lookahead.
      • LookaheadAdaptor.h
      • BeamSearch.h:A generic implementation of beam search exploration.
        • Backtracker.h
        • BestK.h
        • DualPool.h
    • IPruner.h:return: true if the node might be added, false if the node has been pruned.
    • ParallelBestK.h:Collection of several BestK lists, insertions round-robin within the collection.
  • util/Utils.h :不同的 bit / string / likelihood 之間的轉換,其中的類方法均爲靜態方法 ,以便在只定義類的情況下也能夠調用類方法,而不需將其實例化

  • util/ItppUtils.h :實現 string 與 itpp bvec 之間的轉換
  • util/BitStatCounter.h:統計多個字符串中“1”出現的次數
  • util/BlockStatCounter.h:統計一個長爲 k 的 block 非零的次數
  • util/crc.h:實現了 crc16 和 crc32
  • util/MTRand.h:MersenneTwister 隨機數生成

3.7 include/*.h

說明:定義了一些包括 代碼符號定義規則,變換的級聯,兩種檢測譯碼是否正確的方法(crc,oracle),包生成

代碼符號定義規則:

  • include/CodeBench.h :C++ 部分的編碼標準,給出了一些 typedef 和 define 等,注意如果在這裏進行了修改,那麼 ./binding 中的相關內容也要修改,對應的封裝在 bindings/general.i 中,如需要請向前查閱

變換的級聯:

  • include/ComposedTransformation.h :ComposedTransformation2 類的聲明和實現,將兩種變換組合爲一種變換,包括 constructor,transform,forecast 方法,可以理解爲變換的級聯吧。
  • include/TransformationAdaptor.h:貌似沒怎麼用過,且文件中有詳細表述,等遇到了再做研究

檢測譯碼是否正確:

  • include/CrcDetector.h :CRC -16的檢測模塊的聲明和實現,包括 CrcDetector() / setPacket() / isFinished() 方法,由 CrcPacketGenerator 生成的數據包的正確性。檢測方法是使用接收的數據(這裏一般爲譯碼後的結果)的除了前兩個字節之外的其他部分生成的CRC值和前兩個字節的值想對比,若相等則 isFinished=True
  • include/OracleDetector.h:將譯碼後得到的 result 數據結構中的 packet 和 與之相對的發送的 packet 做對比,以判斷譯碼是否成功,包括 OracleDetector,setPacket,isFinished 方法

數據包生成:

  • include/PacketGenerator.h:生成隨機的數據包,包括PacketGenerator,seed,get 方法,實現部分在 src/PacketGenerator.cpp
  • include/CrcPacketGenerator.h:實現了使用include/util/crc.h 中的CRC-16 查表算法,生成帶有CRC頭(位於數據包的前兩個字節)的數據包,實現部分在 src/CrcPacketGenerator.cpp中,包括 CrcPacketGenerator,seed,get,這裏要注意生成的是完整的包而不是根據包生成頭

4 src

說明:大部分功能模塊的實現(.cpp),在 include (上一節)中順帶說明,不做單獨介紹


5 .metadata

說明:不知道是什麼


6 .settings

說明:eclipse的設置記錄


7 autom4te.cache

說明:不知道是什麼


8 build-aux

說明:存放了一些m4的輔助宏


9 data

說明:LDPC的編碼結果


10 doc

說明:Doxyfile文檔


11 lablog

說明


12 release

說明


13 test

說明


14 util

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章