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

📄 total_power3.c

📁 该程序用粒子滤波的方法跟踪一个机器人并根据WiFi信号修改位置信息。
💻 C
📖 第 1 页 / 共 4 页
字号:

/*
 
  Compute Ray path with 3 reflexions
 
  Usage
  ------
 
  rs_amp = total_power3(TXpoint , RXpoint , planes , material , fc  , [nr] , [flp_scale]);
 
 
  Inputs
  -------
 
  TXpoint                               Transmitter point (3 x Nt)
  RXpoint                               Receiver point (3 x Nr)
  planes                                Planes (22 x nplanes)
  material                              Material (6 x nplanes)
  fc                                    Central Frequency
  nr                                    Numbre of reflexion (nr>= 0 and nr < 4, default nr = 3)
  flp_scale                             Scale factor (default = 100)
 
  Outputs
  -------
 
  rs_amp                                Total power (Nt x Nr)
 
 
  To compile
  ----------
 
 
  mex    -output total_power3.dll total_power3.c
 
  mex    -f mexopts_intel10amd.bat -output total_power3.dll total_power3.c
 
 
 
  Example 1
  ---------
 
  flp                      = load_flp('norwich01.flp');
  nr                       = 1;
  Nt                       = 5;
  Nr                       = 10;
  temp                     = flp.geom.planes([1 , 4 , 7] , :);
  xmin                     = min(temp(:));
  xmax                     = max(temp(:));
  temp                     = flp.geom.planes([2 , 5 , 8] , :);
  ymin                     = min(temp(:));
  ymax                     = max(temp(:));
  temp                     = flp.geom.planes([3 , 6 , 9] , :);
  zmin                     = min(temp(:));
  zmax                     = max(temp(:));
  Cov                      = [1000000 0 0 ; 0 1000000 0 ; 0 0 100];
  flp.info.TXpoint         = flp.info.TXpoint(: , ones(1 , Nt)) + chol(Cov)'*randn(3 , Nt);
  flp.info.RXpoint         = flp.info.RXpoint(: , ones(1 , Nr)) + chol(Cov)'*randn(3 , Nr);
  rs_amp                   = total_power3(flp.info.TXpoint ,flp.info.RXpoint , flp.geom.planes , flp.geom.material , flp.info.fc , nr);
  plot_flp(flp);
 
 
 Author : S閎astien PARIS : sebastien.paris@lsis.org
 -------  Date : 10/09/2007
 
 Reference : Jacques Beneat, http://www2.norwich.edu/jbeneat/
 ---------
 
 */

#include <math.h>
#include <mex.h>

#define PI 3.14159265358979323846



void fct_calimage(double * , double * , int  , double *) ;
bool fct_calrpt(double *, double *, double * , int  , double * );
double * fct_caltpts(double *, double *, double *, int , double * , int *, double *);
void compute_distloss(double * , int , double * , double * , double  , double , int , double * , double *);
void qsindex( double * , int * , int , int  );





/*-------------------------------------------------------------------------------------------------------------- */


double c = 3e8 , Ant = 1.0 , loss_factor = 1.0 , t_tol = 1.0;


void mexFunction( int nlhs, mxArray *plhs[] , int nrhs, const mxArray *prhs[] )

{
    
    
    double *TXpoint , *RXpoint , *planes , *material;
    
    double fc , flp_scale;
    
    int    nr , Nt , Nr;
    
    double *rs_amp;
    
    
    
    
    double *rpath1=NULL , *rpath2=NULL , *rpath3=NULL;
    
    double *path0=NULL , *path1=NULL , *path2=NULL , *path3=NULL;
    
    double temp;
    
    
    int nplanes , i , j , k , l , n , id , jd , kd , indice , ind , lNr , nNt , ld;
    
    int npath1 , npath2 , npath3 , npath , currentpath  , nb_pts;
    
    
    
    double *TX , *RX , *TX_i , *Phiti , *TX_j , *Phitj , *Phitij , *TX_k , *Phitk , *Phitjk , *Phitijk , *Phit_nt;
    
    double *Thits0=NULL ;
    
    double *Thits11=NULL , *Thits12=NULL;
    
    double *Thits21=NULL , *Thits22=NULL, *Thits23=NULL;
    
    double *Thits31=NULL , *Thits32=NULL, *Thits33=NULL, *Thits34=NULL;
    
    double *distance , *lossfac;
    
    int tflag0 , tflag11 , tflag12 , tflag21 , tflag22 , tflag23 , tflag31 , tflag32 , tflag33 , tflag34;
    
    bool rflagi=false , rflagj=false , rflagij=false , rflagk=false , rflagjk=false , rflagijk=false;
    
    
    
    /* Inputs  */
    
    if( (nrhs <5) || (nrhs >7) )
        
    {
        
        mexErrMsgTxt("At least 5 inputs are requiered for total_power");
        
    }
    
    
    TXpoint    = mxGetPr(prhs[0]);
    
    if( mxGetNumberOfDimensions(prhs[0]) !=2 || mxGetM(prhs[0]) != 3 )
    {
        
        mexErrMsgTxt("TXpoint must be (3 x Nt)");
        
    }
    
    Nt         = mxGetN(prhs[0]);
    
    
    
    RXpoint    = mxGetPr(prhs[1]);
    
    if( mxGetNumberOfDimensions(prhs[1]) !=2 || mxGetM(prhs[1]) != 3 )
    {
        
        mexErrMsgTxt("RXpoint must be (3 x Nr)");
        
    }
    
    Nr         = mxGetN(prhs[1]);
    
    
    
    
    
    planes     = mxGetPr(prhs[2]);
    
    if( mxGetNumberOfDimensions(prhs[2]) !=2 || mxGetM(prhs[2]) !=22 )
    {
        
        mexErrMsgTxt("planes must be (22 x nplanes)");
        
    }
    
    
    
    nplanes     = mxGetN(prhs[2]);
    
    
    material    = mxGetPr(prhs[3]);
    
    if( mxGetNumberOfDimensions(prhs[3]) !=2 || mxGetM(prhs[3]) !=6 )
    {
        
        mexErrMsgTxt("material must be (6 x nplanes)");
        
    }
    
    
    
    
    fc          = mxGetScalar(prhs[4]);
    
    
    if( nrhs > 5)
        
    {
        nr          = (int)mxGetScalar(prhs[5]);
        
        if((nr < 0) || (nr > 3))
        {
            
            
            mexErrMsgTxt("nr must be [0,1,2,3]");
            
        }
        
    }
    
    else
    {
        
        nr = 3;
        
    }
    
    
    if( nrhs > 6)
        
    {
        
        flp_scale = mxGetScalar(prhs[6]);
        
    }
    
    else
        
    {
        
        flp_scale = 100.0;
        
    }
    
    
    /* Memory allocation  */
    
    
    TX                    = mxMalloc(3*sizeof(double));

    RX                    = mxMalloc(3*sizeof(double));

    
    TX_i                  = mxMalloc(3*sizeof(double));
    
    Phiti                 = mxMalloc(3*sizeof(double));
    
    TX_j                  = mxMalloc(3*sizeof(double));
    
    Phitj                 = mxMalloc(3*sizeof(double));
    
    Phitij                = mxMalloc(3*sizeof(double));
    
    TX_k                  = mxMalloc(3*sizeof(double));
    
    Phitk                 = mxMalloc(3*sizeof(double));
    
    Phitjk                = mxMalloc(3*sizeof(double));
    
    Phitijk               = mxMalloc(3*sizeof(double));
    
    Phit_nt               = mxMalloc(3*sizeof(double));
    
    


    /* Outputs  */
            
            
            
	plhs[0]               = mxCreateDoubleMatrix(Nt , Nr, mxREAL);
                     
	rs_amp                = mxGetPr(plhs[0]);


    
    for(l = 0 ; l < Nr ; l++)
    {
        
        lNr = l*3;

		ld  = l*Nt;

		for (i = 0 ; i < 3 ; i++)

		{

			RX[i]   = RXpoint[i + lNr];

		}



        for (n = 0 ; n < Nt ; n++)
        {
           
			nNt = n*3;
			
			for (i = 0 ; i < 3 ; i++)
				
			{
								
				TX[i]   = TXpoint[i + nNt];
				
			}
			
            
            npath1  = npath2 = npath3 = 0;
            
            currentpath = 0;
            
            if(nr > 0)
            {
                
                for (i = 0 ; i < nplanes ; i++)
                    
                {
                    
                    fct_calimage(TX , planes , i , TX_i);
                    
                    rflagi = fct_calrpt(TX_i, RX, planes , i , Phiti);
                    
                    if (rflagi == true)
                    {
                        
                        id             = npath1*5;
                        
                        npath1++;
                        
                        rpath1         = (double *)mxRealloc((double *)rpath1 , (npath1)*5*sizeof(double));
                        
                        rpath1[0 + id] = Phiti[0];
                        
                        rpath1[1 + id] = Phiti[1];
                        
                        rpath1[2 + id] = Phiti[2];
                        
                        rpath1[3 + id] = i;
                        
                        rpath1[4 + id] = 1.0;
                        
                    }
                    
                    if(nr > 1)
                    {
                        
                        for(j = 0 ; j < nplanes ; j++)
                            
                        {
                            if (j != i)
                            {
                                
                                fct_calimage(TX_i , planes , j , TX_j);
                                
                                rflagj = fct_calrpt(TX_j, RX, planes , j , Phitj);
                                
                                if (rflagj == true)
                                {
                                    
                                    rflagij = fct_calrpt(TX_i,  Phitj, planes , i , Phitij);
                                    
                                    if(rflagij == true)
                                    {
                                        jd             = npath2*10;
                                        
                                        npath2++;
                                        
                                        rpath2         = (double *)mxRealloc((double *)rpath2 , (npath2)*10*sizeof(double));
                                        
                                        
                                        rpath2[0 + jd] = Phitij[0];
                                        
                                        rpath2[1 + jd] = Phitij[1];
                                        
                                        rpath2[2 + jd] = Phitij[2];
                                        
                                        rpath2[3 + jd] = i;
                                        
                                        rpath2[4 + jd] = 1.0;
                                        
                                        rpath2[5 + jd] = Phitj[0];
                                        
                                        rpath2[6 + jd] = Phitj[1];
                                        
                                        rpath2[7 + jd] = Phitj[2];
                                        
                                        rpath2[8 + jd] = j;
                                        
                                        rpath2[9 + jd] = 1.0;
                                        
                                    }
                                    
                                }
                                if(nr > 2)
                                {
                                    for (k = 0 ; k < nplanes ; k++)
                                    {
                                        if(k != j)
                                        {
                                            
                                            fct_calimage(TX_j , planes , k , TX_k);
                                            
                                            rflagk = fct_calrpt(TX_k, RX, planes , k , Phitk);
                                            
                                            if(rflagk == true)
                                            {
                                                
                                                rflagjk = fct_calrpt(TX_j, Phitk, planes , j , Phitjk);
                                                
                                                if(rflagjk == true)
                                                {
                                                    
                                                    rflagijk = fct_calrpt(TX_i, Phitjk, planes , i , Phitijk);
                                                    
                                                    if(rflagijk == true)
                                                    {
                                                        kd              = npath3*15;
                                                        
                                                        npath3++;
                                                        
                                                        rpath3          = (double *)mxRealloc((double *)rpath3 , (npath3)*15*sizeof(double));
                                                        
                                                        
                                                        rpath3[0 + kd]  = Phitijk[0];
                                                        
                                                        rpath3[1 + kd]  = Phitijk[1];
                                                        
                                                        rpath3[2 + kd]  = Phitijk[2];
                                                        
                                                        rpath3[3 + kd]  = i;
                                                        
                                                        rpath3[4 + kd]  = 1.0;

⌨️ 快捷键说明

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