def cw_est(rx, fs:int, Ntone:int, method:str='esprit', usepython=False, useall=False):
"""
estimate beat frequency using subspace frequency estimation techniques.
This is much faster in Fortran, but to start using Python alone doesn't require compiling Fortran.
ESPRIT and RootMUSIC are two popular subspace techniques.
Matlab's rootmusic is a far inferior FFT-based method with very poor accuracy vs. my implementation.
"""
assert isinstance(method,str)
method = method.lower()
tic = time()
if method == 'esprit':
#%% ESPRIT
if rx.ndim == 2:
assert usepython,'Fortran not yet configured for multi-pulse case'
Ntone *= 2
if usepython or (Sc is None and Sr is None):
print('Python ESPRIT')
fb_est, sigma = esprit(rx, Ntone, Nblockest, fs)
elif np.iscomplex(rx).any():
print('Fortran complex64 ESPRIT')
fb_est, sigma = Sc.subspace.esprit(rx,Ntone,Nblockest,fs)
else: # real signal
print('Fortran float32 ESPRIT')
fb_est, sigma = Sr.subspace.esprit(rx,Ntone,Nblockest,fs)
fb_est = abs(fb_est)
#%% ROOTMUSIC
elif method == 'rootmusic':
fb_est, sigma = rootmusic(rx,Ntone,Nblockest,fs)
else:
raise ValueError(f'unknown estimation method: {method}')
print(f'computed via {method} in {time()-tic:.1f} seconds.')
#%% improvised process for CW only without notch filter
# assumes first two results have largest singular values (from SVD)
if not useall:
i = sigma > 0.001 # arbitrary
fb_est = fb_est[i]
sigma = sigma[i]
# if fb_est.size>1:
# ii = np.argpartition(sigma, Ntone-1)[:Ntone-1]
# fb_est = fb_est[ii]
# sigma = sigma[ii]
return fb_est, sigma
评论列表
文章目录