
    AVhi%                     L   d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ d Z ed      ej&                  dej(                  dfd              Z ed      ej&                  dej(                  dfd              Z ed      ej&                  ej(                  dfd              Z ed      ej&                  dej(                  dfd              Z ed      ej&                  dej(                  dfd              Zd Zy)z*Ops for computing common window functions.    N)constant_op)dtypes)ops)tensor_util)	array_ops)cond)math_ops)nn_ops)special_math_ops)dispatch)	tf_exportc                     |j                   st        d|z        t        j                  | t        j
                        } | j                  j                  d       | S )aR  Check window_length and dtype params.

  Args:
    window_length: A scalar value or `Tensor`.
    dtype: The data type to produce. Must be a floating point type.

  Returns:
    window_length converted to a tensor of type int32.

  Raises:
    ValueError: If `dtype` is not a floating point type or window_length is not
      a scalar.
  -dtype must be a floating point type. Found %sdtyper   )is_floating
ValueErrorr   convert_to_tensorr   int32shapeassert_has_rank)window_lengthr   s     W/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/signal/window_ops.py_check_paramsr       sN     
		
DuL
MM''V\\J-%%a(	    zsignal.kaiser_windowg      (@c                 ^   t        j                  |d      5  t        | |      } t        j                  |       }|dk(  r!t        j                  dg|      cddd       S t        j                  | t        j                        dz
  dz  }t        j                  | |dz   t        j                        }t        j                  ||      }t        j                  ||      }t        j                  d|      }t        j                  ||      }|t        j                  t        j                  |t        j                  ||z        z
              z  }t        j                   ||z
        t#        j$                  |      t#        j$                  |      z  z  }	ddd       |	S # 1 sw Y   	S xY w)a  Generate a [Kaiser window][kaiser].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    beta: Beta parameter for Kaiser window, see reference below.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  [kaiser]:
    https://docs.scipy.org/doc/numpy/reference/generated/numpy.kaiser.html
  kaiser_window   r   Ng      ?       @g?)r   
name_scoper   r   constant_valuer   onesr	   castr   float32rangesqrtr
   relusquareexpr   
bessel_i0e)
r   betar   namewindow_length_consthalflen_floatargonenumwindows
             r   r   r   5   sf   " ~~dO, N!-7M%44]Ca^^QCu-	N N 	m6>>:S@CHM
..-)<%~~/C --5
)C==U+D
--5
)CMM-u=M
v{{hoocM122 4 5 5C\\#*%##C(+;+F+Ft+LLNF#N& 
-'N& 
-s   >F"D9F""F,z#signal.kaiser_bessel_derived_windowc                 F   t        j                  |d      5  t        | |      } | dz  }t        |dz   ||      }t	        j
                  |      }t	        j                  |dd |d   z        }t        j                  ||ddd   fd      }ddd       |S # 1 sw Y   S xY w)	a  Generate a [Kaiser Bessel derived window][kbd].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    beta: Beta parameter for Kaiser window.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  [kbd]:
    https://en.wikipedia.org/wiki/Kaiser_window#Kaiser%E2%80%93Bessel-derived_(KBD)_window
  kaiser_bessel_derived_window   r   r   Nr   )axis)	r   r    r   r   r	   cumsumr&   r   concat)	r   r+   r   r,   halflenkaiserwkaiserw_csumhalfwr2   s	            r   r4   r4   \   s    $ ~~d:; <!-7Mq GGaKU;G??7+LMM,s+l2.>>?EueDbDk2;F< 
-< 
-s   A5BB zsignal.vorbis_windowc                    t        j                  |d      5  t        | |      } t        j                  t        j
                  |       |      }t        j                  t        j                  dz  t        j                  t        j                  t        j                  t        j                  | |      z  |dz   z        d      z        }ddd       |S # 1 sw Y   S xY w)a  Generate a [Vorbis power complementary window][vorbis].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  [vorbis]:
    https://en.wikipedia.org/wiki/Modified_discrete_cosine_transform#Window_functions
  vorbis_windowr   r         ?N)
r   r    r   r	   r#   r%   sinnppipow)r   r   r,   r/   r2   s        r   r?   r?   x   s      ~~dO, !-7M
--}5U
CC\\"%%#+X\\
m599	s	6)  F 
- 
-s   B3CCzsignal.hann_windowTc           	      $    t        |d| ||dd      S )a  Generate a [Hann window][hann].

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    periodic: A bool `Tensor` indicating whether to generate a periodic or
      symmetric window. Periodic windows are typically used for spectral
      analysis while symmetric windows are typically used for digital
      filter design.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  Raises:
    ValueError: If `dtype` is not a floating point type.

  [hann]: https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows
  hann_windowr@   _raised_cosine_windowr   periodicr   r,   s       r   rF   rF      s     , 
t]M8$c3
0 0r   zsignal.hamming_windowc           	      $    t        |d| ||dd      S )a  Generate a [Hamming][hamming] window.

  Args:
    window_length: A scalar `Tensor` indicating the window length to generate.
    periodic: A bool `Tensor` indicating whether to generate a periodic or
      symmetric window. Periodic windows are typically used for spectral
      analysis while symmetric windows are typically used for digital
      filter design.
    dtype: The data type to produce. Must be a floating point type.
    name: An optional name for the operation.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  Raises:
    ValueError: If `dtype` is not a floating point type.

  [hamming]:
    https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows
  hamming_windowgHzG?gq=
ףp?rG   rI   s       r   rL   rL      s!    0 
t%5}h$dD
2 2r   c           	      \   j                   st        dz        t        j                  | ||g      5  t        j                  t
        j                  d      j                  j                  d       t        j                        }|dk(  r!t        j                  dg      cddd       S t        j                  t        j                  |t
        j                  d      t
        j                        }|j                  j                  d       dt        j                   d	      z
  }t        j                  ||z  z   dz
        }	t        j                  t        j"                              }
t%        j&                  d	t(        j*                  z        |
z  |	z  |9t        j                  t        j,                        z  z
        cddd       S t/        j.                  t        j0                  d      fd
fd      cddd       S # 1 sw Y   yxY w)a  Helper function for computing a raised cosine window.

  Args:
    name: Name to use for the scope.
    default_name: Default name to use for the scope.
    window_length: A scalar `Tensor` or integer indicating the window length.
    periodic: A bool `Tensor` indicating whether to generate a periodic or
      symmetric window.
    dtype: A floating point `DType`.
    a: The alpha parameter to the raised cosine window.
    b: The beta parameter to the raised cosine window.

  Returns:
    A `Tensor` of shape `[window_length]` of type `dtype`.

  Raises:
    ValueError: If `dtype` is not a floating point type or `window_length` is
      not scalar or `periodic` is not scalar.
  r   r   )r   r,   r   r   r   NrJ   r5   c                  4    t        j                  g       S Nr   )r   r"   )r   r   s   r   <lambda>z'_raised_cosine_window.<locals>.<lambda>   s    	e< r   c                  d    t        j                   t        j                        z  z
        S rO   )r	   r#   cos)abcos_argr   s   r   rP   z'_raised_cosine_window.<locals>.<lambda>   s%    a!hll7&;";;5I r   )r   r   r   r    r   r   r   r   r   r   r!   r   r"   r	   r#   boolmodr%   r   constantrB   rC   rR   r   equal)r,   default_namer   rJ   r   rS   rT   r-   evenncountrU   s     ` ```    @r   rH   rH      s   * 
		
DuL
MM
~~dL=(*CD K))-v||/>@M''*%44]Ca^^QCu-K K }}hfkk
KH NN""1%x||M1--Dmho59GAMM(..7?E""1ruu9E:UBQFG&]]1q8<<#888F%K K& 99}a(<IK'K K Ks   A3H"6D$H"$4H""H+)__doc__numpyrB   tensorflow.python.frameworkr   r   r   r   tensorflow.python.opsr   r   r	   r
   r   tensorflow.python.utilr    tensorflow.python.util.tf_exportr   r   add_dispatch_supportr$   r   r4   r?   rF   rL   rH    r   r   <module>rf      s9   1  3 . + 3 + & * ( 2 + 6* !"	&)d "  #"J 01	58'-~~D  24 !"	'-~~D   #.  	(,FNN 0  !00 "#	+/v~~2  $24.Kr   