Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLaudatQM committed Mar 20, 2024
1 parent 2c100e6 commit f66b0d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
13 changes: 11 additions & 2 deletions qualang_tools/digital_filters/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
# Digital filter tools
This library includes tools for deriving the taps of the OPX digital filters (IIR and FIR).
This library includes tools for deriving the taps of the OPX digital filters (IIR and FIR).

Such filters are generally used to correct for the high-pass filtering occurring on the fast line of a bias-tee,
or to correct flux pulses for possible distortions happening on the flux lines of superconducting qubit chips.

More details about these types of filter and how they are implemented on the OPX can be found [here](https://docs.quantum-machines.co/1.1.7/qm-qua-sdk/docs/Guides/output_filter/?h=iir#output-filter)

The goal of the following functions is to allow users to easily implement such filters by deriving the IIR and FIR taps
from the measured distortions.

## calc_filter_taps
some explanation
Calculate the best FIR and IIR filter taps for a system with any combination of FIR corrections, exponential
corrections (LPF), high pass compensation, reflections (bounce corrections) and a needed delay on the line.

### Usage examples

Expand Down
25 changes: 13 additions & 12 deletions qualang_tools/digital_filters/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def calc_filter_taps(
exponential: List[Tuple[float, float]] = None,
highpass: List[float] = None,
bounce: List[Tuple[float, float]] = None,
delay: float = None,
delay: int = None,
Ts: float = 1,
) -> Tuple[List[float], List[float]]:
"""
Expand Down Expand Up @@ -61,16 +61,16 @@ def calc_filter_taps(
if max_value >= 2:
feedforward_taps = 1.5 * feedforward_taps / max_value

return feedforward_taps, feedback_taps
return list(feedforward_taps), list(feedback_taps)


def exponential_correction(A, tau, Ts=1):
def exponential_correction(A: float, tau: float, Ts: float = 1):
"""
Calculate the best FIR and IIR filter taps to correct for an exponential decay (LPF) of the shape
`1 + A * exp(-t/tau)`.
Args:
A: The exponential decay prefactor.
A: The exponential decay pre-factor.
tau: The time constant for the exponential decay, given in ns.
Ts: The sampling rate (in ns) of the system and filter taps.
Returns:
Expand All @@ -89,7 +89,7 @@ def exponential_correction(A, tau, Ts=1):
return feedforward_taps, feedback_tap


def highpass_correction(tau, Ts=1):
def highpass_correction(tau: float, Ts: float = 1):
"""
Calculate the best FIR and IIR filter taps to correct for a highpass decay (HPF) of the shape `exp(-t/tau)`.
Expand All @@ -102,17 +102,18 @@ def highpass_correction(tau, Ts=1):
The second is a single IIR (feedback) tap.
"""
Ts *= 1e-9
filts = sig.lti(
*sig.butter(1, np.array([1 / tau / Ts]), btype="highpass", analog=True)
)
ahp2, bhp2 = sig.bilinear(filts.den, filts.num, 1000e6)
flt = sig.butter(1, np.array([1 / tau / Ts]), btype="highpass", analog=True)
ahp2, bhp2 = sig.bilinear(flt[1], flt[0], 1000e6)
feedforward_taps = list(np.array([ahp2[0], ahp2[1]]))
feedback_tap = [min(bhp2[0], 0.9999990463225004)] # Maximum value for the iir tap
return feedforward_taps, feedback_tap


def bounce_and_delay_correction(
bounce_values=[], delay=0, feedforward_taps=[1.0], Ts=1
bounce_values: list = (),
delay: int = 0,
feedforward_taps: list = (1.0,),
Ts: float = 1,
):
"""
Calculate the FIR filter taps to correct for reflections (bounce corrections) and to add a delay.
Expand Down Expand Up @@ -175,7 +176,7 @@ def bounce_and_delay_correction(
return feedforward_taps[index_start:index_end]


def _iir_correction(values, filter_type, feedforward_taps, feedback_taps, Ts=1):
def _iir_correction(values, filter_type, feedforward_taps, feedback_taps, Ts:float=1):
b = np.zeros((2, len(values)))
feedback_taps = np.append(np.zeros(len(values)), feedback_taps)

Expand All @@ -194,7 +195,7 @@ def _iir_correction(values, filter_type, feedforward_taps, feedback_taps, Ts=1):
return feedforward_taps, feedback_taps


def _get_coefficients_for_delay(tau, full_taps_x, Ts=1):
def _get_coefficients_for_delay(tau, full_taps_x, Ts:float=1):
full_taps = np.sinc((full_taps_x - tau) / Ts)
full_taps = _round_taps_close_to_zero(full_taps)
return full_taps
Expand Down

0 comments on commit f66b0d6

Please sign in to comment.