首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >频带的Python信号模拟

频带的Python信号模拟
EN

Stack Overflow用户
提问于 2015-06-30 07:17:18
回答 1查看 1.1K关注 0票数 0

我试图产生一个特定频带的信号。我尝试了while &for循环,但是没有得到一个足够的解决方案。

代码语言:javascript
复制
import numpy as np

amp = 1.
sfreq = 1000.
duration = 1000.
nse_amp = 0.9
#____
freq_steps = 0.1
freq_start = 200
freq_end = 220
freq_band = np.arange(freq_start,freq_end,freq_steps)
sig_freq1 = freq_band
#____
n_epochs = 120
epoch_length = 1 # make epoch of 1 second each
times = np.arange(0,epoch_length,1/(sfreq))

def simulate_x_y(times, n_epochs, amp, sig_freq1, nse_amp):
    x  = np.zeros((n_epochs, times.size))
    for i in range(0, n_epochs):
        for j in xrange(freq_start, freq_end):
             x[i] = amp  * np.sin(2 * np.pi * freq_band[j] * times)

    return x

我希望x有一个从200到220的频带。另外,我不希望数组中的x.shape (120, 1000)不被更改。有人做过类似的事吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-30 09:16:24

解决了问题。比我想象的要容易得多。对所有好奇的人来说。

代码语言:javascript
复制
import numpy as np

amp = 1.
sfreq = 1000.
duration = 1000.
nse_amp = 0.9
freq1_start = 200
freq1_end = 300
freq_band1 = np.linspace(freq1_start, freq1_end, times.size)
#____
n_epochs = 120
epoch_length = 1 # make epoch of 1 second each
times = np.arange(0,epoch_length,1/(sfreq))

def simulate_x_y(times, n_epochs, amp, freq_band1):
    x  = np.zeros((n_epochs, times.size))
    for i in range(0, n_epochs):
                    x[i] = (amp  * np.sin(2 * np.pi * freq_band1 * times))
    return x
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31131925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档