@@ -383,7 +383,7 @@ def __init__(self, gain=1.0):
383
383
self ._pattern_name = "omni"
384
384
385
385
386
- def cardioid_func (x , direction , coef , gain = 1.0 , normalize = True , magnitude = False ):
386
+ def cardioid_func (x , direction , p , gain = 1.0 , normalize = True , magnitude = False ):
387
387
"""
388
388
One-shot function for computing cardioid response.
389
389
@@ -392,36 +392,54 @@ def cardioid_func(x, direction, coef, gain=1.0, normalize=True, magnitude=False)
392
392
x: array_like, shape (n_dim, ...)
393
393
Cartesian coordinates
394
394
direction: array_like, shape (n_dim)
395
- Direction vector, should be normalized.
396
- coef : float
397
- Parameter for the cardioid function.
395
+ Direction vector, should be normalized
396
+ p : float
397
+ Parameter for the cardioid function (between 0 and 1)
398
398
gain: float
399
- The gain.
399
+ The gain
400
400
normalize : bool
401
- Whether to normalize coordinates and direction vector.
401
+ Whether to normalize coordinates and direction vector
402
402
magnitude : bool
403
- Whether to return magnitude, default is False.
403
+ Whether to return magnitude, default is False
404
404
405
405
Returns
406
406
-------
407
407
resp : :py:class:`~numpy.ndarray`
408
408
Response at provided angles for the speficied cardioid function.
409
409
"""
410
- assert coef >= 0.0
411
- assert coef <= 1.0
410
+ if not 0.0 <= p <= 1.0 :
411
+ raise ValueError ( "The parameter p must be between 0 and 1." )
412
412
413
413
# normalize positions
414
414
if normalize :
415
415
x /= np .linalg .norm (x , axis = 0 )
416
416
direction /= np .linalg .norm (direction )
417
417
418
418
# compute response
419
- resp = gain * (coef + (1 - coef ) * np .matmul (direction , x ))
419
+ resp = gain * (p + (1 - p ) * np .matmul (direction , x ))
420
420
if magnitude :
421
421
return np .abs (resp )
422
422
else :
423
423
return resp
424
424
425
425
426
- def cardioid_energy (coef , gain = 1.0 ):
427
- return gain ** 2 * (4.0 * np .pi / 3.0 ) * (4 * coef ** 2 - 2 * coef + 1 )
426
+ def cardioid_energy (p , gain = 1.0 ):
427
+ r"""
428
+ This function gives the exact value of the surface integral of the cardioid
429
+ (family) function on the unit sphere
430
+
431
+ .. math::
432
+
433
+ E(p, G) = \iint_{\mathbb{S}^2} G^2 \left( p + (1 - p) \boldsymbol{d}^\top \boldsymbol{r} \right)^2 d\boldsymbol{r}
434
+ = \frac{4 \pi}{3} G^2 \left( 4 p^2 - 2 p + 1 \right).
435
+
436
+ This can be used to normalize the energy sent/received.
437
+
438
+ Parameters
439
+ ---------
440
+ p: float
441
+ The parameter of the cardioid function (between 0 and 1)
442
+ gain: float
443
+ The gain of the cardioid function
444
+ """
445
+ return gain ** 2 * (4.0 * np .pi / 3.0 ) * (4 * p ** 2 - 2 * p + 1 )
0 commit comments