【问题标题】:Python Signal simulation for frequency band频段的 Python 信号模拟
【发布时间】:2015-06-30 07:17:18
【问题描述】:

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

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) 的来源不被更改。 有没有人做过类似的事情?

【问题讨论】:

  • 您的 freq_start 仅用于您的 freq_band。您的 freq_band 无处使用。如果我是 Python 解释器,我不知道如何正确地为您服务……

标签: python numpy signal-processing frequency


【解决方案1】:

解决了这个问题。 这比我预期的要容易。适合所有好奇的人。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-12
    • 2013-05-23
    • 1970-01-01
    • 2020-08-29
    • 2013-02-13
    • 2021-09-07
    • 1970-01-01
    相关资源
    最近更新 更多