Daniel Velden
Daniel Velden

Reputation: 179

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.

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. Do anyone have done something similar ?

Upvotes: 0

Views: 1244

Answers (1)

Daniel Velden
Daniel Velden

Reputation: 179

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

Upvotes: 1

Related Questions