<commit_before>var dsp = exports;
var complex = require('./complex.js')

// Returns an array composed of elements from arr, starting at index start
// and counting by step
dsp.segment = function(arr, start, step) {
  var result = [];
  for ( var i = start; i < arr.length; i += step ) {
    result.push(arr[i]);
  }
  return result;
}

// Returns an array of complex numbers representing the frequency spectrum
// of real valued time domain sequence x. (x.length must be integer power of 2)
// Inspired by http://rosettacode.org/wiki/Fast_Fourier_transform#Python
dsp.fft = function(x) {
  var N = x.length;
  if ( N <= 1 )
    return [ new complex.cNum(x[0],0) ];
  // check that N is int pwr of 2
  if (Math.log(N) / Math.LN2 % 1 !== 0)
    // Could eventually 0-pad the input, throw error for now.
    throw new Error ('Array length must be integer power of 2');
  var even = dsp.fft(dsp.segment(x, 0, 2));
  var odd = dsp.fft(dsp.segment(x, 1, 2));
  var res = [], Nby2 = N / 2;
  for ( var k = 0; k < N; k++ ) {
    var tmpPhase = -2*Math.PI*k/N;
    var phasor = new complex.cNum(Math.cos(tmpPhase),Math.sin(tmpPhase));
    if (k < Nby2)
      res[k] = even[k].add(phasor.multiply(odd[k]));
    else
      res[k] = even[k-Nby2].subtract(phasor.multiply(odd[k-Nby2]));
  }
  return res;
}
<commit_msg>Clean up style<commit_after>var Complex = require('./complex.js').Complex;
var dsp = exports;

/**
 * Returns an array composed of elements from arr, starting at index start
 * and counting by step.
 * 
 * @param {Array} Input array.
 * @param {Number} Starting array index.
 * @param {Number} Step size.
 * @return {Array} Resulting sub-array.
 */
dsp.segment = function(arr, start, step) {
  var result = [];
  for ( var i = start; i < arr.length; i += step ) {
    result.push(arr[i]);
  }
  return result;
}

/**
 * Returns an array of complex numbers representing the frequency spectrum
 * of real valued time domain sequence x. (x.length must be integer power of 2)
 * Inspired by http://rosettacode.org/wiki/Fast_Fourier_transform#Python
 * 
 * @param {Array} Real-valued series input, eg. time-series.
 * @return {Array} Array of complex numbers representing input signal in Fourier domain.
 */
dsp.fft = function(x) {
  var N = x.length;
  if ( N <= 1 )
    return [ new Complex(x[0],0) ];
  // check that N is int pwr of 2
  if (Math.log(N) / Math.LN2 % 1 !== 0)
    // Could eventually 0-pad the input, throw error for now.
    throw new Error ('Array length must be integer power of 2');
  var even = dsp.fft(dsp.segment(x, 0, 2));
  var odd = dsp.fft(dsp.segment(x, 1, 2));
  var res = [], Nby2 = N / 2;
  for ( var k = 0; k < N; k++ ) {
    var tmpPhase = -2*Math.PI*k/N;
    var phasor = new Complex(Math.cos(tmpPhase),Math.sin(tmpPhase));
    if (k < Nby2)
      res[k] = even[k].add(phasor.multiply(odd[k]));
    else
      res[k] = even[k-Nby2].subtract(phasor.multiply(odd[k-Nby2]));
  }
  return res;
}

{'fraction_non_alphanumeric': 0.15124615909866848, 'fraction_numerical': 0.014339364970979856, 'mean_word_length': 3.0581717451523547, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3348410', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1040, 'n_words': 336}