Changeset 9702

Show
Ignore:
Timestamp:
11/04/09 21:45:56 (4 years ago)
Author:
hvolos
Message:

improved VBLAST

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • ossiedev/branches/hvolos/components/MIMODec/MIMODec.cpp

    r9699 r9702  
    187187        cx_mat H(Mr,Nt); //Channel Matrix 
    188188        //std::cout<<NH<<","<<Mr<<"X"<<Nt<<" M:"<< MIMOmethod<<" DL:"<<Data_length<<std::endl; 
     189        short int k=0; 
    189190        for (int i=0;i<Mr;i++) { 
    190191            for (int j=0;j<Nt;j++) { 
    191                 H(i,j)=cx_double((*I_in)[i*Mr+j],(*Q_in)[i*Mr+j])/10000.0; 
     192                H(i,j)=cx_double((*I_in)[k],(*Q_in)[k])/1e4; 
     193                k++; 
    192194                //std::cout<<"Iin:"<<(*I_in)[i*Mr+j]<<"  "; 
    193195                //std::cout<<"H("<<i<<","<<j<<")="<<H(i,j)<<"  "; 
    194196            } 
    195197        } 
    196         //std::cout<<std::endl; 
     198        //std::cout<<"H:"<<H<<std::endl; 
    197199 
    198200        cx_double r1; 
     
    210212            break; 
    211213        case 2: 
    212             OutData_length=(Data_length-NH); 
     214            OutData_length=(Data_length-NH)*Nt/Mr; 
    213215            std::cout<<"MIMODec VBLAST:"; 
    214216            break; 
     
    223225 
    224226 
    225  
    226         short int j; 
    227         j=0; 
     227        short int j=0; 
     228 
    228229        switch (MIMOmethod) { 
    229230        case 0: //MRC 
     231            /** 
     232                j=0; 
     233 
     234                for (short int i=NH; i<Data_length;i+=Mr) { 
     235                    // std::cout<<i<<","<<j; 
     236                    rx_symbols(j,0)=0; 
     237 
     238                    for (short int k=0;k<Mr;k++) { 
     239                        r1=cx_double((*I_in)[i+k],(*Q_in)[i+k]); 
     240                        rx_symbols(j,0)+=r1*conj(H(k,0)); 
     241                        //  std::cout<<","<<k; 
     242                    } 
     243                    //std::cout<<std::endl; 
     244 
     245                    j+=1; 
     246                } 
     247                **/ 
    230248        { 
    231249            cx_mat rx(Mr,OutData_length); 
     
    244262            j=0; 
    245263            for (short int i=NH; i<Data_length;i+=Mr) { 
    246                  //std::cout<<i<<", j"<<j; 
     264                //std::cout<<i<<", j"<<j; 
    247265 
    248266                for (short int k=0;k<Mr;k++) { 
     
    255273            //std::cout<<"rx:"<<rx<<std::endl; 
    256274            scale=(htrans(h)*h); 
     275            //std::cout<<"Scale:"<<scale<<std::endl; 
    257276 
    258277            rx_symbols=htrans(h)*rx/1; 
     
    261280        } 
    262281 
    263             break; 
     282        break; 
    264283        case 1: //STBC Alamouti 2x 
    265284            j=0; 
     
    283302        case 2: //VBLAST 
    284303 
    285             if (!(Mr==Nt)||!(Mr==2)) { 
    286                 std::cout<<"Temporarily only 2x2 VBLAST is supported"<<std::endl; 
     304            cx_mat r(Mr,OutData_length/Nt); 
     305            cx_mat z(1,OutData_length/Nt); 
     306            cx_mat s(1,OutData_length/Nt); 
     307 
     308 
     309            cx_mat T(Nt,Mr); 
     310            cx_mat w(1,Mr); 
     311            T.zeros(); 
     312 
     313 
     314 
     315 
     316            //Computer pseudo-inverse (Moore-Penrose method) 
     317 
     318            T=inv(htrans(H)*H)*htrans(H); 
     319           // std::cout<<"H:"<<H<<std::endl; 
     320           // std::cout<<"T:"<<T<<std::endl; 
     321            //std::cout<<"HTH"<<H*T*H<<std::endl; 
     322 
     323            double n,nmax; 
     324            short I,Q,sno; 
     325            short int k,k2,st; 
     326 
     327            st=0; 
     328            for (short int i=NH; i<Data_length;i+=Mr) { 
     329                for (short int l=0;l<Mr;l++) r(l,st)=cx_double((*I_in)[i+l],(*Q_in)[i+l]); 
     330                st++; 
     331            }; 
     332 
     333            nmax=-1; 
     334            for (k2=0;k2<Nt;k2++) { 
     335                 //if (k2>0) { 
     336                T=pinv(H); 
     337                //std::cout<<"T:"<<T<<std::endl; 
     338               // std::cout<<"HTH"<<H*T*H<<std::endl; 
     339                //} 
     340                k=k2; 
     341                nmax=-1; 
     342                for (short int i=0;i<Nt;i++) { 
     343                    w=T.row(i); 
     344                    n= norm(abs(w),2); 
     345                    if (n>nmax) { 
     346                        nmax=n; 
     347                        k=i; 
     348                        //std::cout<<"k:"<<k<<" nmax:"<<nmax<<std::endl; 
     349                    } 
     350                } 
     351 
     352                w=T.row(k); 
     353                //std::cout<<"w:"<<w<<std::endl; 
     354                z=w*r; 
     355                //std::cout<<"z:"<<z<<std::endl; 
     356                //  std::cout<<" z=w*r;"<<std::endl; 
     357 
     358                for (short int i=0;i<(OutData_length/Nt);i++) { 
     359                    SigProc::DemodulateQPSK((short)(real(z(0,i))),(short)(imag(z(0,i))),sno); 
     360                    SigProc::ModulateQPSK(sno,I,Q); 
     361                    //std::cout<<"sno:"<<sno<<" I,Q:"<<I<<","<<Q<<std::endl; 
     362                    s(0,i)=cx_double(I,Q)*0.989/sqrt(Nt); 
     363                } 
     364                // std::cout<<" s size:"<<s.n_elem<<"s:"<<s<<std::endl; 
     365                r=r-H.col(k)*s; 
     366                //std::cout<<" r="<<H.col(k)*s<<std::endl; 
     367                //std::cout<<"r"<<r<<std::endl; 
     368                //std::cout<<"H.col:"<<H.col(k)<<std::endl; 
     369                //std::cout<<"zeros"<<zeros<cx_colvec>(Mr)<<std::endl; 
     370                H.col(k)=zeros<cx_colvec>(Mr); 
     371 
     372               // std::cout<<"H"<<H<<std::endl; 
     373 
     374                //std::cout<<"rx_index:"<<(i-NH)/Mr+k<<" , i="<<i<<" ,k="<<k<<" ,st="<<st<<std::endl; 
     375                st=0; 
     376                for (short int i=k;i<OutData_length;i+=Nt) { 
     377                    rx_symbols(i,0)=z(0,st); 
     378                    st++; 
     379                    // std::cout<<"i:"<<i<<std::endl; 
     380                } 
     381 
     382 
     383            } 
     384 
     385 
     386 
     387            /** 
     388 
     389                    if (!(Mr==Nt)||!(Mr==2)){ 
     390                    std::cout<<"Temporarily only 2x2 VBLAST is supported"<<std::endl; 
    287391                throw(0); 
    288             } 
    289  
    290  
    291             cx_mat r(Mr,1); 
    292  
    293             cx_mat T0(Nt,Mr); 
    294             cx_mat T(Nt,Mr); 
    295             cx_rowvec w; 
    296             T.zeros(); 
    297  
    298             //Computer pseudo-inverse (Moore-Penrose method) 
    299             T=conj(H)*inv(H*conj(H)); 
    300             //std::cout<<"H:"<<H<<std::endl; 
    301             //std::cout<<"T:"<<T<<std::endl; 
    302  
    303             double n,nmin; 
    304             cx_mat z(1,1),s(1,1); 
    305             short I,Q,sno; 
    306  
    307             n=0; 
    308             nmin=0; 
    309             short int k; 
    310  
    311             //n=norm(abs(w),2); 
    312             //std::cout<<"k:"<<k<<" n:"<<n<<std::endl; 
    313             mat sicorder(Mr,2); 
    314             sicorder.zeros(); 
    315  
    316             for (k=0;k<Mr;k++) { 
    317                 w=T.row(k); 
    318                 sicorder(k,0)=norm(abs(w),2); 
    319                 sicorder(k,1)=k; 
    320             } 
    321  
    322             short int l,l2,l2p,k2; 
    323             for (k=0;k<Mr-1;k++) { 
    324                 for (l=0;l<(Mr-k-1);l++) { 
    325                     l2=sicorder(l,1); 
    326                     l2p=sicorder(l+1,1); 
    327                     if (sicorder(l2,0)<sicorder(l2p,0)) { 
    328                         sicorder(l,1)=l2p; 
    329                         sicorder(l+1,1)=l2; 
    330392                    } 
    331                 } 
    332             } 
    333  
    334             // std::cout<<"sicorder:"<<sicorder<<std::endl; 
    335  
    336  
    337  
    338  
    339             for (short int i=NH; i<Data_length;i+=Mr) { 
    340                 for (short int l=0;l<Mr;l++) r(l,0)=cx_double((*I_in)[i+l],(*Q_in)[i+l]); 
    341                 for (k2=0;k2<Mr;k2++) { 
    342                     k=sicorder(k2,1); 
    343                     //T=pinv(H); 
    344  
    345                     w=T.row(k); 
    346                     //std::cout<<"w:"<<w<<std::endl; 
    347                     z=w*r; 
    348                     //std::cout<<"z:"<<z<<std::endl; 
    349                     SigProc::DemodulateQPSK((short)(real(z(0,0))),(short)(imag(z(0,0))),sno); 
    350                     SigProc::ModulateQPSK(sno,I,Q); 
    351                     //std::cout<<"sno:"<<sno<<std::endl; 
    352                     s=cx_double(I,Q)/sqrt(Nt)*0.7;; 
    353                     r=r-H.col(k)*s; 
    354                     //std::cout<<"r"<<r<<std::endl; 
    355                     //H.col(k)=zeros<cx_colvec>(1,Nt); 
    356                     rx_symbols(i+k-NH,0)=z(0,0); 
    357  
    358                 } 
    359  
    360  
    361             } 
    362  
     393                        cx_mat r(Mr,1); 
     394 
     395                        cx_mat T0(Nt,Mr); 
     396                        cx_mat T(Nt,Mr); 
     397                        cx_rowvec w; 
     398                        T.zeros(); 
     399 
     400                        //Computer pseudo-inverse (Moore-Penrose method) 
     401                        T=conj(H)*inv(H*conj(H)); 
     402                        //std::cout<<"H:"<<H<<std::endl; 
     403                        //std::cout<<"T:"<<T<<std::endl; 
     404 
     405                        double n,nmin; 
     406                        cx_mat z(1,1),s(1,1); 
     407                        short I,Q,sno; 
     408 
     409                        n=0; 
     410                        nmin=0; 
     411                        short int k; 
     412 
     413                        //n=norm(abs(w),2); 
     414                        //std::cout<<"k:"<<k<<" n:"<<n<<std::endl; 
     415                        mat sicorder(Mr,2); 
     416                        sicorder.zeros(); 
     417 
     418                        for (k=0;k<Mr;k++) { 
     419                            w=T.row(k); 
     420                            sicorder(k,0)=norm(abs(w),2); 
     421                            sicorder(k,1)=k; 
     422                        } 
     423 
     424                        short int l,l2,l2p,k2; 
     425                        for (k=0;k<Mr-1;k++) { 
     426                            for (l=0;l<(Mr-k-1);l++) { 
     427                                l2=sicorder(l,1); 
     428                                l2p=sicorder(l+1,1); 
     429                                if (sicorder(l2,0)<sicorder(l2p,0)){ 
     430                                    sicorder(l,1)=l2p; 
     431                                    sicorder(l+1,1)=l2; 
     432                                } 
     433                            } 
     434                        } 
     435 
     436                       // std::cout<<"sicorder:"<<sicorder<<std::endl; 
     437 
     438 
     439 
     440 
     441                        for (short int i=NH; i<Data_length;i+=Mr) { 
     442                            for (short int l=0;l<Mr;l++) r(l,0)=cx_double((*I_in)[i+l],(*Q_in)[i+l]); 
     443                            for (k2=0;k2<Mr;k2++) { 
     444                                k=sicorder(k2,1); 
     445                                //T=pinv(H); 
     446 
     447                                w=T.row(k); 
     448                                //std::cout<<"w:"<<w<<std::endl; 
     449                                z=w*r; 
     450                                //std::cout<<"z:"<<z<<std::endl; 
     451                                SigProc::DemodulateQPSK((short)(real(z(0,0))),(short)(imag(z(0,0))),sno); 
     452                                SigProc::ModulateQPSK(sno,I,Q); 
     453                                //std::cout<<"sno:"<<sno<<std::endl; 
     454                                s=cx_double(I,Q)/sqrt(Nt)*0.7;; 
     455                                r=r-H.col(k)*s; 
     456                                //std::cout<<"r"<<r<<std::endl; 
     457                                //H.col(k)=zeros<cx_colvec>(1,Nt); 
     458                                rx_symbols(i+k-NH,0)=z(0,0); 
     459 
     460                            } 
     461 
     462 
     463                        } 
     464            **/ 
    363465            break; 
    364466        }