Skip to content
Advertisement

Python: Plot sin wav with 3 discrete amplitudes

Using the code below I am able to create a sign wave

JavaScript

enter image description here

I would like to create a sin wave which changes it’s amplitude at time 4s, and 8s so that the sin wave looks like the image below

enter image description here

I know how to create each of the 3 sin waves in that img, but I don’t know how to combine them into one.

I’ve tried to combine the first two by doing

JavaScript

and receive the error

JavaScript

Advertisement

Answer

You can concatenate arrays by making a list of them as parameter to np.concatenate (e.g. np.concatenate([array1,array2,array3]) or as tuple: np.concatenate((array1,array2,array3))) :

JavaScript

resulting plot

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement