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

Rename beta.

parent 220e931f
Branches
No related tags found
1 merge request!408Resolve RTSD-271
...@@ -121,15 +121,15 @@ def impulse_at_zero_crossing(x): ...@@ -121,15 +121,15 @@ def impulse_at_zero_crossing(x):
# Windowed sinc filter design # Windowed sinc filter design
############################################################################### ###############################################################################
def raised_cosine_response(Ntaps, Nsps, beta): def raised_cosine_response(Ntaps, Nsps, roBeta):
"""Generate a raised cosine (RC) FIR filter impulse response. """Generate a raised cosine (RC) FIR filter impulse response.
Input: Input:
. Ntaps : FIR filter length . Ntaps : FIR filter length
. Nsps: symbol period Tsymbol in number of samples per symbol . Nsps: symbol period Tsymbol in number of samples per symbol
. beta : Roll off factor in [0, 1.0], BW = (1 + beta) / Tsymbol, so: . roBeta : Roll off factor in [0, 1.0], BW = (1 + roBeta) / Tsymbol, so:
- beta = 0.0: rectangular spectrum with BW = 1 / Tsymbol - roBeta = 0.0: rectangular spectrum with BW = 1 / Tsymbol
- beta = 1.0: cosine spectrum with BW = 2 / Tsymbol - roBeta = 1.0: cosine spectrum with BW = 2 / Tsymbol
Return: Return:
. hRc : impulse response of the raised cosine filter. . hRc : impulse response of the raised cosine filter.
""" """
...@@ -145,12 +145,12 @@ def raised_cosine_response(Ntaps, Nsps, beta): ...@@ -145,12 +145,12 @@ def raised_cosine_response(Ntaps, Nsps, beta):
# apply cos term, use for loop instead of array assignment, to detect divide by 0 # apply cos term, use for loop instead of array assignment, to detect divide by 0
for tI in tIndices: for tI in tIndices:
t = tI - tCenter t = tI - tCenter
if np.abs(t) != Tsymbol / (2 * beta): if np.abs(t) != Tsymbol / (2 * roBeta):
hRc[tI] *= np.cos(np.pi * beta * t / Tsymbol) / (1 - (2 * beta * t / Tsymbol)**2) hRc[tI] *= np.cos(np.pi * roBeta * t / Tsymbol) / (1 - (2 * roBeta * t / Tsymbol)**2)
return hRc return hRc
def square_root_raised_cosine_response(Ntaps, Nsps, beta): def square_root_raised_cosine_response(Ntaps, Nsps, roBeta):
"""Generate a square root raised cosine (SRRC) FIR filter impulse response. """Generate a square root raised cosine (SRRC) FIR filter impulse response.
Reference: Reference:
...@@ -160,7 +160,7 @@ def square_root_raised_cosine_response(Ntaps, Nsps, beta): ...@@ -160,7 +160,7 @@ def square_root_raised_cosine_response(Ntaps, Nsps, beta):
Input: Input:
. Ntaps : FIR filter length . Ntaps : FIR filter length
. Nsps: symbol period Tsymbol in number of samples per symbol . Nsps: symbol period Tsymbol in number of samples per symbol
. beta : Roll off factor in [0, 1.0] . roBeta : Roll off factor in [0, 1.0]
Return: Return:
. hSrRc : impulse response of the square root raised cosine filter. . hSrRc : impulse response of the square root raised cosine filter.
""" """
...@@ -171,20 +171,20 @@ def square_root_raised_cosine_response(Ntaps, Nsps, beta): ...@@ -171,20 +171,20 @@ def square_root_raised_cosine_response(Ntaps, Nsps, beta):
t = tIndices - tCenter t = tIndices - tCenter
# numerator term, using array assignment # numerator term, using array assignment
hSrRc = 1 / Tsymbol * (np.cos(np.pi * (1 + beta) * t / Tsymbol) * 4 * beta * t / Tsymbol + hSrRc = 1 / Tsymbol * (np.cos(np.pi * (1 + roBeta) * t / Tsymbol) * 4 * roBeta * t / Tsymbol +
np.sin(np.pi * (1 - beta) * t / Tsymbol)) np.sin(np.pi * (1 - roBeta) * t / Tsymbol))
# apply denumerator term, use for loop instead of array assignment, to detect divide by 0 # apply denumerator term, use for loop instead of array assignment, to detect divide by 0
for tI in tIndices: for tI in tIndices:
t = tI - tCenter t = tI - tCenter
if t == 0.0: if t == 0.0:
hSrRc[tI] = 1 / Tsymbol * (1 + beta * (4 / np.pi - 1)) hSrRc[tI] = 1 / Tsymbol * (1 + roBeta * (4 / np.pi - 1))
elif np.abs(t) == Tsymbol / (4 * beta): elif np.abs(t) == Tsymbol / (4 * roBeta):
hSrRc[tI] = 1 / Tsymbol * beta / np.sqrt(2) * \ hSrRc[tI] = 1 / Tsymbol * roBeta / np.sqrt(2) * \
((1 + 2 / np.pi) * np.sin(np.pi / (4 * beta)) + ((1 + 2 / np.pi) * np.sin(np.pi / (4 * roBeta)) +
(1 - 2 / np.pi) * np.cos(np.pi / (4 * beta))) (1 - 2 / np.pi) * np.cos(np.pi / (4 * roBeta)))
else: else:
hSrRc[tI] /= (1 - (4 * beta * t / Tsymbol)**2) * (np.pi * t / Tsymbol) hSrRc[tI] /= (1 - (4 * roBeta * t / Tsymbol)**2) * (np.pi * t / Tsymbol)
return hSrRc return hSrRc
...@@ -195,7 +195,7 @@ def square_root_raised_cosine_response(Ntaps, Nsps, beta): ...@@ -195,7 +195,7 @@ def square_root_raised_cosine_response(Ntaps, Nsps, beta):
def nof_taps_kaiser_window(fs, fpass, fstop, atten_db): def nof_taps_kaiser_window(fs, fpass, fstop, atten_db):
"""Number of FIR LPF taps using Kaiser window based design """Number of FIR LPF taps using Kaiser window based design
Reference: [HARRIS 3.2, Fig. 3.8 for beta] Reference: [HARRIS 3.2, Fig. 3.8 for kaiserBeta]
""" """
df = fstop - fpass df = fstop - fpass
return int((fs / df) * (atten_db - 8) / 14) return int((fs / df) * (atten_db - 8) / 14)
...@@ -242,7 +242,7 @@ def ideal_low_pass_filter(Npoints, Npass, bandEdgeGain=1.0): ...@@ -242,7 +242,7 @@ def ideal_low_pass_filter(Npoints, Npass, bandEdgeGain=1.0):
def prototype_fir_low_pass_filter(method='firls', def prototype_fir_low_pass_filter(method='firls',
Npoints=1024, Ntaps=16, Ncoefs=1024*16, Npoints=1024, Ntaps=16, Ncoefs=1024*16,
hpFactor=0.9, transitionFactor=0.4, stopRippleFactor=1000000, beta=1, fs=1.0): hpFactor=0.9, transitionFactor=0.4, stopRippleFactor=1000000, kaiserBeta=1, fs=1.0):
"""Derive FIR coefficients for prototype low pass filter """Derive FIR coefficients for prototype low pass filter
Use method 'firls' or 'remez'. Use method 'firls' or 'remez'.
...@@ -274,7 +274,7 @@ def prototype_fir_low_pass_filter(method='firls', ...@@ -274,7 +274,7 @@ def prototype_fir_low_pass_filter(method='firls',
- hpFactor : Half power bandwidth of the filter relative to BWbin - hpFactor : Half power bandwidth of the filter relative to BWbin
- transitionFactor: transition bandwidth factor relative to fpass - transitionFactor: transition bandwidth factor relative to fpass
- stopRippleFactor: stopband ripple factor relative to pass band ripple - stopRippleFactor: stopband ripple factor relative to pass band ripple
- beta: When beta > 0 then additionally apply a Kaiser window on FIR - kaiserBeta: When kaiserBeta > 0 then additionally apply a Kaiser window on FIR
coefficients coefficients
- fs: sample frequency, for logging - fs: sample frequency, for logging
Return: Return:
...@@ -292,12 +292,12 @@ def prototype_fir_low_pass_filter(method='firls', ...@@ -292,12 +292,12 @@ def prototype_fir_low_pass_filter(method='firls',
rippleWeights = [1, stopRippleFactor] rippleWeights = [1, stopRippleFactor]
# Design subband filter # Design subband filter
h = design_fir_low_pass_filter(method, Ncoefs, fpass, fstop, fcutoff, cutoffGain, rippleWeights, beta, fs) h = design_fir_low_pass_filter(method, Ncoefs, fpass, fstop, fcutoff, cutoffGain, rippleWeights, kaiserBeta, fs)
return h return h
def design_fir_low_pass_filter(method, def design_fir_low_pass_filter(method,
Ncoefs, fpass, fstop, fcutoff=0, cutoffGain=0.5, rippleWeights=[1, 1], beta=0, fs=1.0): Ncoefs, fpass, fstop, fcutoff=0, cutoffGain=0.5, rippleWeights=[1, 1], kaiserBeta=0, fs=1.0):
"""Derive FIR coefficients for prototype low pass filter """Derive FIR coefficients for prototype low pass filter
Use method 'firls' or 'remez', fs = 1.0 Use method 'firls' or 'remez', fs = 1.0
...@@ -318,7 +318,7 @@ def design_fir_low_pass_filter(method, ...@@ -318,7 +318,7 @@ def design_fir_low_pass_filter(method,
- fcutoff: when fcutoff > 0, then define cutoff frequency point in transition band, fpass < fcutoff < fstop - fcutoff: when fcutoff > 0, then define cutoff frequency point in transition band, fpass < fcutoff < fstop
- cutoffGain: normalized LPF gain at fcutoff - cutoffGain: normalized LPF gain at fcutoff
- rippleWeights: relative ripple factors for pass band, optional fcutoff, and stop band - rippleWeights: relative ripple factors for pass band, optional fcutoff, and stop band
- beta: When beta > 0, then additionally apply a Kaiser window on FIR - kaiserBeta: When kaiserBeta > 0, then additionally apply a Kaiser window on FIR
coefficients coefficients
Return: Return:
- h: FIR coefficients for requested Ncoefs - h: FIR coefficients for requested Ncoefs
...@@ -368,11 +368,11 @@ def design_fir_low_pass_filter(method, ...@@ -368,11 +368,11 @@ def design_fir_low_pass_filter(method,
hFir = signal.remez(N, [0, f_pb, f_co, f_co, f_sb, fNyquist], hFir = signal.remez(N, [0, f_pb, f_co, f_co, f_sb, fNyquist],
[1, cutoffGain, 0], rippleWeights, fs=fs) [1, cutoffGain, 0], rippleWeights, fs=fs)
# Additionally apply a Kaiser window, with beta = 1 like in pfs_coeff_final.m, this improves # Additionally apply a Kaiser window, with kaiserBeta = 1 like in pfs_coeff_final.m, this improves
# the stopband attenuation near the transition band somewhat # the stopband attenuation near the transition band somewhat
# . beta: 0 rect, 5 hamming, 6 hanning # . kaiserBeta: 0 rect, 5 hamming, 6 hanning
if beta: if kaiserBeta:
win = signal.windows.kaiser(N, beta) win = signal.windows.kaiser(N, kaiserBeta)
hFir *= win hFir *= win
# Normalize DC gain # Normalize DC gain
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment