-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
180 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod angle; | ||
pub mod frequency; | ||
pub mod noise; | ||
pub mod power; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
pub fn watts_to_dbm(watts: f64) -> f64 { | ||
10.0 * (watts.log10() + 3.0) | ||
} | ||
|
||
pub fn dbm_to_watts(dbm: f64) -> f64 { | ||
10.0_f64.powf((dbm - 30.0) / 10.0) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
#[test] | ||
fn watts_to_dbm() { | ||
let watts: f64 = 1.0; | ||
|
||
let dbm: f64 = super::watts_to_dbm(watts); | ||
|
||
assert_eq!(30.0, dbm); | ||
} | ||
|
||
#[test] | ||
fn another_watts_to_dbm() { | ||
let watts: f64 = 20.0; | ||
|
||
let dbm: f64 = super::watts_to_dbm(watts); | ||
|
||
// not worrying about floating point precision here | ||
assert_eq!(43.01029995663981, dbm); | ||
} | ||
|
||
#[test] | ||
fn dbm_to_watts() { | ||
// not worrying about floating point precision here | ||
let dbm: f64 = 43.0102999566398087; | ||
|
||
let watts: f64 = super::dbm_to_watts(dbm); | ||
|
||
// not worrying about floating point precision here | ||
assert_eq!(19.99999999999997, watts); | ||
} | ||
|
||
#[test] | ||
fn another_dbm_to_watts() { | ||
let dbm: f64 = 30.0; | ||
|
||
let watts: f64 = super::dbm_to_watts(dbm); | ||
|
||
assert_eq!(1.0, watts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ pub mod constants; | |
pub mod conversions; | ||
pub mod fspl; | ||
pub mod orbits; | ||
pub mod receiver; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use crate::utils::print::{print_row, print_separator}; | ||
|
||
pub struct Receiver { | ||
pub gain: f64, // dB | ||
pub temperature: f64, // K | ||
pub noise_figure: f64, // dB | ||
pub bandwidth: f64, // Hz | ||
} | ||
|
||
impl Receiver { | ||
pub fn calculate_noise_floor(&self) -> f64 { | ||
let receiver_noise_floor_power = | ||
crate::conversions::noise::noise_power_from_bandwidth(self.temperature, self.bandwidth); | ||
|
||
crate::conversions::power::watts_to_dbm(receiver_noise_floor_power) | ||
} | ||
|
||
pub fn calculate_noise_power(&self) -> f64 { | ||
self.calculate_noise_floor() + self.noise_figure | ||
} | ||
|
||
pub fn calculate_snr(&self, input_power: f64) -> f64 { | ||
let receiver_noise_floor_dbm = self.calculate_noise_floor(); | ||
|
||
let receiver_total_noise_power = receiver_noise_floor_dbm + self.noise_figure; | ||
|
||
// Assumes receiver input power is spread across the bandwidth | ||
// returns value in dB | ||
input_power - receiver_total_noise_power | ||
} | ||
|
||
pub fn print(&self, input_power: f64) { | ||
print_row("Gain", &self.gain.to_string(), "dB"); | ||
print_row("Temperature", &self.temperature.to_string(), "K"); | ||
print_row("Noise Figure", &self.noise_figure.to_string(), "dB"); | ||
print_row("Bandwidth", &self.bandwidth.to_string(), "Hz"); | ||
print_separator(); | ||
print_row( | ||
"Noise Floor", | ||
&self.calculate_noise_floor().to_string(), | ||
"dBm", | ||
); | ||
print_row( | ||
"Noise Power", | ||
&self.calculate_noise_power().to_string(), | ||
"dBm", | ||
); | ||
print_row("SNR", &self.calculate_snr(input_power).to_string(), "dB"); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::receiver::Receiver; | ||
|
||
#[test] | ||
fn calculate_noise_floor() { | ||
let receiver = Receiver { | ||
gain: 10.0, // not used | ||
temperature: 290.0, | ||
noise_figure: 3.0, // not used | ||
bandwidth: 100.0e6, | ||
}; | ||
|
||
let noise_floor: f64 = receiver.calculate_noise_floor(); | ||
|
||
assert_eq!(-93.97722915699808, noise_floor); | ||
} | ||
|
||
#[test] | ||
fn calculate_noise_power() { | ||
let receiver = Receiver { | ||
gain: 10.0, // not used | ||
temperature: 290.0, | ||
noise_figure: 3.0, | ||
bandwidth: 100.0e6, | ||
}; | ||
|
||
let noise_power: f64 = receiver.calculate_noise_power(); | ||
|
||
// noise floor + noise figure | ||
assert_eq!(-90.97722915699808, noise_power); | ||
} | ||
|
||
#[test] | ||
fn calculate_snr() { | ||
let receiver = Receiver { | ||
gain: 10.0, // not used | ||
temperature: 290.0, | ||
noise_figure: 3.0, | ||
bandwidth: 100.0e6, | ||
}; | ||
|
||
let input_power: f64 = -70.0; // dBm | ||
|
||
// Assumes receiver input power is spread across the bandwidth | ||
// returns value in dB | ||
let snr: f64 = receiver.calculate_snr(input_power); | ||
|
||
assert_eq!(20.977229156998078, snr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod print; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#[allow(dead_code)] | ||
pub fn print_row(msg1: &str, msg2: &str, msg3: &str) { | ||
println!("{0: <20} | {1: <20} | {2: <5}", msg1, msg2, msg3); | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn print_header() { | ||
print_row("--------------", "-----", "----"); | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn print_separator() { | ||
// println!(""); | ||
println!("--------------------------------------------------"); | ||
println!(""); | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub fn print_title(title: &str) { | ||
println!(" {}", title); | ||
println!("--------------------------------------------------"); | ||
println!(""); | ||
} |