# cosine_pulse

Source: https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/cosine_pulse

```python
boulderopal.signals.cosine_pulse(duration, amplitude, drag=0.0, start_time=0.0, end_time=None, flat_duration=0.0)
```

Create a Signal object representing a cosine pulse.

### Parameters
* **duration** (*float*) – The duration of the pulse.
* **amplitude** (*float* *or* *complex*) – The amplitude of the pulse, $A$.
* **drag** (*float* *,* *optional*) – The DRAG parameter, $\beta$.
  Defaults to 0, in which case there is no DRAG correction.
* **start_time** (*float* *,* *optional*) – The time at which the cosine pulse starts, $t_\mathrm{start}$.
  Defaults to 0.
* **end_time** (*float* *or* *None* *,* *optional*) – The time at which the cosine pulse ends, $t_\mathrm{end}$.
  Defaults to the duration.
* **flat_duration** (*float* *,* *optional*) – The amount of time that the pulse remains constant after the peak of
  the cosine, $t_\mathrm{flat}$.
  If passed, it must be nonnegative and less than the difference between
  end_time and start_time.
  Defaults to 0, in which case no constant part is added to the cosine pulse.
### Returns
The cosine pulse.
### Return type
[Signal](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/Signal.md#boulderopal.signals.Signal)

### SEE ALSO
[`boulderopal.signals.gaussian_pulse`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/gaussian_pulse.md#boulderopal.signals.gaussian_pulse)
: Create a Signal object representing a Gaussian pulse.

[`boulderopal.signals.hann_series`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/hann_series.md#boulderopal.signals.hann_series)
: Create a Signal object representing a sum of Hann window functions.

[`boulderopal.signals.sech_pulse`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/sech_pulse.md#boulderopal.signals.sech_pulse)
: Create a Signal object representing a hyperbolic secant pulse.

[`boulderopal.signals.sinusoid`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/sinusoid.md#boulderopal.signals.sinusoid)
: Create a Signal object representing a sinusoidal oscillation.

[`boulderopal.signals.square_pulse`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/signals/square_pulse.md#boulderopal.signals.square_pulse)
: Create a Signal object representing a square pulse.

[`Graph.signals.cosine_pulse_pwc`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/graph/Graph/signals/cosine_pulse_pwc.md#boulderopal.graph.signals.cosine_pulse_pwc)
: Graph operation to create a Pwc representing a cosine pulse.

## Notes

The cosine pulse is defined as

$$
\mathop{\mathrm{Cos}}(t) =
\begin{cases}
0
&\mathrm{if} \quad t < t_\mathrm{start} \\
\frac{A}{2} \left[1+\cos \left(\omega \{t-\tau_-\} \right)
+ i\omega\beta \sin \left(\omega \{t-\tau_-\}\right)\right]
&\mathrm{if} \quad t_\mathrm{start} \le t < \tau_- \\
A
&\mathrm{if} \quad \tau_- \le t \le \tau_+ \\
\frac{A}{2} \left[1+\cos \left(\omega\{t-\tau_+\}\right)
+ i\omega \beta\sin \left(\omega \{t-\tau_+\}\right)\right]
&\mathrm{if} \quad \tau_+ < t \le t_\mathrm{end} \\
0
&\mathrm{if} \quad t > t_\mathrm{end} \\
\end{cases},
$$

where $\omega=2\pi /(t_\mathrm{end}-t_\mathrm{start} - t_\mathrm{flat})$,
$\tau_\mp$ are the start/end times of the flat segment,
with $\tau_\mp=(t_\mathrm{start}+t_\mathrm{end} \mp t_\mathrm{flat})/2$.

If the flat duration is zero (the default setting), this reduces to

$$
\mathop{\mathrm{Cos}}(t) =
\frac{A}{2} \left[1+\cos \left(\omega \{t-\tau\} \right)
+ i\omega\beta \sin \left(\omega \{t-\tau\}\right)\right]
\theta(t-t_\mathrm{start}) \theta(t_\mathrm{end}-t),
$$

where now $\omega=2\pi /(t_\mathrm{end}-t_\mathrm{start})$,
$\tau=(t_\mathrm{start}+t_\mathrm{end})/2$
and $\theta(t)$ is the
[Heaviside step function](https://en.wikipedia.org/wiki/Heaviside_step_function).

## Examples

Define a cosine pulse.

```pycon
>>> pulse = bo.signals.cosine_pulse(duration=3.0, amplitude=1.0)
>>> pulse.export_with_time_step(time_step=0.5)
array([0.0669873+0.j, 0.5      +0.j, 0.9330127+0.j, 0.9330127+0.j,
       0.5      +0.j, 0.0669873+0.j])
```

Define a flat-top cosine pulse with a DRAG correction.

```pycon
>>> pulse = bo.signals.cosine_pulse(
...     duration=3.0, amplitude=1.0, drag=0.1, flat_duration=0.6
... )
>>> pulse.export_with_sampling_rate(sampling_rate=2.0)
array([0.10332333-0.07968668j, 0.69134172-0.12093555j,
       1.        +0.j        , 1.        +0.j        ,
       0.69134172+0.12093555j, 0.10332333+0.07968668j])
```
