lasp/test/fft_test.py

39 lines
723 B
Python
Raw Normal View History

2018-01-29 15:14:50 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 15 19:45:33 2018
@author: anne
"""
import numpy as np
from lasp.wrappers import Fft
2018-01-29 15:14:50 +00:00
2018-02-17 16:01:53 +00:00
nfft=9
2018-01-29 15:14:50 +00:00
print('nfft:',nfft)
print(nfft)
2018-02-17 16:01:53 +00:00
nchannels = 4
2018-01-29 15:14:50 +00:00
t = np.linspace(0,1,nfft+1)[:-1]
# print(t)
2018-02-17 16:01:53 +00:00
#x1 = 1+np.sin(2*np.pi*t)+3.2*np.cos(2*np.pi*t)+np.sin(7*np.pi*t)
#x1 = np.sin(2*np.pi*t)
x1 = 1+0*t
2018-01-29 15:14:50 +00:00
x = np.vstack([x1.T]*nchannels).T
# Using transpose to get the strides right
x = np.random.randn(nchannels,nfft).T
# x.strides = (8,nfft*8)x
# print("signal:",x)
X = np.fft.rfft(x,axis=0)
print('Numpy fft')
print(X)
fft = Fft(nfft)
2018-01-29 15:14:50 +00:00
Y = fft.fft(x)
2018-02-17 16:01:53 +00:00
print('Beamforming fft')
2018-01-29 15:14:50 +00:00
print(Y)
2018-02-17 16:01:53 +00:00
x2 = fft.ifft(Y)
print('normdiff:',np.linalg.norm(x2-x))
2018-01-29 15:14:50 +00:00
print('end python script')