original_docstring: Returns a notch filter constructed from a high-pass and low-pass filter.
  
      (from https://tomroelandts.com/articles/
      how-to-create-simple-band-pass-and-band-reject-filters)
  
      Arguments
      ---------
      notch_freq : float
          frequency to put notch as a fraction of the
          sampling rate / 2. The range of possible inputs is 0 to 1.
      filter_width : int
          Filter width in samples. Longer filters have
          smaller transition bands, but are more inefficient.
      notch_width : float
          Width of the notch, as a fraction of the sampling_rate / 2.
  
      Example
      -------
      from speechbrain.dataio.dataio import read_audio
      signal = read_audio('samples/audio_samples/example1.wav')
      signal = signal.unsqueeze(0).unsqueeze(2)
      kernel = notch_filter(0.25)
      notched_signal = convolve1d(signal, kernel)
      
docstring: Returns a notch filter constructed from a high-pass and low-pass filter.
  
  Arguments
  
  notch_freq : float
  frequency to put notch as a fraction of the
  sampling rate / 2. The range of possible inputs is 0 to 1.
  filter_width : int
  Filter width in samples. Longer filters have
  smaller transition bands, but are more inefficient.
  notch_width : float
  Width of the notch, as a fraction of the sampling_rate / 2.
  
  Example
  
  
docstring_tokens: Returns a notch filter constructed from a high - pass and low - pass filter . Arguments notch_freq : float frequency to put notch as a fraction of the sampling rate / 2 . The range of possible inputs is 0 to 1 . filter_width : int Filter width in samples . Longer filters have smaller transition bands but are more inefficient . notch_width : float Width of the notch as a fraction of the sampling_rate / 2 . Example
code: def notch_filter(notch_freq, filter_width=101, notch_width=0.05):
      """Returns a notch filter constructed from a high-pass and low-pass filter.
  
      (from https://tomroelandts.com/articles/
      how-to-create-simple-band-pass-and-band-reject-filters)
  
      Arguments
      ---------
      notch_freq : float
          frequency to put notch as a fraction of the
          sampling rate / 2. The range of possible inputs is 0 to 1.
      filter_width : int
          Filter width in samples. Longer filters have
          smaller transition bands, but are more inefficient.
      notch_width : float
          Width of the notch, as a fraction of the sampling_rate / 2.
  
      Example
      -------
      from speechbrain.dataio.dataio import read_audio
      signal = read_audio('samples/audio_samples/example1.wav')
      signal = signal.unsqueeze(0).unsqueeze(2)
      kernel = notch_filter(0.25)
      notched_signal = convolve1d(signal, kernel)
      """
  
      # Check inputs
      assert 0 < notch_freq <= 1
      assert filter_width % 2 != 0
      pad = filter_width // 2
      inputs = torch.arange(filter_width) - pad
  
      # Avoid frequencies that are too low
      notch_freq += notch_width
  
      # Define sinc function, avoiding division by zero
      def sinc(x):
          def _sinc(x):
              return torch.sin(x) / x
  
          # The zero is at the middle index
          return torch.cat([_sinc(x[:pad]), torch.ones(1), _sinc(x[pad + 1:])])
  
      # Compute a low-pass filter with cutoff frequency notch_freq.
      hlpf = sinc(3 * (notch_freq - notch_width) * inputs)
      hlpf *= torch.blackman_window(filter_width)
      hlpf /= torch.sum(hlpf)
  
      # Compute a high-pass filter with cutoff frequency notch_freq.
      hhpf = sinc(3 * (notch_freq + notch_width) * inputs)
      hhpf *= torch.blackman_window(filter_width)
      hhpf /= -torch.sum(hhpf)
      hhpf[pad] += 1
  
      # Adding filters creates notch filter
      return (hlpf + hhpf).view(1, -1, 1)
code_tokens: def notch_filter ( notch_freq , filter_width = 101 , notch_width = 0.05 ) : assert 0 < notch_freq <= 1 assert filter_width % 2 != 0 pad = filter_width // 2 inputs = torch . arange ( filter_width ) - pad notch_freq += notch_width def sinc ( x ) : def _sinc ( x ) : return torch . sin ( x ) / x return torch . cat ( [ _sinc ( x [ : pad ] ) , torch . ones ( 1 ) , _sinc ( x [ pad + 1 : ] ) ] ) hlpf = sinc ( 3 * ( notch_freq - notch_width ) * inputs ) hlpf *= torch . blackman_window ( filter_width ) hlpf /= torch . sum ( hlpf ) hhpf = sinc ( 3 * ( notch_freq + notch_width ) * inputs ) hhpf *= torch . blackman_window ( filter_width ) hhpf /= - torch . sum ( hhpf ) hhpf [ pad ] += 1 return ( hlpf + hhpf ) . view ( 1 , - 1 , 1 )
short_docstring: Returns a notch filter constructed from a high-pass and low-pass filter.
short_docstring_tokens: Returns a notch filter constructed from a high - pass and low - pass filter .
comment: """Returns a notch filter constructed from a high-pass and low-pass filter.
  
      (from https://tomroelandts.com/articles/
      how-to-create-simple-band-pass-and-band-reject-filters)
  
      Arguments
      ---------
      notch_freq : float
          frequency to put notch as a fraction of the
          sampling rate / 2. The range of possible inputs is 0 to 1.
      filter_width : int
          Filter width in samples. Longer filters have
          smaller transition bands, but are more inefficient.
      notch_width : float
          Width of the notch, as a fraction of the sampling_rate / 2.
  
      Example
      -------
      from speechbrain.dataio.dataio import read_audio
      signal = read_audio('samples/audio_samples/example1.wav')
      signal = signal.unsqueeze(0).unsqueeze(2)
      kernel = notch_filter(0.25)
      notched_signal = convolve1d(signal, kernel)
      """$SEP$# Check inputs$SEP$# Avoid frequencies that are too low$SEP$# Define sinc function, avoiding division by zero$SEP$# The zero is at the middle index$SEP$# Compute a low-pass filter with cutoff frequency notch_freq.$SEP$# Compute a high-pass filter with cutoff frequency notch_freq.$SEP$# Adding filters creates notch filter