Skip to content
Snippets Groups Projects
Commit dfb2022f authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Add functions to find specific frequency or gain value in transfer function.

parent ccfdcc45
Branches
No related tags found
No related merge requests found
......@@ -133,6 +133,45 @@ def dtft(coefs, Ndtft=None, zeroCenter=True, fftShift=True):
return h, f, HF
def estimate_gain_at_frequency(f, HF, freq):
"""Find gain = abs(HF) at frequency in f that is closest to freq.
Input:
. f, HF: frequency axis and spectrum as from dtft() with fftShift=True
. freq : frequency to look for in f
Return:
. fIndex: index of frequency in f that is closest to freq
. fValue: frequency at fIndex
. fGain : gain = abs(HF) at fIndex
"""
fDiff = np.abs(f - freq)
fIndex = fDiff.argmin()
fValue = f[fIndex]
fGain = np.abs(HF[fIndex])
return fIndex, fValue, fGain
def estimate_frequency_at_gain(f, HF, gain):
"""Find positive frequency in f that has gain = abs(HF) closest to gain.
Input:
. f, HF: frequency axis and spectrum as from dtft() with fftShift=True
. gain : gain to look for in HF
Return:
. fIndex: index of frequency in f that has abs(HF) closest to gain
. fValue: frequency at fIndex
. fGain : gain = abs(HF) at fIndex
"""
pos = len(f[f <= 0])
HFpos = HF[pos:]
HFgain = np.abs(HFpos)
HFdiff = np.abs(HFgain - gain)
fIndex = pos + HFdiff.argmin()
fValue = f[fIndex]
fGain = np.abs(HF[fIndex])
return fIndex, fValue, fGain
###############################################################################
# Radix FFT
###############################################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment