code: def _fft_helper(
      x: Array,
      win: Array,
      detrend_func: Callable[[Array], Array],
      nperseg: int,
      noverlap: int,
      nfft: int | None,
      sides: str,
  ) -> Array:
      """Calculate windowed FFT in the same way the original SciPy does."""
      if x.dtype.kind == "i":
          x = x.astype(win.dtype)
  
      *batch_shape, signal_length = x.shape
      # Created strided array of data segments
      if nperseg == 1 and noverlap == 0:
          result = x[..., np.newaxis]
      else:
          step = nperseg - noverlap
          batch_shape = list(batch_shape)
          x = x.reshape((math.prod(batch_shape), signal_length, 1))
          result = jax.lax.conv_general_dilated_patches(
              x,
              (nperseg,),
              (step,),
              "VALID",
              dimension_numbers=("NTC", "OIT", "NTC"),
          )
          result = result.reshape(*batch_shape, *result.shape[-2:])
  
      # Detrend each data segment individually
      result = detrend_func(result)
  
      # Apply window by multiplication
      if jnp.iscomplexobj(win):
          (result,) = promote_dtypes_complex(result)
      result = (
          win.reshape((1,) * len(batch_shape) + (1, nperseg)) * result
      )
  
      # Perform the fft on last axis. Zero-pads automatically
      if sides == "twosided":
          return jax.numpy.fft.fft(result, n=nfft)
      else:
          return jax.numpy.fft.rfft(result.real, n=nfft)
  
imports: from __future__ import annotations
  from collections.abc import Sequence
  from functools import partial
  import math
  import operator
  from typing import Callable
  import warnings
  import numpy
  import scipy.signal
  from scipy.fft import next_fast_len
  import jax
  import jax.numpy.fft
  import jax.numpy
  from jax import lax
  from jax._src.api_util import _ensure_index_tuple
  from jax._src import dtypes
  from jax._src.lax.lax import PrecisionLike
  from jax._src.numpy import linalg
  from jax._src.numpy.util import check_arraylike, _wraps, promote_dtypes_inexact, promote_dtypes_complex
  from jax._src.third_party.scipy import signal_helper
  from jax._src.typing import Array, ArrayLike
  from jax._src.util import canonicalize_axis, tuple_delete, tuple_insert
label_desc: Use image node_id 9 for calling a global function with example usage: _fft_helper(x, win, detrend_func, nperseg, noverlap, nfft, sides) and returns: jax, jax