HEMS
HEMS

Reputation: 307

How to bias an absolute sine wave in Python

I am using the below python code so as to bias an absolute sine wave. I would like to have only the crest part of the wave and not the trough part even after positive biasing.Here I am unable achieve continuous crest signal after positive biasing. Can any one help me in this?

Usage: Keeping the input signals above the threshold even during dynamic shift of threshold.

import matplotlib.pyplot as plt
import numpy as np

Bias=5;
x=np.linspace(-20,20,1000);
y=np.abs(np.sin(x)+Bias);
#Bias=np.zeros_like(x); # This is not working

y[(y<=Bias)]= Bias + y # This is not working
plt.plot(x,y)
plt.grid()
plt.show()

Upvotes: 0

Views: 848

Answers (1)

Reblochon Masque
Reblochon Masque

Reputation: 36682

It is a litle bit unclear what you are asking... Maybe you want to try this:

import matplotlib.pyplot as plt
import numpy as np
Bias=5;

x = np.linspace(-20, 20, 1000);
y = np.abs(np.sin(x))
y = y + Bias  

plt.plot(x, y)
plt.grid()
plt.show()

enter image description here

or this:

import matplotlib.pyplot as plt
import numpy as np
Bias=5;

x=np.linspace(-20,20,1000);
y=np.abs(np.sin(x) + Bias);

y[(y<=Bias)]= Bias

plt.plot(x,y)
plt.grid()
plt.show()  

enter image description here

Upvotes: 1

Related Questions