Skip to main content

lib_jsl_electromagnetics/antenna_models/
patch_antenna.rs

1//! Rectangular microstrip patch antennas (transmission-line / cavity model).
2//!
3//! See the book entry [Antenna models](https://jwkunz.github.io/lib_jsl/book/em-arrays/antennas.html).
4
5use super::{Antenna, Excitation};
6use crate::conventions::{C64, Medium, TimeConvention};
7use crate::fields::domain::{Axis, Domain};
8use lib_jsl_core::ErrorsJSL;
9use lib_jsl_core::constants::em::C0;
10use lib_jsl_special_functions::bessel_functions_integer::bessel_j_integer;
11use std::f64::consts::{PI, TAU};
12
13/// A rectangular patch of width `W` (along `y`) and length `L` (along `x`, the resonant
14/// dimension) on a grounded substrate of height `h` and relative permittivity `ε_r`, centred at
15/// the origin with the ground plane at `z = 0` and radiation into `z > 0`.
16///
17/// The dominant TM₀₁₀ mode is modelled by two radiating slots of width `W` at `x = ±L_e/2`
18/// (`L_e = L + 2ΔL`), each an equivalent magnetic line current of `2V₀` doubled by the ground
19/// plane; the far field per unit edge voltage `V₀` (in `e^{+jωt}`) is
20///
21/// `E_θ = -jk/(4π) · S · cos φ · A`,  `E_φ = jk/(4π) · S · cos θ sin φ · A`,
22///
23/// with `S = 2W sinc(kW sin θ sin φ / 2)` the slot factor and `A = 2 cos(k L_e sin θ cos φ / 2)`
24/// the two-slot array factor, and zero below the (infinite) ground plane. Design and impedance
25/// formulas follow Balanis, *Antenna Theory*, §14.2.
26#[derive(Debug, Clone, Copy, PartialEq)]
27pub struct PatchAntenna {
28    pub width: f64,
29    pub length: f64,
30    pub height: f64,
31    pub eps_r: f64,
32}
33
34fn sinc(x: f64) -> f64 {
35    if x.abs() < 1e-12 { 1.0 } else { x.sin() / x }
36}
37
38impl PatchAntenna {
39    pub fn new(width: f64, length: f64, height: f64, eps_r: f64) -> Result<Self, ErrorsJSL> {
40        if [width, length, height].iter().any(|v| !(v.is_finite() && *v > 0.0)) || eps_r.is_nan() || eps_r < 1.0 {
41            return Err(ErrorsJSL::InvalidInputRange("Need positive dimensions and eps_r >= 1."));
42        }
43        Ok(PatchAntenna { width, length, height, eps_r })
44    }
45
46    /// The standard design for resonance at `frequency`: `W = c/(2f) √(2/(ε_r+1))` and
47    /// `L = c/(2f√ε_eff) - 2ΔL`.
48    pub fn design(frequency: f64, eps_r: f64, height: f64) -> Result<Self, ErrorsJSL> {
49        let width = C0 / (2.0 * frequency) * (2.0 / (eps_r + 1.0)).sqrt();
50        let probe = PatchAntenna::new(width, 1.0, height, eps_r)?;
51        let length = C0 / (2.0 * frequency * probe.effective_permittivity().sqrt()) - 2.0 * probe.length_extension();
52        PatchAntenna::new(width, length, height, eps_r)
53    }
54
55    /// The effective permittivity `(ε_r+1)/2 + (ε_r-1)/2 (1 + 12h/W)^{-1/2}`.
56    pub fn effective_permittivity(&self) -> f64 {
57        (self.eps_r + 1.0) / 2.0 + (self.eps_r - 1.0) / 2.0 / (1.0 + 12.0 * self.height / self.width).sqrt()
58    }
59
60    /// The fringing length extension ΔL at each radiating edge.
61    pub fn length_extension(&self) -> f64 {
62        let e = self.effective_permittivity();
63        let wh = self.width / self.height;
64        0.412 * self.height * (e + 0.3) * (wh + 0.264) / ((e - 0.258) * (wh + 0.8))
65    }
66
67    /// The effective length `L + 2ΔL` (the slot separation).
68    pub fn effective_length(&self) -> f64 {
69        self.length + 2.0 * self.length_extension()
70    }
71
72    /// The TM₀₁₀ resonant frequency `c / (2 L_e √ε_eff)`.
73    pub fn resonant_frequency(&self) -> f64 {
74        C0 / (2.0 * self.effective_length() * self.effective_permittivity().sqrt())
75    }
76
77    fn slot_integral(&self, frequency: f64, coupled: bool) -> f64 {
78        let k = TAU * frequency / C0;
79        let axis = Axis::gauss_legendre(0.0, PI, 200).expect("valid");
80        axis.values()
81            .iter()
82            .zip(axis.weights())
83            .map(|(&t, &w)| {
84                let c = t.cos();
85                let x = 0.5 * k * self.width * c;
86                // [sin(kW cos θ / 2) / cos θ]², with its finite limit at cos θ = 0.
87                let base = if c.abs() < 1e-12 { (0.5 * k * self.width).powi(2) } else { (x.sin() / c).powi(2) };
88                let j0 = if coupled { bessel_j_integer(0, k * self.length * t.sin()) } else { 1.0 };
89                w * base * j0 * t.sin().powi(3)
90            })
91            .sum()
92    }
93
94    /// The self conductance `G₁` of one radiating slot (S).
95    pub fn slot_conductance(&self, frequency: f64) -> f64 {
96        self.slot_integral(frequency, false) / (120.0 * PI * PI)
97    }
98
99    /// The mutual conductance `G₁₂` between the two slots (S).
100    pub fn mutual_conductance(&self, frequency: f64) -> f64 {
101        self.slot_integral(frequency, true) / (120.0 * PI * PI)
102    }
103
104    /// The resonant input resistance at a radiating edge, `1 / (2 (G₁ + G₁₂))`.
105    pub fn edge_resistance(&self, frequency: f64) -> f64 {
106        1.0 / (2.0 * (self.slot_conductance(frequency) + self.mutual_conductance(frequency)))
107    }
108
109    /// The resistance of an inset feed `y₀` in from the edge: `R_edge cos²(π y₀ / L)`.
110    pub fn inset_resistance(&self, frequency: f64, inset: f64) -> f64 {
111        self.edge_resistance(frequency) * (PI * inset / self.length).cos().powi(2)
112    }
113
114    /// The inset depth giving the input resistance `target` (Ω), if it is reachable.
115    pub fn inset_for_resistance(&self, frequency: f64, target: f64) -> Option<f64> {
116        let edge = self.edge_resistance(frequency);
117        (target > 0.0 && target <= edge).then(|| self.length / PI * (target / edge).sqrt().acos())
118    }
119}
120
121impl Antenna for PatchAntenna {
122    fn far_field(&self, theta: f64, phi: f64, frequency: f64, convention: TimeConvention) -> [C64; 2] {
123        if theta > PI / 2.0 {
124            return [C64::new(0.0, 0.0); 2];
125        }
126        let k = TAU * frequency / C0;
127        let (st, ct) = theta.sin_cos();
128        let (sp, cp) = phi.sin_cos();
129        let slot = 2.0 * self.width * sinc(0.5 * k * self.width * st * sp);
130        let array = 2.0 * (0.5 * k * self.effective_length() * st * cp).cos();
131        let j = convention.unit();
132        let common = k / (4.0 * PI) * slot * array;
133        [-j * (common * cp), j * (common * ct * sp)]
134    }
135
136    fn excitation(&self) -> Excitation {
137        Excitation::Voltage
138    }
139
140    fn radiated_power(&self, frequency: f64) -> f64 {
141        // Integrate over the upper hemisphere only (the pattern is cut off at the ground plane).
142        let d = Domain::far_field_sphere(Axis::gauss_legendre(0.0, PI / 2.0, 64).expect("valid"), Axis::periodic(0.0, TAU, 128).expect("valid")).expect("valid");
143        let eta = Medium::VACUUM.impedance(TimeConvention::PlusJ).re;
144        d.integrate_fn(|p| {
145            let [a, b] = self.far_field(p.coords[1], p.coords[2], frequency, TimeConvention::PlusJ);
146            (a.norm_sqr() + b.norm_sqr()) / (2.0 * eta)
147        })
148    }
149
150    fn peak_directivity(&self, frequency: f64) -> f64 {
151        // Broadside radiation: the maximum is at θ = 0.
152        self.directivity(0.0, 0.0, frequency)
153    }
154}
155
156#[cfg(test)]
157mod tests {
158    use super::*;
159
160    #[test]
161    fn design_reproduces_the_textbook_example() {
162        // Balanis Example 14.1: ε_r = 2.2, h = 0.1588 cm, f_r = 10 GHz.
163        let p = PatchAntenna::design(10e9, 2.2, 0.1588e-2).unwrap();
164        assert!((p.width - 1.186e-2).abs() < 0.005e-2, "W = {}", p.width);
165        assert!((p.effective_permittivity() - 1.972).abs() < 0.002);
166        assert!((p.length_extension() - 0.081e-2).abs() < 0.001e-2);
167        assert!((p.length - 0.906e-2).abs() < 0.005e-2, "L = {}", p.length);
168        assert!((p.resonant_frequency() - 10e9).abs() < 1e3);
169    }
170
171    #[test]
172    fn impedance_and_inset_feed() {
173        let f = 10e9;
174        let p = PatchAntenna::design(f, 2.2, 0.1588e-2).unwrap();
175        let (g1, g12) = (p.slot_conductance(f), p.mutual_conductance(f));
176        assert!((g1 - 1.57e-3).abs() < 0.05e-3, "G1 = {g1}"); // Balanis: G₁ ≈ 0.00157 S
177        assert!(g12 > 0.0 && g12 < g1);
178        let edge = p.edge_resistance(f);
179        assert!((150.0..300.0).contains(&edge), "{edge}");
180        let y0 = p.inset_for_resistance(f, 50.0).unwrap();
181        assert!((p.inset_resistance(f, y0) - 50.0).abs() < 1e-9 && y0 > 0.0 && y0 < p.length / 2.0);
182        assert!(p.inset_for_resistance(f, edge * 2.0).is_none());
183        assert!(PatchAntenna::new(1.0, 1.0, 0.0, 2.0).is_err() && PatchAntenna::new(1.0, 1.0, 1.0, 0.5).is_err());
184    }
185
186    #[test]
187    fn pattern_is_broadside_with_the_usual_directivity_and_no_back_radiation() {
188        let f = 10e9;
189        let p = PatchAntenna::design(f, 2.2, 0.1588e-2).unwrap();
190        let d = p.peak_directivity(f);
191        assert!((5.0..9.0).contains(&d), "D = {d} ({:.2} dBi)", 10.0 * d.log10());
192        assert_eq!(p.far_field(2.0, 0.3, f, TimeConvention::PlusJ), [C64::new(0.0, 0.0); 2]);
193        // E-plane (φ = 0) is θ-polarized and does not vanish at grazing; the H-plane (φ = 90°)
194        // is φ-polarized and vanishes at grazing.
195        let [et, ep] = p.far_field(PI / 2.0 - 1e-9, 0.0, f, TimeConvention::PlusJ);
196        assert!(et.norm() > 0.0 && ep.norm() < 1e-12);
197        let [_, eph] = p.far_field(PI / 2.0 - 1e-9, PI / 2.0, f, TimeConvention::PlusJ);
198        assert!(eph.norm() < 1e-6 * et.norm());
199    }
200}