Skip to content

Instantly share code, notes, and snippets.

@goodwill
Created July 11, 2026 02:18
Show Gist options
  • Select an option

  • Save goodwill/f5db84ef0602d1e4590a37a5aa44883f to your computer and use it in GitHub Desktop.

Select an option

Save goodwill/f5db84ef0602d1e4590a37a5aa44883f to your computer and use it in GitHub Desktop.
python HF 13.56 detuning and fix simulation calculator
import numpy as np
def calculate_rfid_performance():
print("\n--- 13.56 MHz RFID/FeliCa Range & Tuning Calculator ---")
print(" (Press ENTER to accept the default values in brackets) \n")
# 1. Antenna Geometry
a_input = input("Enter antenna side length in mm [Default: 80]: ").strip()
a = float(a_input if a_input else 80) / 1000.0 # convert to meters
N_input = input("Enter number of antenna turns [Default: 3]: ").strip()
N = int(N_input if N_input else 3)
I_input = input("Enter antenna drive current in Amps [Default: 0.2]: ").strip()
I = float(I_input if I_input else 0.2)
# 2. Environment Constraints
z_input = input("Enter target compliance read distance in mm [Default: 70]: ").strip()
z_target = float(z_input if z_input else 70) / 1000.0
m_input = input("Enter side metal gap in mm [Default: 25]: ").strip()
metal_gap = float(m_input if m_input else 25) / 1000.0
# 3. Ferrite Properties
use_ferrite = input("Are you using ferrite tape? (yes/no) [Default: no]: ").strip().lower()
if use_ferrite == 'yes' or use_ferrite == 'y':
mu_input = input("Enter ferrite real permeability mu' at 13.56 MHz [Default: 100]: ").strip()
mu_prime = float(mu_input if mu_input else 100)
else:
mu_prime = 1.0 # Air/Vacuum permeability
# Physical Constants
mu_0 = 4 * np.pi * 1e-7 # Permeability of free space
# --- Part 1: Ideal Magnetic Field B(z) at Target Distance (Biot-Savart Law) ---
numerator = mu_0 * I * N * (a**2)
denominator = np.pi * ((a/2)**2 + z_target**2) * np.sqrt(2 * (a/2)**2 + z_target**2)
B_ideal = numerator / denominator
# --- Part 2: Metal Interaction & Eddy Current Losses ---
# Coupling factor increases exponentially as the gap gets smaller relative to antenna size 'a'
coupling_factor = (a / (2 * metal_gap))**3 if metal_gap > 0 else 100
# High mu' ferrite drops the shielding effectiveness factor, reducing opposing eddy current fields
shielding_effectiveness = 1.0 / mu_prime
loss_coefficient = 0.15 * coupling_factor * shielding_effectiveness
# Calculate final effective B-field factor (bounded safely between 0.1 and 1.0)
field_retention = max(0.1, min(1.0, 1.0 - loss_coefficient))
B_effective = B_ideal * field_retention
# --- Part 3: Calculate Estimated Read Ranges ---
# Benchmark open-air range (roughly 95% of antenna loop size for high-performance readers)
open_air_range_mm = a * 1000 * 0.95
# Read range scales down with the cube root of the field attenuation
current_range_mm = open_air_range_mm * (field_retention ** (1/3))
# Output Report
print("\n=================== RESULTS ===================")
print(f"Ideal Forward B-Field (Open Air): {B_ideal*1e6:.2f} uT")
print(f"Effective B-Field (With Metal): {B_effective*1e6:.2f} uT")
print(f"Field Energy Retention: {field_retention*100:.1f}%")
print("-----------------------------------------------")
print(f"Estimated Read Range: {current_range_mm:.1f} mm")
if current_range_mm >= (z_target * 1000):
print("COMPLIANCE STATUS: PASSED ✅")
else:
print("COMPLIANCE STATUS: FAILED ❌")
print("===============================================\n")
if __name__ == "__main__":
calculate_rfid_performance()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment