54 lines
1.8 KiB
Plaintext
54 lines
1.8 KiB
Plaintext
---
|
||
title: triangle
|
||
description: API reference for qiskit.pulse.library.triangle
|
||
in_page_toc_min_heading_level: 1
|
||
python_api_type: function
|
||
python_api_name: qiskit.pulse.library.triangle
|
||
---
|
||
|
||
<span id="qiskit-pulse-library-triangle" />
|
||
|
||
# qiskit.pulse.library.triangle
|
||
|
||
<Function id="qiskit.pulse.library.triangle" isDedicatedPage={true} github="https://github.com/qiskit/qiskit/tree/stable/0.24/qiskit/pulse/library/discrete.py" signature="triangle(duration, amp, freq=None, phase=0, name=None)">
|
||
Generates triangle 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) = A \left(-2\left|\text{sawtooth}(x, A, T, \phi)\right| + 1\right)
|
||
$$
|
||
|
||
This a non-sinusoidal wave with linear ramping.
|
||
|
||
**Parameters**
|
||
|
||
* **duration** (*int*) – Duration of pulse. Must be greater than zero.
|
||
* **amp** (*complex*) – Pulse amplitude. Wave range is $[-$ `amp` $,$ `amp` $]$.
|
||
* **freq** (*float | None*) – Pulse frequency, units of 1./dt. If `None` defaults to 1./duration.
|
||
* **phase** (*float*) – Pulse phase.
|
||
* **name** (*str | None*) – Name of pulse.
|
||
|
||
**Return type**
|
||
|
||
[*Waveform*](qiskit.pulse.library.Waveform "qiskit.pulse.library.waveform.Waveform")
|
||
|
||
**Example**
|
||
|
||
```python
|
||
import matplotlib.pyplot as plt
|
||
from qiskit.pulse.library import triangle
|
||
import numpy as np
|
||
|
||
duration = 100
|
||
amp = 1
|
||
freq = 1 / duration
|
||
triangle_wave = np.real(triangle(duration, amp, freq).samples)
|
||
plt.plot(range(duration), triangle_wave)
|
||
plt.show()
|
||
```
|
||
|
||

|
||
</Function>
|
||
|