N2F is a comprehensive library for performing near-field to far-field (N2F) transformations in electromagnetic computations. It implements efficient algorithms for computing far-field radiation patterns from near-field measurement or simulation data using Huygens' principle and model order reduction techniques.
This library is particularly useful for:
- Antenna analysis and design
- Electromagnetic compatibility (EMC) testing
- Radar cross-section (RCS) prediction
- Wireless communication system design
- Microwave and RF engineering applications
✅ Dual-language support: Original MATLAB implementation with Python conversion
✅ Complete electromagnetic theory implementation: Based on Huygens' principle and Kottler's equations
✅ Model order reduction: SVD-based low-rank approximation for computational efficiency
✅ Flexible geometry handling: Support for spherical, box, and arbitrary surfaces
✅ Both scalar and vector field formulations: For different approximation levels
✅ Comprehensive test suites: Validation against direct solvers
✅ Extensive visualization tools: 3D field pattern plotting and analysis
The N2F transformation computes far-field radiation patterns from equivalent electric and magnetic currents on a Huygens surface enclosing the source:
Scalar Field (Simplified):
f(θ,φ) = ∫∫_S [(ikn·R̂)ψ - ∂ψ/∂n] exp(ikR)/4πR dS
Vector Field (Rigorous EM): Uses Kottler's equations to relate tangential E/H fields to far-field patterns through vector potentials.
Where:
- ψ = near field value
- ∂ψ/∂n = normal derivative
- k = wavenumber
- R = distance from surface to observation point
- n̂ = surface normal
- R̂ = unit vector from source to observation
- Antenna Characterization: Convert near-field scanner measurements to far-field radiation patterns
- EMI/EMC Analysis: Predict radiation from electronic enclosures and PCBs
- Radar Systems: Compute RCS from near-field scattered data
- Wireless Design: Analyze array beamforming and coverage patterns
- Protoype Validation: Verify simulation results against measurements
- Academic Research: Study electromagnetic wave propagation and transformation theory
- Clone or download this repository
- Add the
mn2f/directory to your MATLAB path:addpath(genpath('path/to/N2f/mn2f')) - Run test scripts from
scalarField/orvectorFields/directories
# Clone repository
git clone https://github.com/ntilau/N2f.git
cd N2f
# Install dependencies
pip install -r requirements.txt
# Install package in development mode
pip install -e .Required Python packages:
- numpy >= 1.21.0
- scipy >= 1.7.0
- matplotlib >= 3.4.0
addpath('mn2f');
% 1. Create test array
arrayPos = buildArray(1, 3, 0.5, 3, 0.5); % 3x3 array, lambda/2 spacing
% 2. Build spherical sampling surface
radius = getSphRadius(1, arrayPos, 0.5);
[spherePos, dS, thetaNF, phiNF, mSize] = buildSphere(radius, 0.1, 3, 3, 1);
% 3. Compute near field on sphere
[Rmag, NdotRV, n] = getSphVectors(arrayPos, spherePos);
excitPhasor = sf_excitations(1, arrayPos, 0, 0); % Broadside excitation
[psi, delPsi] = sf_nfSolver(1, excitPhasor, Rmag, NdotRV);
% 4. Transform to far-field
thetaFF = deg2rad(-90:1:90);
phiFF = deg2rad([0 90]); % E-plane and H-plane cuts
farField = sf_nf2ffSolver(1, thetaFF, phiFF, spherePos, n, dS, psi, delPsi);
% 5. Visualize results
sf_plotFFCutPlanes(abs(farField), thetaFF, phiFF, {'E-plane', 'H-plane'});import numpy as np
from pyn2f import (
build_array, build_box, get_box_dim, get_box_vectors,
sf_excitations, sf_solvers, deg2rad
)
# 1. Define geometry
wavelength = 1.0
array_pos = build_array(wavelength, 2, 0.5, 2, 0.5) # 2x2 array
x_min, x_max, y_min, y_max, z_min, z_max, x_pts, y_pts, z_pts = \
get_box_dim(wavelength, array_pos, 0.5, 0.1, 0.5)
box_pos, box_n, ds, m_size = build_box(
[1, 1, 1, 1, 1, 1], x_min, x_max, y_min, y_max, z_min, z_max,
x_pts, y_pts, z_pts, 1, 0, 0)
# 2. Compute near field
r_mag, ndot_rv = get_box_vectors(array_pos, box_pos, box_n)
excit_phasor = sf_excitations.sf_excitations(wavelength, array_pos, 0, 0)
psi, del_psi = sf_solvers.sf_nf_solver(wavelength, excit_phasor, r_mag, ndot_rv)
# 3. Transform to far-field
theta_ff = deg2rad(np.linspace(-90, 90, 181))
phi_ff = deg2rad([0, 90])
far_field = sf_solvers.sf_nf2ff_solver(wavelength, theta_ff, phi_ff,
box_pos, box_n, ds, psi, del_psi)
# 4. Compute gain/directivity
gain = sf_solvers.sf_compute_gain(far_field)N2f/
├── mn2f/ # MATLAB source code
│ ├── Geometry functions (array, box, sphere construction)
│ ├── Coordinate transforms (cart↔spherical)
│ ├── Scalar field solvers (NF and N2F)
│ ├── Vector field solvers (EF/HF and N2F)
│ └── Utility & plotting functions
│
├── pyn2f/ # Python package
│ ├── geometry/ # Surface and array generation
│ ├── transforms/ # Coordinate system conversions
│ ├── scalar/ # Scalar wave solvers
│ ├── vector/ # Vector EM field solvers
│ ├── utils/ # Mathematical utilities
│ └── plotting/ # Visualization functions
│
├── scalarField/ # MATLAB scalar field examples
│ ├── sphere/ # Spherical surface tests
│ └── box/ # Rectangular box tests
│
├── vectorFields/ # MATLAB vector field examples
│ ├── sphere/
│ └── box/
│
├── tests/ # Python test and example scripts
│ ├── scalar_field/
│ └── vector_field/
│
├── MovScan.gif # Demonstration: 3x5 array beamsteering
├── README.md # This file
├── LICENSE # MIT License
└── requirements.txt # Python dependencies
All implementations include validation tests comparing:
- Direct N2F transformation (exact integration)
- Low-rank approximated N2F (SVD-reduced)
- Analytical solutions for canonical cases (dipoles, arrays)
Typical accuracy:
- Full-rank transformation: Machine precision (relative error < 1e-12)
- Low-rank approximation: Configurable accuracy based on retained modes
- 90% energy retention: Typically < 1% error
- 99% energy retention: Typically < 0.1% error
The library implements several optimization strategies:
- Vectorized Operations: All core computations use NumPy/MATLAB vectorization
- Low-Rank Approximation: Reduces O(N²) operations to O(N×r) where r << N
- Precomputed Operators: N2F operator matrices can be reused for multiple excitations
- Efficient Geometry: Analytical surface integration where possible
Contributions are welcome! Please feel free to submit Pull Requests for:
- Bug fixes and performance improvements
- Additional geometry types (cylindrical, arbitrary meshes)
- Extended validation test suites
- Documentation improvements
- Additional language bindings (Julia, C++, etc.)
The implementation is based on standard electromagnetic theory:
- Harrington, R.F. - "Time-Harmonic Electromagnetic Fields"
- Balanis, C.A. - "Advanced Engineering Electromagnetics"
- Hansen, J.E. - "Spherical Near-Field Antenna Measurements"
- Schmidt, J. - "Multilevel Plane Wave Expansion for NFFT"
- Various IEEE Transactions on Antennas and Propagation papers
This project is licensed under the MIT License - see the LICENSE file for details.
Original MATLAB implementation developed by Laurent Ntibarikure
Python conversion and maintenance by the open-source community
Special thanks to contributors who have provided test cases, bug reports, and enhancements
Keywords: Near-field to far-field, N2F transformation, electromagnetic compatibility, antenna measurement, model order reduction, SVD approximation, Huygens principle, radiation pattern calculation, far-field prediction
Topics: Electromagnetics, Antenna Engineering, Computational EM, RF/Microwave Engineering, Wireless Communications, Radar Cross Section, EMC Testing, Scientific Computing