Changeset 9489
- Timestamp:
- 07/28/09 11:10:56 (4 years ago)
- Location:
- ossiedev/branches/hvolos/components/ChannelMIMO
- Files:
-
- 3 modified
-
ChannelMIMO.cpp (modified) (5 diffs)
-
ChannelMIMO.h (modified) (2 diffs)
-
ChannelMIMO.prf.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ossiedev/branches/hvolos/components/ChannelMIMO/ChannelMIMO.cpp
r9450 r9489 1 1 /**************************************************************************** 2 2 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 ****************************************************************************/ 7 6 8 7 #include <string> … … 12 11 13 12 using namespace arma; 14 15 ChannelMIMO_i::ChannelMIMO_i(const char *uuid, omni_condition *condition) : 16 Resource_impl(uuid), component_running(condition) 17 { 13 ChannelMIMO_i::ChannelMIMO_i(const char *uuid, omni_condition *condition) : 14 Resource_impl(uuid), component_running(condition) { 18 15 dataIn_0 = new standardInterfaces_i::complexShort_p("data_in"); 19 16 dataOut_0 = new standardInterfaces_i::complexShort_u("data_out"); 20 17 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 22 24 processing_thread = new omni_thread(Run, (void *) this); 23 25 24 //Start the thread containing the writer's processing function 26 //Start the thread containing the writer's processing function 25 27 processing_thread->start(); 26 28 27 29 } 28 30 29 ChannelMIMO_i::~ChannelMIMO_i(void) 30 { 31 ChannelMIMO_i::~ChannelMIMO_i(void) { 31 32 delete dataIn_0; 32 33 delete dataOut_0; 33 34 } 34 35 35 // Static function for omni thread 36 void ChannelMIMO_i::Run( void * data ) 37 { 36 // Static function for omni t hread 37 void ChannelMIMO_i::Run(void * data) { 38 38 ((ChannelMIMO_i*)data)->ProcessData(); 39 39 } 40 41 CORBA::Object_ptr ChannelMIMO_i::getPort( const char* portName ) throw ( 42 CORBA::SystemException, CF::PortSupplier::UnknownPort) 43 { 40 CORBA::Object_ptr ChannelMIMO_i::getPort(const char* portName) 41 throw (CORBA::SystemException, CF::PortSupplier::UnknownPort) { 44 42 DEBUG(3, ChannelMIMO, "getPort() invoked with " << portName) 45 43 46 44 CORBA::Object_var p; 47 45 … … 60 58 } 61 59 62 void ChannelMIMO_i::start() throw (CORBA::SystemException, 63 CF::Resource::StartError) 64 { 60 void ChannelMIMO_i::start() throw (CORBA::SystemException, 61 CF::Resource::StartError) { 65 62 DEBUG(3, ChannelMIMO, "start() invoked") 66 63 } 67 64 68 void ChannelMIMO_i::stop() throw (CORBA::SystemException, CF::Resource::StopError) 69 { 70 DEBUG(3, ChannelMIMO, "stop() invoked") 71 } 72 65 void ChannelMIMO_i::stop() throw (CORBA::SystemException, 66 CF::Resource::StopError) { 67 DEBUG(3, ChannelMIMO, "stop() invoke d") 68 } 73 69 void 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( ); 79 74 } 80 75 81 76 void 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 81 void ChannelMIMO_i ::configure(const CF::Properties& props) 82 throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, 83 CF::PropertySet::PartialConfiguration) { 84 DEBUG(3 ,ChannelMIMO,"configure() invoked") 85 94 86 std::cout << "props length : " << props.length() << std::endl; 95 87 96 for (unsigned int i = 0; i <props.length(); i++) 97 { 88 for (unsigned int i = 0; i <props.length(); i++) { 98 89 std::cout << "Property id : " << props[i].id << std::endl; 99 90 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 114 void ChannelMIMO_i::ProcessData() { 108 115 DEBUG(3, ChannelMIMO, "ProcessData() invoked") 109 116 110 117 PortTypes::ShortSequence I_out, Q_out; 111 118 112 113 119 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) { 118 123 dataIn_0->getData(I_in, Q_in); 119 124 120 125 Nin = I_in->length(); 121 NH=4; 122 123 126 NH=Mr*Nt; //Number of samples needed for channel info 124 127 125 128 I_out.length(Nin+NH); //must define length of output 126 Q_out.length(Nin +NH); //must define length of output129 Q_out.length(Nin/Nt*Mr+NH); //must define length of output 127 130 128 131 /*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 136 136 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); 147 146 //cx_mat H(eye(2,2),zeros(2,2)); 148 outdata=indata*H; 149 147 outdata=indata*H; 148 150 149 //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 159 159 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 170 169 dataIn_0->bufferEmptied(); 171 170 dataOut_0->pushPacket(I_out, Q_out); … … 173 172 } 174 173 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 174 cx_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 190 cx_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 } 206 202 207 203 double ChannelMIMO_i::randn() 208 204 //Generates a Gaussian distributed number with zero mean and unit standard deviation 209 // Adapted from http://www.taygeta.com/rand om/gaussian.html205 // Adapted from http://www.taygeta.com/rand om/gaussian.html 210 206 // Algorithm bny Dr. Everett (Skip) Carter, Jr 211 207 { 212 double x1,x2,w; 213 do 214 { 208 double x1, x2, w; 209 do { 215 210 x1=2.0*randd()-1.0; 216 211 x2=2.0*randd()-1.0; 217 212 w=x1*x1+x2*x2; 218 213 219 } while (w>=1.0);214 } while (w>=1.0); 220 215 221 216 w=sqrt((-2.0*log(w))/w); … … 231 226 } 232 227 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 228 cx_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 265 cx_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 25 25 */ 26 26 using namespace arma; 27 27 28 28 class ChannelMIMO_i : public virtual Resource_impl 29 29 { … … 70 70 /// Main signal processing method 71 71 void ProcessData(); 72 72 73 73 omni_condition *component_running; ///< for component shutdown 74 74 omni_thread *processing_thread; ///< for component writer function 75 75 76 76 CORBA::Long simple_0_value; 77 77 CORBA::Short simple_1_value; 78 78 79 79 80 80 // list components provides and uses ports 81 81 standardInterfaces_i::complexShort_p *dataIn_0; 82 82 standardInterfaces_i::complexShort_u *dataOut_0; 83 83 84 84 double randd(); 85 85 double randn(); 86 double ant_sep; 87 short int Mr,Nt; 88 long int noise_sigma; 86 89 cx_mat randn_mat(int rows, int cols); 87 90 cx_mat sqrtm(cx_mat Y); -
ossiedev/branches/hvolos/components/ChannelMIMO/ChannelMIMO.prf.xml
r9341 r9489 4 4 <!--Powered by Python--> 5 5 <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> 7 7 <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> 10 10 <kind kindtype="configure"/> 11 11 </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> 15 25 <kind kindtype="configure"/> 16 26 </simple> 17 27 <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> 19 29 <kind kindtype="configure"/> 20 30 <values> 21 <value>data_in::standardInterfaces.complexShort</value> 31 <value>data_in::standardInterfaces.complexShort</value> 22 32 </values> 23 33 </simplesequence>