## Get the Books

Enjoying these notebooks and want to support the work? Check out the practical books on Data Science, Visualisation, and Evolutionary Algorithms. # Multiple Sine Waves in the Time Domain

Contents

## Preamble¶

In :
```# used to create block diagrams
%xdiag_output_format svg

import numpy as np                   # for multi-dimensional containers
import pandas as pd                  # for DataFrames
import plotly.graph_objects as go    # for data visualisation
import plotly.io as pio              # to set shahin plot layout
from plotly.subplots import make_subplots

pio.templates['shahin'] = pio.to_templated(go.Figure().update_layout(margin=dict(t=0,r=0,b=40,l=40))).layout.template
pio.templates.default = 'shahin'```

## Creating Sine Waves¶

In a previous section we looked at how to create a single Sine Wave and visualise it in the time domain.

In :
```sample_rate = 1000
start_time = 0
end_time = 10

time = np.arange(start_time, end_time, 1/sample_rate)

frequency = 3
amplitude = 1
theta = 0

sinewave = amplitude * np.sin(2 * np.pi * frequency * time + theta)

fig = go.Figure(layout=dict(xaxis=dict(title='Time (sec)'),yaxis=dict(title='Amplitude')))
fig.show()```

## Creating Multiple Sine Wave¶

Let's create and plot five sine waves. Let's start by defining our time window and sample rate.

In :
```sample_rate = 1000
start_time = 0
end_time = 10
theta = 0

time = np.arange(start_time, end_time, 1/sample_rate)```

Now we'll store their frequencies in a `list` named `frequency`, and their amplitudes in a `list` named `amplitude`.

In :
```frequency = [3, 5, 2, 1, 10]
amplitude = [1, 2, 7, 3, 0.1]```

Finally, let's loop through our five frequency/amplitude values and use them to calculate and visualise the sine waves using subplots.

In :
```fig = make_subplots(rows=5, cols=1, shared_xaxes=True)

for i in range(5):
sinewave = amplitude[i] * np.sin(2 * np.pi * frequency[i] * time + theta)
fig.add_scatter(x=time, y=sinewave, row=i+1, col=1, name=f"wave {i+1}")

fig.show()```