<commit_before>var sigGen = require('./sigGen.js');
var modulator = require('./modulator.js');
var fft = require('./fft.js');
var windowing = require('fft-windowing');

function getPsd(centerFreq, span, resBw, vidBw, refLvl, scale, sigFreq) {
	var startFreq = centerFreq - span / 2.0;
	var NENBW = 1.5;
	var df = resBw / NENBW;
	var n = Math.ceil(span / df);
	var T = 1 / ( 2 * n * df); // Get sampling interval.

	var fftResult = getFFT(1, T, sigFreq, 0, n, startFreq);

	var psd = {
		refLvl: refLvl,
		scale: scale,
		resBw: resBw,
		vidBw: vidBw,
		freq: fftResult.freq,
		psd: fftResult.psd,
		power: fftResult.power
	};

	return psd;
}

function getFFT(A, T, f, phi, n, startFreq) {
    var t = new Array(n);
	var bins = new Array(n);
	for (var i = 0; i < n; i++) {
		t[i] = i * T;
		bins[i] = i;
	}

	// Generate the signal
	var noise = sigGen.noise(0, A/1000, n);
	var signal = sigGen.sinusoid(A, f, t, phi);
	signal = sigGen.add([signal, noise]);

	// Heterodyne with LO signal to shift the DFT to the specified start frequency
	if(startFreq != 0)
		signal = sigGen.multiply([signal, sigGen.sinusoid(1, startFreq, t, 0)]);
	
	signal = windowing.hann(signal);
	var NENBW = 1.5; // Hann window normalized equivalent noise bandwidth

	// Subtract DC offset
	var avg = 0;
	for (var i = 0; i < n; i++)
		avg += signal[i];
	avg /= n;

	for (var i = 0; i < n; i++)
		signal[i] -= avg;

	// Compute the FFT in place
	var reals = signal.slice(0);
	var imag = new Array(n);
	for (var i = 0; i < n; i++) 
		imag[i] = 0;
	fft.transform(reals, imag);
<commit_msg>Added anti-alias FIR filter.<commit_after>var sigGen = require('./sigGen.js');
var modulator = require('./modulator.js');
var fft = require('./fft.js');
var windowing = require('fft-windowing');
var filter = require('./filter.js');

function getPsd(centerFreq, span, resBw, vidBw, refLvl, scale, sigFreq) {
	var startFreq = centerFreq - span / 2.0;
	var NENBW = 1.5;
	var df = resBw / NENBW;
	var n = Math.ceil(span / df);
	var T = 1 / ( 2 * n * df); // Get sampling interval.

	var fftResult = getFFT(1, T, sigFreq, 0, n, startFreq);

	var psd = {
		refLvl: refLvl,
		scale: scale,
		resBw: resBw,
		vidBw: vidBw,
		freq: fftResult.freq,
		psd: fftResult.psd,
		power: fftResult.power
	};

	return psd;
}

function getFFT(A, T, f, phi, n, startFreq) {
    var t = new Array(n);
	var bins = new Array(n);
	for (var i = 0; i < n; i++) {
		t[i] = i * T;
		bins[i] = i;
	}

	// Generate the signal
	var noise = sigGen.noise(0, A/1000, n);
	var signal = sigGen.sinusoid(A, f, t, phi);
	signal = sigGen.add([signal, noise]);

	// Heterodyne with LO signal to shift the DFT to the specified start frequency
	if(startFreq != 0)
		signal = sigGen.multiply([signal, sigGen.sinusoid(1, startFreq, t, 0)]);

	// Anti-alias filter
	//var FIRCoeff = filter.calcFilter(1/T, startFreq, 40, 31, -150);
	//signal = filter.convFilter(FIRCoeff, signal, n, 1);
	
	// Apply window
	signal = windowing.hann(signal);
	var NENBW = 1.5; // Hann window normalized equivalent noise bandwidth

	// Subtract DC offset
	var avg = 0;
	for (var i = 0; i < n; i++)
		avg += signal[i];
	avg /= n;

	for (var i = 0; i < n; i++)
		signal[i] -= avg;

	// Compute the FFT in place
	var reals = signal.slice(0);
	var imag = new Array(n);
	for (var i = 0; i < n; i++) 
		imag[i] = 0;
	fft.transform(reals, imag);

{'fraction_non_alphanumeric': 0.16536614645858344, 'fraction_numerical': 0.017707082833133252, 'mean_word_length': 3.1714643304130163, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '992936', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1354, 'n_words': 414}