qiskit-documentation/docs/api/qiskit/0.37/qiskit.pulse.library.sawtoo...

55 lines
1.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: sawtooth
description: API reference for qiskit.pulse.library.sawtooth
in_page_toc_min_heading_level: 1
python_api_type: function
python_api_name: qiskit.pulse.library.sawtooth
---
# qiskit.pulse.library.sawtooth
<Function id="qiskit.pulse.library.sawtooth" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.21/qiskit/pulse/library/discrete.py" signature="sawtooth(duration, amp, freq=None, phase=0, name=None)">
Generates sawtooth wave [`Waveform`](qiskit.pulse.library.Waveform "qiskit.pulse.library.Waveform").
For $A=$ `amp`, $T=$ `period`, and $\phi=$ `phase`, applies the midpoint sampling strategy to generate a discrete pulse sampled from the continuous function:
$$
f(x) = 2 A \left( g(x) - \left\lfloor \frac{1}{2} + g(x) \right\rfloor\right)
$$
where $g(x) = x/T + \phi/\pi$.
**Parameters**
* **duration** (`int`) Duration of pulse. Must be greater than zero.
* **amp** (`complex`) Pulse amplitude. Wave range is $[-$ `amp` $,$ `amp` $]$.
* **freq** (`Optional`\[`float`]) Pulse frequency, units of 1./dt. If `None` defaults to 1./duration.
* **phase** (`float`) Pulse phase.
* **name** (`Optional`\[`str`]) Name of pulse.
**Example**
```python
import matplotlib.pyplot as plt
from qiskit.pulse.library import sawtooth
import numpy as np
duration = 100
amp = 1
freq = 1 / duration
sawtooth_wave = np.real(sawtooth(duration, amp, freq).samples)
plt.plot(range(duration), sawtooth_wave)
```
```python
[<matplotlib.lines.Line2D at 0x7f7925c00850>]
```
![../\_images/qiskit.pulse.library.sawtooth\_0\_1.png](/images/api/qiskit/0.37/qiskit.pulse.library.sawtooth_0_1.png)
**Return type**
[`Waveform`](qiskit.pulse.library.Waveform "qiskit.pulse.library.waveform.Waveform")
</Function>