改变幅度和pylab 中 numpy.sin(wt) 的频率
对于另一个项目的一部分,我只需要制作一个频率为 f 的简单正弦波。
更改“样本”会对 pylab 图产生一些奇怪的影响,我只是不知道为什么!
使用样本 = 500 给出频率 = 1/50 Hz 的图。
使用样本 = 1000 给出频率 = 1/100 Hz 的图。
然后,对于 5000 和 10000 等较大样本,绘制的波会沿 t 轴以模式改变振幅。
import numpy as N
f = 10.
w = 2. * N.pi * f
time_interval = 100
samples = 5000
t = N.linspace(0, time_interval, samples)
y = N.sin(w * t)
pylab.plot(t, y)
pylab.show()
这里的任何帮助都会很棒!我只想要一个基本的正弦波,但似乎无法做到这一点!
For part of another project, I just need to make a simple sine wave with some frequency f.
Changing "samples" gives some strange effects on the pylab plot and I just don't know why!
using samples=500 gives a plot with frequency = 1/50 Hz.
using samples=1000 gives a plot with frequency = 1/100 Hz.
then with larger samples like 5000 and 10000, the plotted wave changes amplitude along the t axis, in patterns.
import numpy as N
f = 10.
w = 2. * N.pi * f
time_interval = 100
samples = 5000
t = N.linspace(0, time_interval, samples)
y = N.sin(w * t)
pylab.plot(t, y)
pylab.show()
Any help here would be great! I just want a basic sine wave but can't even seem to do that!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您对
样本
有轻微的误解。它仅给出时间的分辨率。尝试使用time_interval= 1
进行绘图并改变样本
(从较小的值(例如 10)开始,然后逐渐增加)。你会看到的。I think you have a slight misconception with
samples
. It only gives the resolution of time. Try to plot withtime_interval= 1
and vary thesamples
(Start with small values like 10 and increase it then gradually). You'll see.为了使 eat 的答案明确,我将
time_interval
设置为 1,并改变samples
,正如他建议的那样:50 个样本对于
time_interval
显然是不够的1 个;这就是为什么 5000 个样本对于time_interval
100 来说是不够的。To make eat's answer explicit, I set
time_interval
to 1, and variedsamples
, as he suggested:50 samples is clearly not enough for a
time_interval
of 1; This is why 5000 isn't enough samples for atime_interval
of 100.这是一个基本示例。
仔细观察正在创建的数据:
x
是一个从 0 到 149.8 的数组(技术上 datatype = numpy.ndarray),间隔为 0.2,即输入 x 可以看到array([0. , 0.2, 0.4, ..., 149.8])
y
是一个从 sin(0) 到 sin(149.8) 的数组,即array([0., 0.198. ..,...,-0.839...])
Here's a basic example.
Look closely at the data being created:
x
is an array (technically datatype = numpy.ndarray) from 0 to 149.8 with an interval of 0.2, i.e. type x to seearray([0., 0.2, 0.4, ..., 149.8])
y
is an array from sin(0) to sin(149.8), i.e.array([0., 0.198..., ..., -0.839...])
根据给定的参数:频率,F = 10 Hz,时间周期,T = 100 s,T = 100 s 的样本数,N = 5000。
这意味着,周期数 = F * T = 10 * 100 = 1000。选择 T = 10/F,以可视化 10 个周期。这意味着我们将在 1 秒内从 10 Hz 正弦波获得 10 个周期。这也意味着我们将在 10 个周期中有 5000 个样本,或者每个周期有 500 个样本,这对于信号的复制来说是相当多的。
From the given parameters: Frequency, F = 10 Hz, Time period, T = 100 s and Number of samples for T = 100 s, N = 5000.
This implies, the No. of cycles = F * T = 10 * 100 = 1000. Let choose T = 10/F, to visualize 10 cycles. This means that we will get 10 cycles from the 10 Hz sine wave in 1 sec. This also means that we will have 5000 samples for the 10 cycles, or 500 samples per cycle which is quite a bit for replication of the signal.