0
$\begingroup$

I am trying to plot cos(x) + isin(x)

this is a 2 part question

part 1

I am tryin to plot a signal cos(x) + i*sin(x)

In python when i am trying to calculate np.sqrt(-1) for i,It is giving NaN Thats why i am not getting any plot of the data

Sample_rate = 1000 
Duration = 5
i = np.sqrt(-1)
print(i)
def generate_sine_and_cosine_wave(freq, sample_rate, duration):
    sines = np.linspace(0, duration, sample_rate*duration, endpoint=False)
    frequencies_sines = sines * freq
    cosines = np.linspace(1, duration, sample_rate*duration, endpoint=False)
    frequencies_cosines = cosines * freq
    x = i*sines+cosines
    y = np.cos((2 * np.pi) * frequencies_cosines +frequencies_sines)
    return x, y

x, y = generate_sine_and_cosine_wave(2, Sample_rate, Duration)
plt.plot(x, y)
plt.show()

part 2

And if i try to code to get cos(x) + sin(x)? My actual intention was to produce the signal with 2 HZ frequency but when I am trying to produce datapoints for the signal(for cos(x) + i sin(x)), then i am unable to produce the frequency as 2 HZ

Help me to correct the code

$\endgroup$
5
  • $\begingroup$ Hi John! You actually forgot to ask a question! $\endgroup$ Jul 13 '21 at 10:41
  • $\begingroup$ but: you really need to read the python documentation: 1j is the imaginary unit in python. sqrt, on the other hand, or negative real numbers is undefined. $\endgroup$ Jul 13 '21 at 10:42
  • $\begingroup$ yeah that is why can you suggest any other way to implement a code to plot that complex signal>> $\endgroup$ Jul 13 '21 at 10:46
  • $\begingroup$ I just did exactly that! 1j is valid python for "imaginary unit". And I can't read the python docs for you! $\endgroup$ Jul 13 '21 at 10:47
  • $\begingroup$ ohh okay thanks.... $\endgroup$ Jul 13 '21 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.