⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viterbi_decoding_wrapper.asv

📁 用simlink开发的space-time coding仿真模型,仿真的精度与效率有不小的提高
💻 ASV
字号:
/*
  *
  *   --- THIS FILE GENERATED BY S-FUNCTION BUILDER: 3.0 ---
  *
  *   This file is a wrapper S-function produced by the S-Function
  *   Builder which only recognizes certain fields.  Changes made
  *   outside these fields will be lost the next time the block is
  *   used to load, edit, and resave this file. This file will be overwritten
  *   by the S-function Builder block. If you want to edit this file by hand, 
  *   you must change it only in the area defined as:  
  *
  *        %%%-SFUNWIZ_wrapper_XXXXX_Changes_BEGIN 
  *            Your Changes go here
  *        %%%-SFUNWIZ_wrapper_XXXXXX_Changes_END
  *
  *   For better compatibility with the Real-Time Workshop, the
  *   "wrapper" S-function technique is used.  This is discussed
  *   in the Real-Time Workshop User's Manual in the Chapter titled,
  *   "Wrapper S-functions".
  *
  *   Created: Fri Aug 26 14:01:02 2005
  */


/*
 * Include Files
 *
 */
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#include <math.h>
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 130
#define y_width 1
/*
 * Create external references here.  
 *
 */
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
double mydis (double r_re,double r_im,double h1_re,double h1_im,double h2_re,double h2_im,int x1,int x2)
{
	double tempd,temp_re,temp_im,x1_re,x1_im,x2_re,x2_im;
	
	switch (x1){
    case 0 : x1_re=1;  x1_im=0; break;
    case 1 : x1_re=0;  x1_im=1; break;
    case 2 : x1_re=-1; x1_im=0; break;
    case 3 : x1_re=0;  x1_im=-1;break;
    default : ;
    }
    switch (x2){
    case 0 : x2_re=1;  x2_im=0; break;
    case 1 : x2_re=0;  x2_im=1; break;
    case 2 : x2_re=-1; x2_im=0; break;
    case 3 : x2_re=0;  x2_im=-1;break;
    default : ;
    }
    
	temp_re = r_re - h1_re*x1_re + h1_im*x1_im - h2_re*x2_re + h2_im*x2_im;
	temp_im = r_im - h1_im*x1_re - h1_re*x1_im - h2_im*x2_re - h2_re*x2_im;
    tempd=temp_re*temp_re + temp_im*temp_im;
    return  (tempd);
}
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */

/*
 * Output functions
 *
 */
void Viterbi_Decoding_Outputs_wrapper(const creal_T *r,
                          const creal_T *h1,
                          const creal_T *h2,
                          real_T *y)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
      double current_dis[4]={0,0,0,0};
      double cumulative_dis[4]={0,0,0,0};
      double temp_dis[4]={0,0,0,0};
      
      double current_state[4][130];
      double last_state[4][130];
      
      double temp_min;
      int m,n,k,g,temp_index;
      
      int send1[4][4]={{0,2,0,2},{0,2,0,2},{1,3,1,3},{1,3,1,3}};
      int send2[4][4]={{0,2,2,0},{1,3,3,1},{0,2,2,0},{1,3,3,1}};
      
      cumulative_dis[0]=mydis(r[0].re,r[0].im,h1[0].re,h1[0].im,h2[0].re,h2[0].im,0,0);
      cumulative_dis[1]=mydis(r[0].re,r[0].im,h1[0].re,h1[0].im,h2[0].re,h2[0].im,2,2);
      cumulative_dis[2]=mydis(r[0].re,r[0].im,h1[0].re,h1[0].im,h2[0].re,h2[0].im,0,2);
      cumulative_dis[3]=mydis(r[0].re,r[0].im,h1[0].re,h1[0].im,h2[0].re,h2[0].im,2,0);
      
      last_state[0][0]=0;
      last_state[1][0]=1;
      last_state[2][0]=2;
      last_state[3][0]=3;
      
     
      for (m=1;m<=128;m++){
           for (n=0;n<=3;n++){    // this is input bits, and is also the next state
                for (k=0;k<=3;k++){    //  this is four states 
                     temp_dis[k]=0;
                     current_dis[k]=mydis(r[m].re,r[m].im,h1[m].re,h1[m].im,h2[m].re,h2[m].im,send1[k][n],send2[k][n]);
                     temp_dis[k]=current_dis[k]+cumulative_dis[k];
                }
                temp_min=999999; temp_index=0;
                for (k=0;k<=3;k++){
                     if (temp_dis[k]<temp_min){
                         temp_min=temp_dis[k];
                         temp_index=k;
                     }
                }
                cumulative_dis[n]=temp_dis[temp_index];
                
                for (g=0;g<m;g++){
                     current_state[n][g]=last_state[temp_index][g];
                }
                current_state[n][m]=n;
           }
           for (n=0;n<=3;n++){
                for (k=0;k<=m;k++){
                     last_state[n][k]=current_state[n][k];
                }
           }
      }
      for (k=0;k<=3;k++){
           current_dis[k]=mydis(r[].re,r[130].im,h1[130].re,h1[130].im,h2[130].re,h2[130].im,send1[k][0],send2[k][0]);
      }
      temp_min=999999; temp_index=0;
      for (k=0;k<4;k++){
           if (current_dis[k]<temp_min){
               temp_min=current_dis[k];
               temp_index=k;
           }
      }
      for (k=0;k<129;k++){
           last_state[k]=states[temp_index][k];
      }
      
      for (k=0;k<129;k++){
           y[k]=last_state[k];
      }
      y[129]=0;
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}

⌨️ 快捷键说明

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