Skip to main content

lib_jsl_electromagnetics/
signal_models.rs

1//! Signal models for arrays: polarization states, point sources, distributed (brightness /
2//! noise-temperature) scenes, and the covariance matrices they induce.
3//!
4//! Polarizations are expressed in the `(θ̂, φ̂)` basis of the arrival direction. Powers are
5//! available powers in watts over the scene bandwidth, so `R` has units of W.
6//!
7//! See the book entry [Arrays, scenes and beamformers](https://jwkunz.github.io/lib_jsl/book/em-arrays/beamforming.html).
8
9pub mod covariance;
10pub mod distributed;
11pub mod point_source;
12
13pub use covariance::{Scene, sample_covariance, synthesize_snapshots};
14pub use distributed::{BrightnessScene, SkyPolarization};
15pub use point_source::PointSource;
16
17use crate::conventions::{C64, TimeConvention};
18use std::f64::consts::FRAC_1_SQRT_2;
19
20/// A 2×2 coherency (polarization) matrix `J = ⟨p pᴴ⟩` in the `(θ̂, φ̂)` basis, normalised to unit
21/// trace (it describes the *shape* of the polarization; power is carried separately).
22#[derive(Debug, Clone, Copy, PartialEq)]
23pub struct Coherency(pub [[C64; 2]; 2]);
24
25impl Coherency {
26    /// A fully polarized state with Jones vector `p` (normalised here).
27    pub fn from_jones(p: [C64; 2]) -> Self {
28        let n = p[0].norm_sqr() + p[1].norm_sqr();
29        let p = p.map(|v| v / n.sqrt().max(1e-300));
30        Coherency([[p[0] * p[0].conj(), p[0] * p[1].conj()], [p[1] * p[0].conj(), p[1] * p[1].conj()]])
31    }
32
33    /// Unpolarized: `½ I`.
34    pub fn unpolarized() -> Self {
35        let h = C64::new(0.5, 0.0);
36        let z = C64::new(0.0, 0.0);
37        Coherency([[h, z], [z, h]])
38    }
39
40    /// Linear polarization along θ̂.
41    pub fn theta() -> Self {
42        Self::from_jones([C64::new(1.0, 0.0), C64::new(0.0, 0.0)])
43    }
44
45    /// Linear polarization along φ̂.
46    pub fn phi() -> Self {
47        Self::from_jones([C64::new(0.0, 0.0), C64::new(1.0, 0.0)])
48    }
49
50    /// A wave arriving from the direction with right-hand circular polarization (IEEE, with
51    /// respect to its own propagation, i.e. `-r̂`).
52    pub fn rhcp_incoming(convention: TimeConvention) -> Self {
53        // θ̂ × φ̂ = r̂ points against the propagation, so handedness is reversed in this basis.
54        Self::from_jones([C64::new(FRAC_1_SQRT_2, 0.0), convention.unit() * FRAC_1_SQRT_2])
55    }
56
57    /// A wave arriving from the direction with left-hand circular polarization.
58    pub fn lhcp_incoming(convention: TimeConvention) -> Self {
59        Self::from_jones([C64::new(FRAC_1_SQRT_2, 0.0), -convention.unit() * FRAC_1_SQRT_2])
60    }
61
62    pub fn trace(&self) -> f64 {
63        self.0[0][0].re + self.0[1][1].re
64    }
65
66    /// The degree of polarization `√(1 - 4 det J)` (0 unpolarized, 1 fully polarized).
67    pub fn degree_of_polarization(&self) -> f64 {
68        let det = (self.0[0][0] * self.0[1][1] - self.0[0][1] * self.0[1][0]).re;
69        (1.0 - 4.0 * det).max(0.0).sqrt()
70    }
71}
72
73#[cfg(test)]
74mod tests {
75    use super::*;
76
77    #[test]
78    fn coherency_states() {
79        assert!((Coherency::unpolarized().degree_of_polarization()).abs() < 1e-12);
80        assert!((Coherency::theta().degree_of_polarization() - 1.0).abs() < 1e-12);
81        let r = Coherency::rhcp_incoming(TimeConvention::PlusJ);
82        assert!((r.trace() - 1.0).abs() < 1e-12 && (r.degree_of_polarization() - 1.0).abs() < 1e-12);
83        // Right- and left-hand states are orthogonal: tr(J_R J_L) = 0.
84        let l = Coherency::lhcp_incoming(TimeConvention::PlusJ);
85        let tr: C64 = (0..2).flat_map(|i| (0..2).map(move |k| (i, k))).map(|(i, k)| r.0[i][k] * l.0[k][i]).sum();
86        assert!(tr.norm() < 1e-12);
87        assert!((Coherency::from_jones([C64::new(3.0, 0.0), C64::new(0.0, 4.0)]).trace() - 1.0).abs() < 1e-12);
88    }
89}