Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

N2F: Near-Field to Far-Field Transformation Library

Overview

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

Key Features

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

Theory Background

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

Applications

  1. Antenna Characterization: Convert near-field scanner measurements to far-field radiation patterns
  2. EMI/EMC Analysis: Predict radiation from electronic enclosures and PCBs
  3. Radar Systems: Compute RCS from near-field scattered data
  4. Wireless Design: Analyze array beamforming and coverage patterns
  5. Protoype Validation: Verify simulation results against measurements
  6. Academic Research: Study electromagnetic wave propagation and transformation theory

Installation

MATLAB Version

  1. Clone or download this repository
  2. Add the mn2f/ directory to your MATLAB path:
    addpath(genpath('path/to/N2f/mn2f'))
  3. Run test scripts from scalarField/ or vectorFields/ directories

Python Version

# 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

Quick Start Examples

MATLAB - Spherical N2F Transformation

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'});

Python - Box N2F Transformation

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)

Project Structure

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

Validation and Accuracy

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

Performance

The library implements several optimization strategies:

  1. Vectorized Operations: All core computations use NumPy/MATLAB vectorization
  2. Low-Rank Approximation: Reduces O(N²) operations to O(N×r) where r << N
  3. Precomputed Operators: N2F operator matrices can be reused for multiple excitations
  4. Efficient Geometry: Analytical surface integration where possible

Contributing

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.)

References

The implementation is based on standard electromagnetic theory:

  1. Harrington, R.F. - "Time-Harmonic Electromagnetic Fields"
  2. Balanis, C.A. - "Advanced Engineering Electromagnetics"
  3. Hansen, J.E. - "Spherical Near-Field Antenna Measurements"
  4. Schmidt, J. - "Multilevel Plane Wave Expansion for NFFT"
  5. Various IEEE Transactions on Antennas and Propagation papers

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

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

Releases

Packages

Contributors

Languages