lasp/test/test_ps.py
J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F 0ed005e35f
Some checks failed
continuous-integration/drone/push Build is failing
Cleanup of tests
2023-01-12 20:35:00 +01:00

37 lines
741 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Testing code for power spectra
"""
import numpy as np
from lasp import PowerSpectra, Window
def test_ps():
"""
Check Parsevall for single-sided power spectra
"""
nfft = 2048
t = np.linspace(0, 1.0, nfft, endpoint=False)
ps = PowerSpectra(nfft, Window.WindowType.Rectangular)
sig = np.random.randn(nfft)
freq = 4
omg = 2*np.pi*freq
# sig = 8*np.cos(omg*t)
cps = ps.compute(sig[:,None])
pow1 = np.sum(sig**2)/sig.size
pow2 = np.sum((cps[:,0,0]).real)
# print(pow1)
# print(pow2)
# plt.plot(cps[:,0,0])
assert np.isclose(pow2 - pow1,0, atol=1e-1)
if __name__ == '__main__':
test_ps()