[英]Python Signal simulation for frequency band
I try to generate a signal with a specific frequency band. 我尝试生成具有特定频段的信号。 I tried while & for-loops, but doesn't get an adequate solution. 我尝试了while和for-loops,但没有得到足够的解决方案。
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
I want x to have a frequency band from 200 to 220. Additionally I don't want the from of my array x.shape (120, 1000)
not being changed. 我希望x的频带为200到220。此外,我不希望数组x.shape (120, 1000)
的from x.shape (120, 1000)
。 Do anyone have done something similar ? 有人做过类似的事情吗?
Solved the problem. 解决了问题。 It was easier than I expected it to be. 这比我预期的要容易。 For everyone that is curious. 对于每个好奇的人。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.