#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Jan 15 19:45:33 2018 @author: anne """ import numpy as np from lasp import AvPowerSpectra, Window import matplotlib.pyplot as plt # plt.close('all') def test_aps1(): nfft = 16384 fs = 48000 tend = 10 t = np.linspace(0, (tend*fs)//fs, int(fs*tend), endpoint=False) w = Window.WindowType.Hann # w = Window.WindowType.Rectangular aps = AvPowerSpectra(nfft, w, 50, -1) sig = np.random.randn(int(fs*tend)) # freq = 400 # omg = 2*np.pi*freq # sig = np.cos(omg*t) cps = aps.compute(sig) pow1 = np.sum(sig**2)/sig.size pow2 = np.sum((cps[:,0,0]).real) assert np.isclose(pow2 - pow1,0, atol=1e-2) if __name__ == '__main__': test_aps1()