コード例 #1
0
ファイル: test_windows.py プロジェクト: zaccharieramzi/scipy
 def test_basic(self):
     assert_allclose(windows.general_hamming(5, 0.7),
                     [0.4, 0.7, 1.0, 0.7, 0.4])
     assert_allclose(
         windows.general_hamming(5, 0.75, sym=False),
         [0.5, 0.6727457514, 0.9522542486, 0.9522542486, 0.6727457514])
     assert_allclose(
         windows.general_hamming(6, 0.75, sym=True),
         [0.5, 0.6727457514, 0.9522542486, 0.9522542486, 0.6727457514, 0.5])
コード例 #2
0
ファイル: test_windows.py プロジェクト: BranYang/scipy
 def test_basic(self):
     assert_allclose(windows.general_hamming(5, 0.7),
                     [0.4, 0.7, 1.0, 0.7, 0.4])
     assert_allclose(windows.general_hamming(5, 0.75, sym=False),
                     [0.5, 0.6727457514, 0.9522542486,
                      0.9522542486, 0.6727457514])
     assert_allclose(windows.general_hamming(6, 0.75, sym=True),
                     [0.5, 0.6727457514, 0.9522542486,
                     0.9522542486, 0.6727457514, 0.5])
コード例 #3
0
def general_hamming(dataset, alpha, **kwargs):
    r"""
    Calculate generalized Hamming apodization.

    For multidimensional NDDataset,
    the apodization is by default performed on the last dimension.

    The data in the last dimension MUST be time-domain or dimensionless,
    otherwise an error is raised.

    Functional form of apodization window :

    .. math:: w(n) = \alpha - \left(1 - \alpha\right) \cos\left(\frac{2\pi{n}}{M-1}\right)
              \qquad 0 \leq n \leq M-1

    where M is the number of point of the input dataset.

    Both the common Hamming window and Hann window are special cases of the
    generalized Hamming window with :math:`\alpha` = 0.54 and :math:\alpha =
    0.5, respectively

    Parameters
    ----------
    dataset : array.
        Input dataset.
    alpha : float
        The window coefficient, :math:\alpha.
    **kwargs
        Optional keyword parameters (see Other Parameters).

    Returns
    -------
    apodized
        Dataset.
    apod_arr
        The apodization array only if 'retapod' is True.

    Other Parameters
    ----------------
    dim : str or int, keyword parameter, optional, default='x'
        Specify on which dimension to apply the apodization method. If `dim` is specified as an integer it is equivalent
        to the usual `axis` numpy parameter.
    inv : bool, keyword parameter, optional, default=False
        True for inverse apodization.
    rev : bool, keyword parameter, optional, default=False
        True to reverse the apodization before applying it to the data.
    inplace : bool, keyword parameter, optional, default=False
        True if we make the transform inplace.  If False, the function return a new dataset.
    retapod : bool, keyword parameter, optional, default=False
        True to return the apodization array along with the apodized object.

    See Also
    --------
    gm, sp, sine, sinm, qsin, hamming, triang, bartlett, blackmanharris
    """

    x = dataset

    return windows.general_hamming(len(x), alpha, sym=True)
コード例 #4
0


# *****

# Filtering adapted to the signal

# *****

# RANGE COMPRESSION

if (hamming_rg):

  n_rg_eff = 2. * np.round((n_rg * B / f_s)/2.)

  h_hamming_rg_F = np.roll(np.concatenate((np.repeat(0., (n_rg - n_rg_eff) / 2.), general_hamming(int(n_rg_eff),hamming_rg_alpha), np.repeat(0., (n_rg - n_rg_eff) / 2.)),axis=0), int(n_rg / 2))

# Hamming window in range

h_rg_desired = np.roll(np.less_equal(np.abs(t_rg-2*R0/c0), tau/2) *np.exp(- j* np.pi * B / tau * (t_rg - 2. * R0 / c0) ** 2.), int(n_rg / 2.))
# impulse response of the range compression filter

temp_var=np.fft.fft(h_rg_desired)*np.conj(np.fft.fft(h_rg_desired))

for k in range(0, n_az):

  t_i_local=0 #t_i[k % len(t_i)]

  h_rg = np.roll(np.less_equal(np.abs(t_rg-2*R0/c0), tau/2) *np.exp((-1)**k*j * np.pi * B / tau * (t_rg - 2. * R0 / c0 - t_i_local - tau * np.floor((t_rg - 2. * R0 / c0 + tau / 2 - t_i_local) / tau)) ** 2.), int(n_rg / 2.))

  h_rg_F_ideal=temp_var/np.fft.fft(h_rg)
# data [Rea199fc456d6-3]_. The facility uses various values for the :math:`\alpha` parameter
# based on operating mode of the SAR instrument. Some common :math:`\alpha`
# values include 0.75, 0.7 and 0.52 [Rea199fc456d6-4]_. As an example, we plot these different
# windows.

from scipy.signal.windows import general_hamming
from scipy.fftpack import fft, fftshift
import matplotlib.pyplot as plt

plt.figure()
plt.title("Generalized Hamming Windows")
plt.ylabel("Amplitude")
plt.xlabel("Sample")
spatial_plot = plt.axes()

plt.figure()
plt.title("Frequency Responses")
plt.ylabel("Normalized magnitude [dB]")
plt.xlabel("Normalized frequency [cycles per sample]")
freq_plot = plt.axes()

for alpha in [0.75, 0.7, 0.52]:
    window = general_hamming(41, alpha)
    spatial_plot.plot(window, label="{:.2f}".format(alpha))
    A = fft(window, 2048) / (len(window) / 2.0)
    freq = np.linspace(-0.5, 0.5, len(A))
    response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    freq_plot.plot(freq, response, label="{:.2f}".format(alpha))
freq_plot.legend(loc="upper right")
spatial_plot.legend(loc="upper right")
コード例 #6
0
# *****

# Filtering adapted to the signal

# *****

# RANGE COMPRESSION

if (hamming_rg):

    n_rg_eff = 2. * np.round((n_rg * B / f_s) / 2.)

    h_hamming_rg_F = np.roll(
        np.concatenate((np.repeat(0., (n_rg - n_rg_eff) / 2.),
                        general_hamming(int(n_rg_eff), hamming_rg_alpha),
                        np.repeat(0., (n_rg - n_rg_eff) / 2.)),
                       axis=0), int(n_rg / 2))

# Hamming window in range

h_rg_desired = np.roll(
    np.less_equal(np.abs(t_rg - 2 * R0 / c0), tau / 2) *
    np.exp(-j * np.pi * B / tau * (t_rg - 2. * R0 / c0)**2.), int(n_rg / 2.))
# impulse response of the range compression filter

temp_var = np.fft.fft(h_rg_desired) * np.conj(np.fft.fft(h_rg_desired))

for k in range(1, n_az - 1):

    t_i_local = 0  #t_i[k % len(t_i)]