original_docstring: Based on LinearResample::SetIndexesAndWeights
  
          Retrieves the weights for resampling as well as the indices in which
          they are valid. LinearResample (LR) means that the output signal is at
          linearly spaced intervals (i.e the output signal has a frequency
          of ``new_freq``). It uses sinc/bandlimited interpolation to
          upsample/downsample the signal.
  
          Returns
          -------
          - the place where each filter should start being applied
          - the filters to be applied to the signal for resampling
          
docstring: Based on LinearResample::SetIndexesAndWeights
  Retrieves the weights for resampling as well as the indices in which
  they are valid. LinearResample (LR) means that the output signal is at
  linearly spaced intervals . It uses sinc/bandlimited interpolation to
  upsample/downsample the signal.
  
  Returns
  
  the place where each filter should start being applied
  the filters to be applied to the signal for resampling
docstring_tokens: Based on LinearResample :: SetIndexesAndWeights Retrieves the weights for resampling as well as the indices in which they are valid . LinearResample ( LR ) means that the output signal is at linearly spaced intervals . It uses sinc / bandlimited interpolation to upsample / downsample the signal . Returns the place where each filter should start being applied the filters to be applied to the signal for resampling
code: def _indices_and_weights(self, waveforms):
          """Based on LinearResample::SetIndexesAndWeights
  
          Retrieves the weights for resampling as well as the indices in which
          they are valid. LinearResample (LR) means that the output signal is at
          linearly spaced intervals (i.e the output signal has a frequency
          of ``new_freq``). It uses sinc/bandlimited interpolation to
          upsample/downsample the signal.
  
          Returns
          -------
          - the place where each filter should start being applied
          - the filters to be applied to the signal for resampling
          """
  
          # Lowpass filter frequency depends on smaller of two frequencies
          min_freq = min(self.orig_freq, self.new_freq)
          lowpass_cutoff = 0.99 * 0.5 * min_freq
  
          assert lowpass_cutoff * 2 <= min_freq
          window_width = self.lowpass_filter_width / (2.0 * lowpass_cutoff)
  
          assert lowpass_cutoff < min(self.orig_freq, self.new_freq) / 2
          output_t = torch.arange(
              start=0.0, end=self.output_samples, device=waveforms.device,
          )
          output_t /= self.new_freq
          min_t = output_t - window_width
          max_t = output_t + window_width
  
          min_input_index = torch.ceil(min_t * self.orig_freq)
          max_input_index = torch.floor(max_t * self.orig_freq)
          num_indices = max_input_index - min_input_index + 1
  
          max_weight_width = num_indices.max()
          j = torch.arange(max_weight_width, device=waveforms.device)
          input_index = min_input_index.unsqueeze(1) + j.unsqueeze(0)
          delta_t = (input_index / self.orig_freq) - output_t.unsqueeze(1)
  
          weights = torch.zeros_like(delta_t)
          inside_window_indices = delta_t.abs().lt(window_width)
  
          # raised-cosine (Hanning) window with width `window_width`
          weights[inside_window_indices] = 0.5 * (
                  1
                  + torch.cos(
              2
              * math.pi
              * lowpass_cutoff
              / self.lowpass_filter_width
              * delta_t[inside_window_indices]
          )
          )
  
          t_eq_zero_indices = delta_t.eq(0.0)
          t_not_eq_zero_indices = ~t_eq_zero_indices
  
          # sinc filter function
          weights[t_not_eq_zero_indices] *= torch.sin(
              2 * math.pi * lowpass_cutoff * delta_t[t_not_eq_zero_indices]
          ) / (math.pi * delta_t[t_not_eq_zero_indices])
  
          # limit of the function at t = 0
          weights[t_eq_zero_indices] *= 2 * lowpass_cutoff
  
          # size (output_samples, max_weight_width)
          weights /= self.orig_freq
  
          self.first_indices = min_input_index
          self.weights = weights
code_tokens: def _indices_and_weights ( self , waveforms ) : min_freq = min ( self . orig_freq , self . new_freq ) lowpass_cutoff = 0.99 * 0.5 * min_freq assert lowpass_cutoff * 2 <= min_freq window_width = self . lowpass_filter_width / ( 2.0 * lowpass_cutoff ) assert lowpass_cutoff < min ( self . orig_freq , self . new_freq ) / 2 output_t = torch . arange ( start = 0.0 , end = self . output_samples , device = waveforms . device , ) output_t /= self . new_freq min_t = output_t - window_width max_t = output_t + window_width min_input_index = torch . ceil ( min_t * self . orig_freq ) max_input_index = torch . floor ( max_t * self . orig_freq ) num_indices = max_input_index - min_input_index + 1 max_weight_width = num_indices . max ( ) j = torch . arange ( max_weight_width , device = waveforms . device ) input_index = min_input_index . unsqueeze ( 1 ) + j . unsqueeze ( 0 ) delta_t = ( input_index / self . orig_freq ) - output_t . unsqueeze ( 1 ) weights = torch . zeros_like ( delta_t ) inside_window_indices = delta_t . abs ( ) . lt ( window_width ) weights [ inside_window_indices ] = 0.5 * ( 1 + torch . cos ( 2 * math . pi * lowpass_cutoff / self . lowpass_filter_width * delta_t [ inside_window_indices ] ) ) t_eq_zero_indices = delta_t . eq ( 0.0 ) t_not_eq_zero_indices = ~ t_eq_zero_indices weights [ t_not_eq_zero_indices ] *= torch . sin ( 2 * math . pi * lowpass_cutoff * delta_t [ t_not_eq_zero_indices ] ) / ( math . pi * delta_t [ t_not_eq_zero_indices ] ) weights [ t_eq_zero_indices ] *= 2 * lowpass_cutoff weights /= self . orig_freq self . first_indices = min_input_index self . weights = weights
short_docstring: Based on LinearResample::SetIndexesAndWeights
  Retrieves the weights for resampling as well as the indices in which
  they are valid.
short_docstring_tokens: Based on LinearResample :: SetIndexesAndWeights Retrieves the weights for resampling as well as the indices in which they are valid .
comment: """Based on LinearResample::SetIndexesAndWeights
  
          Retrieves the weights for resampling as well as the indices in which
          they are valid. LinearResample (LR) means that the output signal is at
          linearly spaced intervals (i.e the output signal has a frequency
          of ``new_freq``). It uses sinc/bandlimited interpolation to
          upsample/downsample the signal.
  
          Returns
          -------
          - the place where each filter should start being applied
          - the filters to be applied to the signal for resampling
          """$SEP$# Lowpass filter frequency depends on smaller of two frequencies$SEP$# raised-cosine (Hanning) window with width `window_width`$SEP$# sinc filter function$SEP$# limit of the function at t = 0$SEP$# size (output_samples, max_weight_width)