简体   繁体   English

Python中正弦波发生器的不同频率

[英]Different frequencies for sine wave generator in python

I am using the code below to generate a sine wave and it works fine. 我正在使用下面的代码来生成正弦波,并且工作正常。 However, when I try to use large frequencies 500kHz and change the time period to 0.2us I expect to get a full sine wave with time period of 0.2us but what I get is just a straight line don't know why. 但是,当我尝试使用500kHz的较大频率并将时间段更改为0.2us时,我希望得到一个完整的正弦波,时间段为0.2us,但是我得到的只是一条直线,不知道为什么。

def sampled_sine_wave(freq):
    samples = 1000
    time_period = 2e-7
    time = linspace(0,time_period,samples)
    _ = plot(time,[sin(t*freq*2*np.pi) for t in time], linewidth=2)
    Vin1=([np.sin(t*freq*2*np.pi) for t in time])
    #print (Vin1)
return Vin1

Can somebody tell me why I am getting that and how can I solve it. 有人可以告诉我为什么要得到它以及如何解决它。 Thanks 谢谢

As mentioned in the comments, you probably aren't actually getting a straight line . 如评论中所述, 您实际上可能并没有获得一条直线 If you graph it in that range, it looks almost like a straight line. 如果在该范围内绘制图形 ,它看起来几乎像一条直线。 In fact, at the edge of that range, at x=2e-7 , that sine function and 5e5*x have less than a 7% difference . 实际上,在该范围的边缘,在x=2e-7 ,正弦函数与5e5*x 相差不到7% You probably meant to use a full period, time_period = 2e-6 , which looks more like a sine wave . 您可能打算使用一个完整的时间段time_period = 2e-6 ,它看起来更像一个正弦波 You seem to know that the period of that function is 2 microseconds, but 2 microseconds is 2e-6 seconds, not 2e-7 seconds . 您似乎知道该功能的周期是2微秒,但是2微秒是2e-6秒,而不是2e-7秒


Wow, this took a while to write for such a short answer. 哇,花了一段时间写了这么短的答案。 I kept messing up and dividing by pi instead of multiplying and pasting the wrong links. 我一直搞乱并用pi除,而不是乘并粘贴错误的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM