Changeset 9489

Show
Ignore:
Timestamp:
07/28/09 11:10:56 (4 years ago)
Author:
hvolos
Message:

component now uses the its properties

Location:
ossiedev/branches/hvolos/components/ChannelMIMO
Files:
3 modified

Legend:

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

    r9450 r9489  
    11/**************************************************************************** 
    22 
    3 Copyright 2009 by your_name_or_organization, all rights reserved. 
    4  
    5 ****************************************************************************/ 
    6  
     3 Copyright 2009 by your_name_or_organization, all rights reserved. 
     4 
     5 ****************************************************************************/ 
    76 
    87#include <string> 
     
    1211 
    1312using namespace arma; 
    14  
    15 ChannelMIMO_i::ChannelMIMO_i(const char *uuid, omni_condition *condition) :  
    16     Resource_impl(uuid), component_running(condition)  
    17 { 
     13ChannelMIMO_i::ChannelMIMO_i(const char *uuid, omni_condition *condition) : 
     14        Resource_impl(uuid), component_running(condition) { 
    1815    dataIn_0 = new standardInterfaces_i::complexShort_p("data_in"); 
    1916    dataOut_0 = new standardInterfaces_i::complexShort_u("data_out"); 
    2017 
    21     //Create the thread for the writer's processing function  
     18    ant_sep=1; 
     19    Mr=1; 
     20    Nt=1; 
     21    noise_sigma=0; 
     22 
     23    //Create the thread for the writer's processing function 
    2224    processing_thread = new omni_thread(Run, (void *) this); 
    2325 
    24     //Start the thread containing the writer's processing function  
     26    //Start the thread containing the writer's processing function 
    2527    processing_thread->start(); 
    2628 
    2729} 
    2830 
    29 ChannelMIMO_i::~ChannelMIMO_i(void) 
    30 {    
     31ChannelMIMO_i::~ChannelMIMO_i(void) { 
    3132    delete dataIn_0; 
    3233    delete dataOut_0; 
    3334} 
    3435 
    35 // Static function for omni thread 
    36 void ChannelMIMO_i::Run( void * data ) 
    37 { 
     36// Static function for omni t hread 
     37void ChannelMIMO_i::Run(void * data) { 
    3838    ((ChannelMIMO_i*)data)->ProcessData(); 
    3939} 
    40  
    41 CORBA::Object_ptr ChannelMIMO_i::getPort( const char* portName ) throw ( 
    42     CORBA::SystemException, CF::PortSupplier::UnknownPort) 
    43 { 
     40CORBA::Object_ptr ChannelMIMO_i::getPort(const char* portName) 
     41throw (CORBA::SystemException, CF::PortSupplier::UnknownPort) { 
    4442    DEBUG(3, ChannelMIMO, "getPort() invoked with " << portName) 
    45      
     43 
    4644    CORBA::Object_var p; 
    4745 
     
    6058} 
    6159 
    62 void ChannelMIMO_i::start() throw (CORBA::SystemException,  
    63     CF::Resource::StartError) 
    64 { 
     60void ChannelMIMO_i::start() throw (CORBA::SystemException, 
     61                                   CF::Resource::StartError) { 
    6562    DEBUG(3, ChannelMIMO, "start() invoked") 
    6663} 
    6764 
    68 void ChannelMIMO_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)  
    69  
    70     DEBUG(3, ChannelMIMO, "stop() invoked") 
    71 } 
    72  
     65void ChannelMIMO_i::stop() throw (CORBA::SystemException, 
     66                                  CF::Resource::StopError) { 
     67    DEBUG(3, ChannelMIMO, "stop() invoke d") 
     68} 
    7369void ChannelMIMO_i::releaseObject() throw (CORBA::SystemException, 
    74     CF::LifeCycle::ReleaseError) 
    75 { 
    76     DEBUG(3, ChannelMIMO, "releaseObject() invoked") 
    77      
    78     component_running->signal(); 
     70        CF::LifeCycle::ReleaseError) { 
     71    DEBUG(3, ChannelMIMO, "relea seObject() invoked") 
     72 
     73    component_running->signal( ); 
    7974} 
    8075 
    8176void ChannelMIMO_i::initialize() throw (CF::LifeCycle::InitializeError, 
    82     CORBA::SystemException) 
    83 { 
    84     DEBUG(3, ChannelMIMO, "initialize() invoked") 
    85 } 
    86  
    87 void ChannelMIMO_i::configure(const CF::Properties& props) 
    88 throw (CORBA::SystemException, 
    89     CF::PropertySet::InvalidConfiguration, 
    90     CF::PropertySet::PartialConfiguration) 
    91 { 
    92     DEBUG(3, ChannelMIMO, "configure() invoked") 
    93      
     77                                        CORBA::SystemException) { 
     78    DEBUG(3, ChannelMIMO, "initialize() invoked ") 
     79} 
     80 
     81void ChannelMIMO_i ::configure(const CF::Properties& props) 
     82throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, 
     83       CF::PropertySet::PartialConfiguration) { 
     84    DEBUG(3 ,ChannelMIMO,"configure() invoked") 
     85 
    9486    std::cout << "props length : " << props.length() << std::endl; 
    9587 
    96     for (unsigned int i = 0; i <props.length(); i++) 
    97     { 
     88    for (unsigned int i = 0; i <props.length(); i++) { 
    9889        std::cout << "Property id : " << props[i].id << std::endl; 
    9990 
    100         if (strcmp(props[i].id, "DCE:3804769a-3dd1-11de-b7e0-00226b9f0fde") == 0) 
    101         { 
    102         } 
    103         } 
    104 } 
    105  
    106 void ChannelMIMO_i::ProcessData() 
    107 { 
     91        if (strcmp(props[i].id, "DCE:3804769a-3dd1-11de-b7e0-00226b9f0fde")== 0) { 
     92            //The power of the AWGN noise 
     93            CORBA::Long simple_temp; 
     94            props[i].value >>= simple_temp; 
     95            noise_sigma = sqrt(simple_temp/2.0); 
     96        } else if (strcmp(props[i].id, "DCE:9192e75a-3dd1-11de-b7e0-00226b9f0fde") == 0) { 
     97            // min antenna separation distance 
     98            CORBA::Double simple_temp; 
     99            props[i].value >>= simple_temp; 
     100            ant_sep=simple_temp; 
     101        } else if (strcmp(props[i].id, "DCE:6ea173f7-5bfe-4853-b4fa-81134c9f200a") == 0) { 
     102            CORBA::Short simple_temp; 
     103            props[i].value >>= simple_temp; 
     104            Nt = simple_temp; 
     105        } else if (strcmp(props[i].id, "DCE:9fb3dc68-d118-4aab-b344-2e10462c9da6") == 0) { 
     106            CORBA::Short simple_temp; 
     107            props[i].value >>= simple_temp; 
     108            Mr = simple_temp; 
     109        } 
     110 
     111    } 
     112} 
     113 
     114void ChannelMIMO_i::ProcessData() { 
    108115    DEBUG(3, ChannelMIMO, "ProcessData() invoked") 
    109116 
    110117    PortTypes::ShortSequence I_out, Q_out; 
    111118 
    112  
    113119    PortTypes::ShortSequence *I_in(NULL), *Q_in(NULL); 
    114     short int Nin, NH;  
    115  
    116     while(1) 
    117     { 
     120    short int Nin, NH; 
     121 
     122    while (1) { 
    118123        dataIn_0->getData(I_in, Q_in); 
    119          
     124 
    120125        Nin = I_in->length(); 
    121         NH=4; 
    122          
    123  
     126        NH=Mr*Nt; //Number of samples needed for channel info 
    124127 
    125128        I_out.length(Nin+NH); //must define length of output 
    126         Q_out.length(Nin+NH); //must define length of output 
     129        Q_out.length(Nin/Nt*Mr+NH); //must define length of output 
    127130 
    128131        /*insert code here to do work*/ 
    129          
    130         cx_mat indata(Nin/2,2); 
    131         cx_mat outdata(Nin/2,2); 
    132          
    133  
    134          
    135          
     132 
     133        cx_mat indata(Nin/Nt, Nt); 
     134        cx_mat outdata(Nin/Nt, Mr); 
     135 
    136136        int j=0; 
    137         for (int i=0;i<Nin;i+=2) 
    138         { 
    139          
    140         indata(j,0)=cx_double((*I_in)[i],(*Q_in)[i]); 
    141         indata(j,1)=cx_double((*I_in)[i+1],(*Q_in)[i+1]); 
    142         j++; 
    143         } 
    144          
    145         cx_mat H(2,2); 
    146         H=generateH(2,2,3.914); 
     137        for (int i=0; i<Nin; i+=Nt) { 
     138            for (int k=0;k<Nt;k++) { 
     139                indata(j, k)=cx_double((*I_in)[i+k], (*Q_in)[i+k]); 
     140                j++; 
     141            } 
     142        } 
     143 
     144        cx_mat H(Mr, Nt); 
     145        H=generateH(Mr, Nt, ant_sep); 
    147146        //cx_mat H(eye(2,2),zeros(2,2)); 
    148         outdata=indata*H;  
    149          
     147        outdata=indata*H; 
     148 
    150149        //std::cout<<outdata; 
    151               //std::cout<<"Hch="<<H; 
    152         for (int i=0;i<2;i++){ 
    153                 for (int j=0;j<2;j++){ 
    154                 I_out[i*2+j]=(CORBA::Short)(real(H(i,j))*1e4); 
    155                 Q_out[i*2+j]=(CORBA::Short)(imag(H(i,j))*1e4); 
    156                 } 
    157         } 
    158          
     150        //std::cout<<"Hch="<<H; 
     151        //Add channel info 
     152        for (int i=0; i<Mr; i++) { 
     153            for (int j=0; j<Nt; j++) { 
     154                I_out[i*2+j]=(CORBA::Short)(real(H(i, j))*1e4); 
     155                Q_out[i*2+j]=(CORBA::Short)(imag(H(i, j))*1e4); 
     156            } 
     157        } 
     158 
    159159        j=0; 
    160         for (int i=0;i<Nin;i+=2) 
    161         { 
    162         I_out[i+NH]=(CORBA::Short)real(outdata(j,0)); 
    163         Q_out[i+NH]=(CORBA::Short)imag(outdata(j,0)); 
    164         I_out[i+1+NH]=(CORBA::Short)real(outdata(j,1)); 
    165         Q_out[i+1+NH]=(CORBA::Short)imag(outdata(j,1)); 
    166         j++; 
    167          
    168         } 
    169          
     160        for (int i=0; i<Nin; i+=Nt) { 
     161            for (int k=0;k<Mr;k++) { 
     162                I_out[i+NH+k]=(CORBA::Short)real(outdata(j, k)); 
     163                Q_out[i+NH+k]=(CORBA::Short)imag(outdata(j, k)); 
     164                j++; 
     165            } 
     166 
     167        } 
     168 
    170169        dataIn_0->bufferEmptied(); 
    171170        dataOut_0->pushPacket(I_out, Q_out); 
     
    173172} 
    174173 
    175 cx_mat ChannelMIMO_i::generateH(int Nr, int Nt, double ant_spacing_in_wvlenths) 
    176 { 
    177   cx_mat H(Nr,Nt); 
    178   cx_mat Hw(Nr,Nt); 
    179   cx_mat Rrx_mat(Nr,Nr); 
    180   cx_mat Rtx_mat(Nt,Nt); 
    181    
    182   Rrx_mat=make_Rmatrix(Nr,ant_spacing_in_wvlenths); 
    183   Rtx_mat=make_Rmatrix(Nt,ant_spacing_in_wvlenths); 
    184   Hw=randn_mat(Nr,Nt)/sqrt(2); 
    185    
    186   H=sqrtm(Rrx_mat)*Hw*sqrtm(Rtx_mat); 
    187    
    188   return H; 
    189  
    190 } 
    191  
    192 cx_mat ChannelMIMO_i::randn_mat(int rows, int cols) 
    193 { 
    194         cx_mat Rn(rows,cols); 
    195          
    196         for (int i=0;i<rows;i++){ 
    197                 for (int j=0;j<cols;j++){ 
    198                 Rn(i,j)=cx_double(randn(),randn()); 
    199                  
    200                 } 
    201           } 
    202  
    203         return Rn; 
    204 } 
    205  
     174cx_mat ChannelMIMO_i::generateH(int Nr, int Nt, double ant_spacing_in_wvlenths) { 
     175    cx_mat H(Nr, Nt); 
     176    cx_mat Hw(Nr, Nt); 
     177    cx_mat Rrx_mat(Nr, Nr); 
     178    cx_mat Rtx_mat(Nt, Nt); 
     179 
     180    Rrx_mat=make_Rmatrix(Nr, ant_spacing_in_wvlenths); 
     181    Rtx_mat=make_Rmatrix(Nt, ant_spacing_in_wvlenths); 
     182    Hw=randn_mat(Nr, Nt)/sqrt(2); 
     183 
     184    H=sqrtm(Rrx_mat)*Hw*sqrtm(Rtx_mat); 
     185 
     186    return H; 
     187 
     188} 
     189 
     190cx_mat ChannelMIMO_i::randn_mat(int rows, int cols) { 
     191    cx_mat Rn(rows, cols); 
     192 
     193    for (int i=0; i<rows; i++) { 
     194        for (int j=0; j<cols; j++) { 
     195            Rn(i, j)=cx_double(randn(),randn()); 
     196 
     197        } 
     198    } 
     199 
     200    return Rn; 
     201} 
    206202 
    207203double ChannelMIMO_i::randn() 
    208204//Generates a Gaussian distributed number with zero mean and unit standard deviation 
    209 // Adapted from http://www.taygeta.com/random/gaussian.html 
     205// Adapted from http://www.taygeta.com/rand om/gaussian.html 
    210206// Algorithm bny Dr. Everett (Skip) Carter, Jr 
    211207{ 
    212 double x1,x2,w; 
    213     do 
    214     { 
     208    double x1, x2, w; 
     209    do { 
    215210        x1=2.0*randd()-1.0; 
    216211        x2=2.0*randd()-1.0; 
    217212        w=x1*x1+x2*x2; 
    218213 
    219     }while (w>=1.0); 
     214    } while (w>=1.0); 
    220215 
    221216    w=sqrt((-2.0*log(w))/w); 
     
    231226} 
    232227 
    233 cx_mat ChannelMIMO_i::make_Rmatrix(int antennas_no,double ant_spacing_in_wvlenths) 
    234 { 
    235  
    236         cx_mat R(antennas_no,antennas_no); 
    237         R.fill(0); 
    238  
    239         /** 
    240         Rrx=zeros(Nr); 
    241         for ant1=1:Nr, 
    242                 for ant2=1:Nr, 
    243                 dl=antspacingrx*(ant1-ant2); 
    244                 %Gaussian aoa corr at rx 
    245                 Rrx(ant1,ant2)=... 
    246                 exp(j*2*pi()*dl*sin(aoamean))... 
    247                 .*exp(-0.5*(2*pi()*dl*aoastd*cos(aoamean)).^2);  
    248          
    249                 end 
    250         end 
    251         **/ 
    252         double dl; 
    253         cx_double r; 
    254         double pi=3.1415926535897932384626433832795; 
    255         double aoamean=(0.0/180)*pi; 
    256         double aoastd=(0.5/180)*pi; 
    257          
    258         for (int ant1=0;ant1<antennas_no;ant1++) { 
    259                 for (int ant2=0;ant2<antennas_no;ant2++) { 
    260                       dl=ant_spacing_in_wvlenths*(ant1-ant2); 
    261                       r=exp(cx_double(0,1)*cx_double(2.0*pi*dl*sin(aoamean),0)); 
    262                       r*=cx_double(exp(-0.5*pow(2*pi*dl*aoastd*cos(aoamean),2)),0); 
    263                       R(ant1,ant2)=r; 
    264                 } 
    265         } 
    266  
    267         return R; 
    268 } 
    269    
    270    
    271 cx_mat ChannelMIMO_i::sqrtm(cx_mat Y) 
    272 { 
    273   //Computes the square root of a matrix 
    274    
    275   int rows=0; 
    276   int cols=0; 
    277   rows=Y.n_rows; 
    278   cols=Y.n_cols; 
    279   cx_mat Z=eye<cx_mat>(rows,cols); 
    280    
    281   cx_mat Yn(rows,cols); 
    282   cx_mat Zn(rows,cols); 
    283    
    284   Yn=0.5*(Y+inv(Z)); 
    285   Zn=0.5*(Z+inv(Y)); 
    286    
    287   while ( abs(sum(sum(Yn-Y)))>0.00001){ 
    288   Y=Yn; 
    289   Z=Zn; 
    290    
    291   Yn=0.5*(Y+inv(Z)); 
    292   Zn=0.5*(Z+inv(Y)); 
    293   } 
    294   Y=Yn; 
    295   //Z=Zn; 
    296    
    297   return Y; 
    298  
    299 } 
    300  
     228cx_mat ChannelMIMO_i::make_Rmatrix(int antennas_no, 
     229                                   double               ant_spacing_in_wvlenths) { 
     230 
     231    cx_mat R(antennas_no, antennas_no); 
     232    R.fill(0); 
     233 
     234    /** 
     235     Rrx=zeros(Nr); 
     236     for ant1=1:Nr, 
     237     for ant2=1:Nr, 
     238     dl=antspacingrx*(ant1-ant2); 
     239     %Gaussian aoa corr at rx 
     240         Rrx(ant1,ant2)=... 
     241             exp(j*2* pi()*dl*sin(aoamean))... 
     242                 .*exp(-0.5*(2*pi()*dl*aoastd*cos(aoamean)).^2); 
     243 
     244                 end 
     245                     end 
     246                     **/ 
     247    double dl; 
     248    cx_double r; 
     249    double pi=3.1415926535897932384626433832795; 
     250    double aoamean=(0.0/180)*pi; 
     251    double aoastd=(0.5/180)*pi; 
     252 
     253    for (int ant1=0; ant1<antennas_no; ant1++) { 
     254        for (int ant2=0; ant2<antennas_no; ant2++) { 
     255            dl=ant_spacing_in_wvlenths*(ant1-ant2); 
     256            r=exp(cx_double(0, 1)*cx_double(2.0*pi*dl*sin(aoamean), 0)); 
     257            r*=cx_double(exp(-0.5*pow(2*pi*dl*aoastd*cos(aoamean), 2)), 0); 
     258            R(ant1, ant2)=r; 
     259        } 
     260    } 
     261 
     262    return R; 
     263} 
     264 
     265cx_mat ChannelMIMO_i::sqrtm(cx_mat Y) { 
     266    //Computes the square root of a matrix 
     267 
     268    int rows=0; 
     269    int cols=0; 
     270    rows=Y.n_rows; 
     271    cols=Y.n_cols; 
     272    cx_mat Z=eye<cx_mat>(rows, cols); 
     273 
     274    cx_mat Yn(rows, cols); 
     275    cx_mat Zn(rows, cols); 
     276 
     277    Yn=0.5*(Y+inv(Z)); 
     278    Zn=0.5*(Z+inv(Y)); 
     279 
     280    while (abs(sum(sum(Yn-Y)))>0.00001) { 
     281        Y=Yn; 
     282        Z=Zn; 
     283 
     284        Yn=0.5*(Y+inv(Z)); 
     285        Zn=0.5*(Z+inv(Y)); 
     286    } 
     287    Y=Yn; 
     288    //Z=Zn; 
     289 
     290    return Y; 
     291 
     292} 
     293 
  • ossiedev/branches/hvolos/components/ChannelMIMO/ChannelMIMO.h

    r9383 r9489  
    2525 */ 
    2626 using namespace arma; 
    27   
     27 
    2828class ChannelMIMO_i : public virtual Resource_impl 
    2929{ 
     
    7070    /// Main signal processing method 
    7171    void ProcessData(); 
    72     
     72 
    7373    omni_condition *component_running;  ///< for component shutdown 
    7474    omni_thread *processing_thread;     ///< for component writer function 
    75          
     75 
    7676        CORBA::Long simple_0_value; 
    7777        CORBA::Short simple_1_value; 
    7878 
    79      
     79 
    8080    // list components provides and uses ports 
    8181        standardInterfaces_i::complexShort_p *dataIn_0; 
    8282        standardInterfaces_i::complexShort_u *dataOut_0; 
    83          
     83 
    8484        double randd(); 
    8585        double randn(); 
     86        double ant_sep; 
     87        short int Mr,Nt; 
     88        long int noise_sigma; 
    8689        cx_mat randn_mat(int rows, int cols); 
    8790        cx_mat sqrtm(cx_mat Y); 
  • ossiedev/branches/hvolos/components/ChannelMIMO/ChannelMIMO.prf.xml

    r9341 r9489  
    44<!--Powered by Python--> 
    55<properties> 
    6     <description>These are the properties to configure the device manager</description>  
     6    <description>These are the properties to configure the device manager</description> 
    77    <simple id="DCE:3804769a-3dd1-11de-b7e0-00226b9f0fde" mode="readonly" name="Noise Power" type="long"> 
    8         <value>10000</value>  
    9         <description>The power of AGWN noise</description>  
     8        <value>10000</value> 
     9        <description>The power of AGWN noise</description> 
    1010        <kind kindtype="configure"/> 
    1111    </simple> 
    12     <simple id="DCE:9192e75a-3dd1-11de-b7e0-00226b9f0fde" mode="readonly" name="Antenna Separation Distance" type="short"> 
    13         <value>0.5</value>  
    14         <description>The min. antenna separation in terms of wavelength</description>  
     12    <simple id="DCE:9192e75a-3dd1-11de-b7e0-00226b9f0fde" mode="readonly" name="Antenna Separation Distance (in wavelengths)" type="double"> 
     13        <value>3.914</value> 
     14        <description>The min. antenna separation in terms of wavelength</description> 
     15        <kind kindtype="configure"/> 
     16    </simple> 
     17        <simple id="DCE:6ea173f7-5bfe-4853-b4fa-81134c9f200a" mode="readonly" name="No of TX Antennas" type="short"> 
     18        <value>2</value> 
     19        <description>Specifies the number of TX antennas (Going "In" to this component).</description> 
     20        <kind kindtype="configure"/> 
     21    </simple> 
     22    <simple id="DCE:9fb3dc68-d118-4aab-b344-2e10462c9da6" mode="readonly" name="No of RX Antennas" type="short"> 
     23        <value>2</value> 
     24        <description>The number of RX Antennas (Going "Out" of this component)</description> 
    1525        <kind kindtype="configure"/> 
    1626    </simple> 
    1727    <simplesequence id="port_list" mode="readonly" name="port_list" type="string"> 
    18         <description>Returns a sequence of strings with the names of the available Provides ports</description>  
     28        <description>Returns a sequence of strings with the names of the available Provides ports</description> 
    1929        <kind kindtype="configure"/> 
    2030        <values> 
    21             <value>data_in::standardInterfaces.complexShort</value>  
     31            <value>data_in::standardInterfaces.complexShort</value> 
    2232        </values> 
    2333    </simplesequence>