This notebook computes the magnetomotive force (MMF) waveform and harmonic spectrum produced by an AC stator winding.
Why It Matters
The spatial shape of the airgap MMF directly determines: - Torque production — the working harmonic (ν = p) drives the fundamental torque. - Torque ripple — sub- and super-harmonics create pulsating torque components. - Rotor losses — higher-order harmonics induce eddy currents in the rotor magnets and back-iron, causing heating and efficiency loss. - Acoustic noise — MMF harmonics that coincide with structural resonances generate audible noise.
Designers use the MMF spectrum to compare winding configurations, choose slot/pole combinations, and decide between single- and double-layer layouts before running finite-element analysis.
How It Fits Into Motor Design
emachines workflow:
01_winding.ipynb
(winding factors, star-of-slots)
│
▼
01_winding_mmf.ipynb ←── YOU ARE HERE
(MMF waveform & spectrum)
│
▼
02_pmsm.ipynb (torque, back-EMF via kw and MMF)
04_mec_solver.ipynb (flux linkage in magnetic circuit)
Depends on:01_winding.ipynb — uses build_coil_matrix, get_valid_coil_spans from emachines.winding.sos.
Feeds into:02_pmsm.ipynb, 04_mec_solver.ipynb.
What You Provide (Inputs)
Parameter
Symbol
Description
Units
Typical Range
Stator slots
Q
Total number of stator slots
—
6 – 72
Poles
P
Number of poles (even)
—
2 – 20
Phases
m
Number of phases
—
3 (three-phase)
Layers
layers
Single- or double-layer winding
—
1 or 2
Coil span
w
Span of each coil in slots
slots
1 – Q/p
Time angle
θ_e
Electrical time angle
rad
0 – 2π
Mode
mode
"three_phase", "single_phase", "winding_factor"
—
—
Max harmonic
nu_max
Highest spatial harmonic to evaluate
—
20 – 50
What You Get (Outputs)
Result
Symbol
Meaning
Conductor distribution
n[i]
Signed A·turns per slot at angle θ_e
MMF waveform
F(θ)
Staircase MMF along the airgap
Winding factor spectrum
kw(ν)
MMF harmonic amplitudes
F̂(ν)
kw(ν)·p/ν, balanced 3-phase cancellation applied
Quick Example
from emachines.winding.mmf import mmf_waveform, mmf_harmonics# 12-slot / 10-pole double-layer FSCW at θ_e = 0angles, F = mmf_waveform(12, 10, layers=2)# Three-phase MMF harmonic spectrum, normalisednu, amp = mmf_harmonics(12, 10, layers=2)
Abbreviations and Notation
Symbol
Definition
Units
Q
Number of stator slots
—
P
Number of poles
—
p
Pole pairs, p = P/2
—
m
Number of phases
—
ν
Mechanical spatial harmonic order
—
w
Coil span in slots
slots
θ_e
Electrical time angle
rad
n_i
Signed ampere-conductor value at slot i
A·turns (pu)
F(θ)
MMF waveform along the airgap
A·turns (pu)
kw(ν)
Winding factor magnitude at harmonic ν
—
F̂(ν)
MMF harmonic amplitude = kw(ν)·p/ν
A·turns (pu)
t
Winding periodicity = gcd(Q, p)
—
Imports and Setup
Background: MMF in AC Windings
When alternating current flows through a stator winding, each conductor contributes a localised magnetomotive force proportional to the current it carries and its winding direction. Summing these contributions around the airgap circumference via Ampere’s law yields the MMF waveform F(θ).
For a sinusoidal balanced three-phase supply: \[
i_k(\theta_e) = \hat{I}\cos\!\left(\theta_e - \frac{2\pi k}{m}\right),\quad k = 0,1,\ldots,m-1
\]
The MMF waveform is computed in three steps:
Slot assignment — build_coil_matrix maps each slot conductor to a phase and current direction.
Ampere-conductor distribution — multiply signed conductor occupancy by instantaneous phase currents to get n[i] at each slot.
Cumulative sum — integrate n[i] around the circumference (Ampere’s law) and remove the DC offset.
The resulting staircase is then decomposed by spatial Fourier analysis into its harmonic spectrum.
mmf_distribution: Ampere-Conductor Distribution
Theory
The ampere-conductor distribution n(θ) is a step function that equals the net signed conductor current at each slot position:
where code is the signed conductor occupancy from build_coil_matrix (+k = phase k forward, −k = phase k return), and \(i_k(\theta_e)\) is the instantaneous current of phase k.
Physical meaning: n(θ) is the “source density” of MMF. The MMF itself is its spatial running integral (cumulative sum around the bore).
Design insight: The distribution of conductors across slots determines which spatial harmonics are present and how strongly. Distributed windings spread conductors to suppress low-order harmonics; concentrated windings concentrate them for high torque density at the cost of richer harmonic content.
def mmf_distribution( Q:int, P:int, m:int=3, layers:int|None=None, # None → the best buildable, balanced candidate. w:int|None=None, # Coil span in slots. ``None`` → coil span that# maximises the fundamental winding factor. theta_electrical:float=0.0)->np.ndarray: # Signed ampere-conductor value at each slot. Per-unit (peak = 1 A·turn).
Instantaneous signed ampere-conductor distribution along the airgap.
For each slot position i (mechanical angle θᵢ = 2π·i/Q), n[i] is the sum of signed conductor currents across all winding layers:
.. math:: n_i = {} ({i,}) i_{,||-1}(_e)
Parameters
Q : int Number of stator slots P : int Number of poles (even, ≥ 2) m : int Number of phases (default 3) layers : int | None 1 (single-layer) or 2 (double-layer). None → the best buildable, balanced candidate. w : int | None Coil span in slots. None → coil span that maximises the fundamental winding factor. theta_electrical : float Electrical time angle (radians, default 0).
Returns
np.ndarray, shape (Q,), dtype float64 Signed ampere-conductor value at each slot. Per-unit (peak = 1 A·turn).
import mathfrom emachines.winding.mmf import mmf_distribution, mmf_waveform, mmf_harmonics# Examplesn = mmf_distribution(12, 10, layers=2)assert n.shape == (12,)assertabs(n.sum()) <1e-10# Ampère: ampere-conductors sum to zero around the bore
mmf_distribution: Example
from emachines.winding.mmf import mmf_distributionimport numpy as np# 12s/10p double-layer FSCW at θ_e = 0 (phase A at positive peak)n = mmf_distribution(12, 10, layers=2, theta_electrical=0.0)print("12-slot / 10-pole double-layer FSCW, θ_e = 0°")print(f"Slot conductors: {np.round(n, 4)}")print(f"Sum (should be ≈ 0): {n.sum():.2e}")print()print("Interpretation: positive = net A·turns in forward direction,")print(" negative = net A·turns in return direction.")
12-slot / 10-pole double-layer FSCW, θ_e = 0°
Slot conductors: [ 2. -1.5 1. 0. -1. 1.5 -2. 1.5 -1. -0. 1. -1.5]
Sum (should be ≈ 0): 0.00e+00
Interpretation: positive = net A·turns in forward direction,
negative = net A·turns in return direction.
mmf_waveform: MMF Staircase
Theory
The MMF waveform is obtained by applying Ampere’s law around the stator bore. Integrating the ampere-conductor distribution n(θ) in the positive θ direction gives:
where \(\overline{F}\) is the spatial mean, subtracted to enforce zero net MMF around the closed path (no DC offset).
The result is a staircase waveform — constant between slots, stepping at each slot opening. In the limit of many slots (large Q) it approaches a sinusoid; for concentrated windings with few slots per phase it is highly non-sinusoidal.
Design insight: The ratio of fundamental amplitude to harmonic content directly determines torque quality. A near-sinusoidal MMF (many slots, distributed winding) gives low ripple; a square-wave MMF (concentrated winding) is rich in harmonics but simpler to manufacture.
Instantaneous MMF staircase waveform along the airgap.
Applies Ampere’s law around the stator bore: the MMF at mechanical angle θ equals the cumulative sum of ampere-conductors from slot 0 up to the slot preceding θ, with the DC offset removed.
.. math:: F(i) = {j=0}^{i-1} n_j -
The staircase is returned closed (first point repeated at 360°) for direct use in step-line plots.
Parameters
Q : int P : int m : int (default 3) layers : int | None 1 or 2. None → the best candidate. w : int | None theta_electrical : float Electrical time angle (radians, default 0)
Returns
angles : np.ndarray, shape (Q + 1,) Mechanical angles in degrees, 0° … 360° inclusive. F : np.ndarray, shape (Q + 1,) Per-unit MMF at each slot boundary (closed staircase).
# Examplesangles, F = mmf_waveform(12, 10, layers=2)assert angles.shape == F.shape == (13,) # closed staircase: 0° repeated at 360°assertabs(F[:-1].mean()) <1e-10# zero mean over the Q slot boundaries (repeat excluded)
mmf_waveform: Example — Effect of Electrical Time Angle
from emachines.winding.mmf import mmf_waveformimport numpy as npprint("MMF waveform at three electrical time angles")print("12-slot / 10-pole double-layer FSCW")print()for theta_deg in [0, 30, 90]: angles, F = mmf_waveform(12, 10, layers=2, theta_electrical=np.radians(theta_deg))print(f" θ_e = {theta_deg:3d}° | peak MMF = {np.max(np.abs(F[:-1])):.4f} pu")print()print("Observation: the peak MMF is the same at all time angles (rotating wave).")
MMF waveform at three electrical time angles
12-slot / 10-pole double-layer FSCW
θ_e = 0° | peak MMF = 1.0000 pu
θ_e = 30° | peak MMF = 0.8660 pu
θ_e = 90° | peak MMF = 0.8660 pu
Observation: the peak MMF is the same at all time angles (rotating wave).
winding_factor_spectrum: Winding Factor vs. Harmonic Order
Theory
The winding factor for mechanical harmonic ν is the ratio of the actual phasor sum of conductor voltages to the arithmetic sum (i.e. the ideal case where all conductors are in one slot):
where the inner sum runs over all conductors (across all layers) of phase k, \(s_{i,\text{lyr}} \in \{+1,-1\}\) is the conductor direction, and \(N_k\) is the total conductor count for phase k.
Mechanical vs. electrical harmonics: ν is the mechanical harmonic order — the number of complete cycles of the waveform around the full 360° mechanical circumference. The working harmonic (the one that produces torque with P poles) is at ν = p = P/2.
Design insight: Harmonics with high kw(ν) are efficiently produced. For a PMSM, harmonics other than ν = p are parasitic — they store reactive energy and cause rotor losses. A good winding has kw(p) ≈ 0.9–1.0 and kw(ν) ≈ 0 for all other significant ν.
# winding_factor_spectrum is defined in emachines.winding.winding_factors# and imported into this module via the setup cell above.# It is re-exported from emachines.winding for convenience.from emachines.winding.winding_factors import winding_factor_spectrum # noqa: F401
winding_factor_spectrum: Example — Integer-slot vs. FSCW
The Fourier decomposition of the airgap MMF gives amplitude coefficients for each spatial harmonic ν. For a winding with winding factor kw(ν) and p pole pairs, the analytical result is:
\[
\hat{F}_\nu = \frac{k_{w\nu} \cdot p}{\nu}
\]
The factor \(p/\nu\) arises because the MMF is the spatial integral of the conductor distribution: integrating \(\cos(\nu x)\) yields \(\sin(\nu x)/\nu\), and multiplying by p normalises the working harmonic (ν = p) to kw₁.
Three-phase cancellation: In a balanced m-phase winding, certain harmonics cancel completely. For m = 3, harmonics where ν is a non-working multiple of 3 vanish in the balanced sum. However, the simple rule “ν % m == 0 → cancel” fails when p itself is divisible by m (e.g. 9s/6p where p = 3). This implementation detects cancellation numerically by computing the complex m-phase phasor sum at each ν and checking whether both the forward- and backward-rotating components vanish.
Mode options: - "three_phase" — balanced m-phase MMF; zero-sequence harmonics cancelled (default, matches the website tool). - "single_phase" — single-phase MMF; all harmonics retained. - "winding_factor" — returns |kw(ν)| directly without the 1/ν weighting.
def mmf_harmonics( Q:int, P:int, m:int=3, layers:int|None=None, w:int|None=None, mode:str='three_phase', # ``"three_phase"`` — balanced m-phase MMF; zero-sequence harmonics# cancelled numerically (default).# ``"single_phase"`` — single-phase MMF; all harmonics retained.# ``"winding_factor"`` — returns |kw(ν)| with no 1/ν weighting. nu_max:int=40, normalize:bool=True, # ``True`` (default) — divide by the working-harmonic amplitude# so the working harmonic = 1.0.# ``False`` — return raw kw(ν)·p/ν values.)->tuple[np.ndarray, np.ndarray]: # Mechanical harmonic orders 1 … nu_max.
MMF harmonic amplitude spectrum.
The amplitude of spatial harmonic ν in the airgap MMF:
.. math:: _=
For mode="three_phase" harmonics cancelled by the balanced m-phase current sum are identified numerically and zeroed out.
Parameters
Q : int P : int m : int Number of phases (default 3) layers : int | None 1 or 2. None → the best candidate. w : int | None mode : str "three_phase" — balanced m-phase MMF; zero-sequence harmonics cancelled numerically (default). "single_phase" — single-phase MMF; all harmonics retained. "winding_factor" — returns |kw(ν)| with no 1/ν weighting. nu_max : int Maximum harmonic order (default 40) normalize : bool True (default) — divide by the working-harmonic amplitude so the working harmonic = 1.0. False — return raw kw(ν)·p/ν values.
Pyrhönen, J., Jokinen, T., & Hrabovcová, V. (2014). Design of Rotating Electrical Machines, 2nd ed. Wiley. §2.4, eq. (2.73), (2.98).
Bianchi, N., & Bolognani, S. (2002). Design techniques for reducing cogging torque in surface-mounted PM motors. IEEE Transactions on Industry Applications, 38(5), 1259–1265. DOI: 10.1109/TIA.2002.802909
Müller, G., Vogt, K., & Ponick, B. (2008). Berechnung elektrischer Maschinen. Wiley-VCH. §3.4–3.6, eq. (3.65).