Fix formatting for apply_channelmod.c

This commit is contained in:
Bartosz Podrygajlo
2025-12-23 10:04:39 +01:00
parent f0d4325cd7
commit 4ec69cad1f
2 changed files with 93 additions and 76 deletions
+63 -45
View File
@@ -1,26 +1,25 @@
/* /*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file * the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. * except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
* Author and copyright: Laurent Thomas, open-cells.com * Author and copyright: Laurent Thomas, open-cells.com
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance: * For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org * contact@openairinterface.org
*/ */
#include <complex.h> #include <complex.h>
#include <common/utils/LOG/log.h> #include <common/utils/LOG/log.h>
@@ -53,11 +52,14 @@ void rxAddInput(const c16_t *input_sig,
{ {
static uint64_t last_TS = 0; static uint64_t last_TS = 0;
if ((channelDesc->sat_height > 0) && (channelDesc->enable_dynamic_delay || channelDesc->enable_dynamic_Doppler)) { // model for transparent satellite on circular orbit if ((channelDesc->sat_height > 0)
&& (channelDesc->enable_dynamic_delay
|| channelDesc->enable_dynamic_Doppler)) { // model for transparent satellite on circular orbit
/* assumptions: /* assumptions:
- The Earth is spherical, the ground station is static, and that the Earth does not rotate. - The Earth is spherical, the ground station is static, and that the Earth does not rotate.
- An access or link is possible from the satellite to the ground station at all times. - An access or link is possible from the satellite to the ground station at all times.
- The ground station is located at the North Pole (positive Zaxis), and the satellite starts from the initial elevation angle 0° in the second quadrant of the YZplane. - The ground station is located at the North Pole (positive Zaxis), and the satellite starts from the initial elevation angle
0° in the second quadrant of the YZplane.
- Satellite moves in the clockwise direction in its circular orbit. - Satellite moves in the clockwise direction in its circular orbit.
*/ */
const double radius_earth = 6377900; // m const double radius_earth = 6377900; // m
@@ -78,7 +80,7 @@ void rxAddInput(const c16_t *input_sig,
const double pos_sat_z = radius_sat * cos(w_sat * t); const double pos_sat_z = radius_sat * cos(w_sat * t);
const double vel_sat_x = 0; const double vel_sat_x = 0;
const double vel_sat_y = w_sat * radius_sat * cos(w_sat * t); const double vel_sat_y = w_sat * radius_sat * cos(w_sat * t);
const double vel_sat_z = -w_sat * radius_sat * sin(w_sat * t); const double vel_sat_z = -w_sat * radius_sat * sin(w_sat * t);
const double pos_ue_x = 0; const double pos_ue_x = 0;
@@ -157,9 +159,17 @@ void rxAddInput(const c16_t *input_sig,
if (channelDesc->enable_dynamic_Doppler) if (channelDesc->enable_dynamic_Doppler)
channelDesc->Doppler_phase_inc = 2 * M_PI * f_Doppler_shift_ue_sat / channelDesc->sampling_rate; channelDesc->Doppler_phase_inc = 2 * M_PI * f_Doppler_shift_ue_sat / channelDesc->sampling_rate;
if(TS - last_TS >= channelDesc->sampling_rate) { if (TS - last_TS >= channelDesc->sampling_rate) {
last_TS = TS; last_TS = TS;
LOG_I(HW, "Satellite orbit: time %f s, Position = (%f, %f, %f), Velocity = (%f, %f, %f)\n", t, pos_sat_x, pos_sat_y, pos_sat_z, vel_sat_x, vel_sat_y, vel_sat_z); LOG_I(HW,
"Satellite orbit: time %f s, Position = (%f, %f, %f), Velocity = (%f, %f, %f)\n",
t,
pos_sat_x,
pos_sat_y,
pos_sat_z,
vel_sat_x,
vel_sat_y,
vel_sat_z);
LOG_I(HW, "Uplink delay %f ms, Doppler shift UE->SAT %f kHz\n", prop_delay * 1000, f_Doppler_shift_ue_sat / 1000); LOG_I(HW, "Uplink delay %f ms, Doppler shift UE->SAT %f kHz\n", prop_delay * 1000, f_Doppler_shift_ue_sat / 1000);
LOG_I(HW, "Satellite velocity towards gNB: %f m/s, acceleration towards gNB: %f m/s²\n", -vel_sat_gnb, acc_sat_gnb); LOG_I(HW, "Satellite velocity towards gNB: %f m/s, acceleration towards gNB: %f m/s²\n", -vel_sat_gnb, acc_sat_gnb);
} }
@@ -216,9 +226,17 @@ void rxAddInput(const c16_t *input_sig,
if (channelDesc->enable_dynamic_Doppler) if (channelDesc->enable_dynamic_Doppler)
channelDesc->Doppler_phase_inc = 2 * M_PI * f_Doppler_shift_sat_ue / channelDesc->sampling_rate; channelDesc->Doppler_phase_inc = 2 * M_PI * f_Doppler_shift_sat_ue / channelDesc->sampling_rate;
if(TS - last_TS >= channelDesc->sampling_rate) { if (TS - last_TS >= channelDesc->sampling_rate) {
last_TS = TS; last_TS = TS;
LOG_I(HW, "Satellite orbit: time %f s, Position = (%f, %f, %f), Velocity = (%f, %f, %f)\n", t, pos_sat_x, pos_sat_y, pos_sat_z, vel_sat_x, vel_sat_y, vel_sat_z); LOG_I(HW,
"Satellite orbit: time %f s, Position = (%f, %f, %f), Velocity = (%f, %f, %f)\n",
t,
pos_sat_x,
pos_sat_y,
pos_sat_z,
vel_sat_x,
vel_sat_y,
vel_sat_z);
LOG_I(HW, "Downlink delay %f ms, Doppler shift SAT->UE %f kHz\n", prop_delay * 1000, f_Doppler_shift_sat_ue / 1000); LOG_I(HW, "Downlink delay %f ms, Doppler shift SAT->UE %f kHz\n", prop_delay * 1000, f_Doppler_shift_sat_ue / 1000);
} }
} }
@@ -228,24 +246,24 @@ void rxAddInput(const c16_t *input_sig,
// so, in actual RF: tx gain + path loss + rx gain (+antenna gain, ...) // so, in actual RF: tx gain + path loss + rx gain (+antenna gain, ...)
// UE and NB gain control to be added // UE and NB gain control to be added
// Fixme: not sure when it is "volts" so dB is 20*log10(...) or "power", so dB is 10*log10(...) // Fixme: not sure when it is "volts" so dB is 20*log10(...) or "power", so dB is 10*log10(...)
const double pathLossLinear = pow(10,channelDesc->path_loss_dB/20.0); const double pathLossLinear = pow(10, channelDesc->path_loss_dB / 20.0);
// Energy in one sample to calibrate input noise // Energy in one sample to calibrate input noise
// the normalized OAI value seems to be 256 as average amplitude (numerical amplification = 1) // the normalized OAI value seems to be 256 as average amplitude (numerical amplification = 1)
const double noise_per_sample = add_noise ? pow(10,channelDesc->noise_power_dB/10.0) * 256 : 0; const double noise_per_sample = add_noise ? pow(10, channelDesc->noise_power_dB / 10.0) * 256 : 0;
const uint64_t dd = channelDesc->channel_offset; const uint64_t dd = channelDesc->channel_offset;
const int nbTx=channelDesc->nb_tx; const int nbTx = channelDesc->nb_tx;
double Doppler_phase_cur = channelDesc->Doppler_phase_cur[rxAnt]; double Doppler_phase_cur = channelDesc->Doppler_phase_cur[rxAnt];
Doppler_phase_cur -= 2 * M_PI * round(Doppler_phase_cur / (2 * M_PI)); Doppler_phase_cur -= 2 * M_PI * round(Doppler_phase_cur / (2 * M_PI));
for (int i=0; i<nbSamples; i++) { for (int i = 0; i < nbSamples; i++) {
cf_t *out_ptr = after_channel_sig + i; cf_t *out_ptr = after_channel_sig + i;
struct complexd rx_tmp= {0}; struct complexd rx_tmp = {0};
for (int txAnt=0; txAnt < nbTx; txAnt++) { for (int txAnt = 0; txAnt < nbTx; txAnt++) {
const struct complexd *channelModel= channelDesc->ch[rxAnt+(txAnt*channelDesc->nb_rx)]; const struct complexd *channelModel = channelDesc->ch[rxAnt + (txAnt * channelDesc->nb_rx)];
//const struct complex *channelModelEnd=channelModel+channelDesc->channel_length; // const struct complex *channelModelEnd=channelModel+channelDesc->channel_length;
for (int l = 0; l<(int)channelDesc->channel_length; l++) { for (int l = 0; l < (int)channelDesc->channel_length; l++) {
// let's assume TS+i >= l // let's assume TS+i >= l
// fixme: the rfsimulator current structure is interleaved antennas // fixme: the rfsimulator current structure is interleaved antennas
// this has been designed to not have to wait a full block transmission // this has been designed to not have to wait a full block transmission
@@ -257,7 +275,7 @@ void rxAddInput(const c16_t *input_sig,
const struct complex16 tx16 = input_sig[idx]; const struct complex16 tx16 = input_sig[idx];
rx_tmp.r += tx16.r * channelModel[l].r - tx16.i * channelModel[l].i; rx_tmp.r += tx16.r * channelModel[l].r - tx16.i * channelModel[l].i;
rx_tmp.i += tx16.i * channelModel[l].r + tx16.r * channelModel[l].i; rx_tmp.i += tx16.i * channelModel[l].r + tx16.r * channelModel[l].i;
} //l } // l
} }
if (channelDesc->Doppler_phase_inc != 0.0) { if (channelDesc->Doppler_phase_inc != 0.0) {
@@ -279,12 +297,12 @@ void rxAddInput(const c16_t *input_sig,
channelDesc->Doppler_phase_cur[rxAnt] = Doppler_phase_cur; channelDesc->Doppler_phase_cur[rxAnt] = Doppler_phase_cur;
if ( (TS*nbTx)%CirSize+nbSamples <= CirSize ) if ((TS * nbTx) % CirSize + nbSamples <= CirSize)
// Cast to a wrong type for compatibility ! // Cast to a wrong type for compatibility !
LOG_D(HW,"Input power %f, output power: %f, channel path loss %f, noise coeff: %f \n", LOG_D(HW,
10*log10((double)signal_energy((int32_t *)&input_sig[(TS*nbTx)%CirSize], nbSamples)), "Input power %f, output power: %f, channel path loss %f, noise coeff: %f \n",
10*log10((double)signal_energy((int32_t *)after_channel_sig, nbSamples)), 10 * log10((double)signal_energy((int32_t *)&input_sig[(TS * nbTx) % CirSize], nbSamples)),
10 * log10((double)signal_energy((int32_t *)after_channel_sig, nbSamples)),
channelDesc->path_loss_dB, channelDesc->path_loss_dB,
10*log10(noise_per_sample)); 10 * log10(noise_per_sample));
} }
+30 -31
View File
@@ -1,37 +1,36 @@
/* /*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. * this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under * The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file * the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. * except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.openairinterface.org/?page_id=698 * http://www.openairinterface.org/?page_id=698
* *
* Author and copyright: Laurent Thomas, open-cells.com * Author and copyright: Laurent Thomas, open-cells.com
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*------------------------------------------------------------------------------- *-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance: * For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org * contact@openairinterface.org
*/ */
#ifndef __RFSIMULATOR_H #ifndef __RFSIMULATOR_H
#define __RFSIMULATOR_H #define __RFSIMULATOR_H
#include <stdbool.h> #include <stdbool.h>
void rxAddInput( const c16_t *input_sig, void rxAddInput(const c16_t *input_sig,
cf_t *after_channel_sig, cf_t *after_channel_sig,
int rxAnt, int rxAnt,
channel_desc_t *channelDesc, channel_desc_t *channelDesc,
int nbSamples, int nbSamples,
uint64_t TS, uint64_t TS,
uint32_t CirSize, uint32_t CirSize,
bool apply_noise bool apply_noise);
);
#endif #endif