@@ -3834,17 +3834,33 @@ def kaiser(M, beta):
3834
3834
return i0 (beta * sqrt (1 - ((n - alpha )/ alpha )** 2.0 ))/ i0 (float (beta ))
3835
3835
3836
3836
3837
- def sinc (x ):
3838
- """
3839
- Return the sinc function.
3837
+ def sinc (x , scale = 'normalized' ):
3838
+ r"""
3839
+ Apply the sinc function to an array, element-wise.
3840
+
3841
+ The normalized sinc function is :math:`\frac{\sin(\pi x)}{\pi x}`.
3842
+ The unnormalized sinc function is :math:`\frac{\sin(x)}{x}`. The
3843
+ normalized version is used more commonly because it has roots at
3844
+ integer values of `x` and the integral is exactly one.
3840
3845
3841
- The sinc function is :math:`\\ sin(\\ pi x)/(\\ pi x)`.
3846
+ For arbitrary scales, the function is defined as
3847
+ :math:`\frac{\sin(scale \cdot x)}{scale \cdot x}`. In this case, the
3848
+ integral from negative infinity to infinity is
3849
+ :math:`\frac{\pi}{scale}` and roots are at multiples of
3850
+ `\frac{\pi}{scale}`.
3842
3851
3843
3852
Parameters
3844
3853
----------
3845
3854
x : ndarray
3846
3855
Array (possibly multi-dimensional) of values for which to to
3847
3856
calculate ``sinc(x)``.
3857
+ scale : {'normalized', 'unnormalized', scalar or array_like}, optional
3858
+ The scale to apply to `x` when computing the sinc function. The
3859
+ default is the most common engineering usage, 'normalized'. The
3860
+ mathematical definition is 'unnormalized'. If an arbitrary scale
3861
+ is provided as an array, it must broadcast against `x`. This
3862
+ parameter should be used as a keyword only parameter. Support for
3863
+ it as a positional parameter may be removed in the near future.
3848
3864
3849
3865
Returns
3850
3866
-------
@@ -3858,16 +3874,16 @@ def sinc(x):
3858
3874
The name sinc is short for "sine cardinal" or "sinus cardinalis".
3859
3875
3860
3876
The sinc function is used in various signal processing applications,
3861
- including in anti-aliasing, in the construction of a Lanczos resampling
3862
- filter, and in interpolation.
3877
+ including in anti-aliasing, in the construction of a Lanczos
3878
+ resampling filter, and in interpolation.
3863
3879
3864
3880
For bandlimited interpolation of discrete-time signals, the ideal
3865
3881
interpolation kernel is proportional to the sinc function.
3866
3882
3867
3883
References
3868
3884
----------
3869
- .. [1] Weisstein, Eric W. "Sinc Function." From MathWorld--A Wolfram Web
3870
- Resource. http://mathworld.wolfram.com/SincFunction.html
3885
+ .. [1] Weisstein, Eric W. "Sinc Function." From MathWorld--A Wolfram
3886
+ Web Resource. http://mathworld.wolfram.com/SincFunction.html
3871
3887
.. [2] Wikipedia, "Sinc function",
3872
3888
http://en.wikipedia.org/wiki/Sinc_function
3873
3889
@@ -3890,9 +3906,9 @@ def sinc(x):
3890
3906
-5.84680802e-02, -8.90384387e-02, -8.40918587e-02,
3891
3907
-4.92362781e-02, -3.89804309e-17])
3892
3908
3893
- >>> plt.plot(x, np.sinc(x))
3894
- [<matplotlib.lines.Line2D object at 0x...>]
3895
- >>> plt.title("Sinc Function ")
3909
+ >>> plt.plot(x, np.sinc(x), x, np.sinc(x, scale='unnormalized') )
3910
+ [<matplotlib.lines.Line2D object at 0x...>, <matplotlib.lines.Line2D object at 0x...> ]
3911
+ >>> plt.title("Normalized and Un-normalized Sinc Functions ")
3896
3912
<matplotlib.text.Text object at 0x...>
3897
3913
>>> plt.ylabel("Amplitude")
3898
3914
<matplotlib.text.Text object at 0x...>
@@ -3908,9 +3924,25 @@ def sinc(x):
3908
3924
<matplotlib.image.AxesImage object
67E6
at 0x...>
3909
3925
3910
3926
"""
3927
+ if isinstance (scale , str ):
3928
+ if scale == 'normalized' :
3929
+ scale = pi
3930
+ elif scale == 'unnormalized' :
3931
+ scale = 1.0
3932
+ else :
3933
+ raise ValueError ("{} is not a valid scaling for `sinc`" .format (scale ))
3934
+
3911
3935
x = np .asanyarray (x )
3912
- y = pi * where (x == 0 , 1.0e-20 , x )
3913
- return sin (y )/ y
3936
+
3937
+ if isinstance (x .dtype , np .inexact ):
3938
+ min_val = np .finfo (x .dtype ).tiny
3939
+ else :
3940
+ min_val = np .finfo (np .float_ ).tiny
3941
+
3942
+ y = where (x == 0 , min_val , x )
3943
+ if np .any (scale != 1.0 ):
3944
+ y *= scale
3945
+ return sin (y ) / y
3914
3946
3915
3947
3916
3948
def msort (a ):
0 commit comments