main.cpp

来自「signal-processing.rar信号处理demo原码」· C++ 代码 · 共 154 行

CPP
154
字号
/*
//
//               INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in accordance with the terms of that agreement.
//    Copyright (c) 2006 Intel Corporation. All Rights Reserved.
//
*/

#include "stdio.h"
#include "viterbi.h"
#include "timer.h"




static void show_ipp_version(void)
{
  const IppLibraryVersion* pLibVer = ippsGetLibVersion();

  printf("\n");
  printf("Intel(R) Integrated Performance Primitives\n");
  printf("  Name      : %s\n",pLibVer->Name);
  printf("  Version   : %s\n",pLibVer->Version);
  printf("  BuildDate : %s\n",pLibVer->BuildDate);
  printf("  CPU       : %s\n",pLibVer->targetCpu);
  printf("\n");
   
  return;
} // show_ipp_version()


int runViterbi(double SNR, double *result, CTimer* timer)
{
    int i;
    long failCount = 0;
    
    Real4DSymbl     tOut[TRELLIS_SEQ_LEN];  // trellis sequence )
    Real4DSymbl     vInp[TRELLIS_SEQ_LEN];  // noise corrupted trellis sequence )
    ViterbiTestInfo vInf;
    
/* ------------------------------ 16 STATES ------------------------------ */
    timer[0].Init();
    timer[0].Start();
    ViterbiInit(&vInf, ViterbiState16);

    for( i = 0; i < VITERBI_TEST_LEN; i++ )
    {
        vInf.ceDlState = 0;
        GetTrellisSequence( tOut, TRELLIS_SEQ_LEN, &vInf );
        if(AddChannelNoise( tOut, vInp, TRELLIS_SEQ_LEN, SNR))
        {
            return 1;
        }
        if(CheckViterbiOut( tOut, vInp, TRELLIS_SEQ_LEN, &vInf, &failCount))
        {
            return 1;
        }
    }

    timer[0].Stop();
    result[0] = failCount;

/* ------------------------------ 32 STATES ------------------------------ */
    timer[1].Init();
    timer[1].Start();

    ViterbiInit(&vInf, ViterbiState32);

    failCount = 0;

    for( i = 0; i < VITERBI_TEST_LEN; i++ )
    {
        vInf.ceDlState = 0;
        GetTrellisSequence( tOut, TRELLIS_SEQ_LEN, &vInf );
        if(AddChannelNoise( tOut, vInp, TRELLIS_SEQ_LEN, SNR))
        {
            return 1;
        }
        if(CheckViterbiOut( tOut, vInp, TRELLIS_SEQ_LEN, &vInf, &failCount))
        {
            return 1;
        }
    }
    timer[1].Stop();
    result[1] = failCount;

/* ------------------------------ 64 STATES ------------------------------ */
    timer[2].Init();
    timer[2].Start();    

    ViterbiInit(&vInf, ViterbiState64);

    failCount = 0;

    for( i = 0; i < VITERBI_TEST_LEN; i++ )
    {
        vInf.ceDlState = 0;
        GetTrellisSequence( tOut, TRELLIS_SEQ_LEN, &vInf );
        if(AddChannelNoise( tOut, vInp, TRELLIS_SEQ_LEN, SNR))
        {
            return 1;
        }
        if(CheckViterbiOut( tOut, vInp, TRELLIS_SEQ_LEN, &vInf, &failCount))
        {
            return 1;
        }
    }
    timer[2].Stop();
    result[2] = failCount;

    return 0;
} // runViterbi()


int main(void)
{   
   double SNR = 36.0;
   double result[3] = {0, 0, 0};
   double vLen = TRELLIS_SEQ_LEN * VITERBI_TEST_LEN; 
   CTimer timer[3];
   double sec16, sec32, sec64; 
   
   show_ipp_version();
   printf("\t\t\t VITERBI DECODER\n\n");
   printf("SNR(dB)        16 STATE           32 STATE             64 STATE\n");
   
   printf("\t      err  t(ms)\t err  t(ms)\t      err  t(ms)\n");
   
   while(SNR > VITERBI_SNR_MIN)
   {
       if(runViterbi(SNR, result, timer))
       {
           break;
       }
       
       sec16 = timer[0].GetTime(CTimer::msec);
       sec32 = timer[1].GetTime(CTimer::msec);
       sec64 = timer[2].GetTime(CTimer::msec);
       printf("%3.1f\t     %5.2f %5.2f\t%5.2f %5.2f\t     %5.2f %5.2f\n",
                    SNR,
                    result[0]/vLen*100,
                    sec16,
                    result[1]/vLen*100,
                    sec32,
                    result[2]/vLen*100,
                    sec64);
       SNR -= 1.0;
   }
 
   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?