# generate a repeated square pulse train in python

Generate a pulse train with -2dBFS pulses of 20 sample duration every 8 seconds. I have referred here to generate a pulse train but not able to repeat it. How can I repeat this audio signal every 8 second and between aforementioned signal there has to be silence?

from scipy import signal
import matplotlib.pyplot as plt
import numpy as np

sampling_rate = 16000
time_seconds = 1
number_of_pulses = 20
pulse_frequency = 1/(time_seconds/(number_of_pulses/2))
t = np.linspace(0, time_seconds, sampling_rate, endpoint=False)
signal_dbfs = 0.8 #-1dBFS
plt.plot(t, signal.square(2 * np.pi * pulse_frequency * t) * signal_dbfs)
plt.ylim(-2, 2)
plt.show()

• Hi, @user3053970, and welcome to DSP.SE. To make it easier for people here to help with your problem it is usually beneficial to clearly state your question, and, if possible, to describe what you have tried and where exactly you're stuck. For example, this question lacks a clear title (actually, the title is not formulated as a question here). Also, the question asked, i.e., "How can I repeat this audio signal [...]" refers to some audio signal, but it is not clear which audio signal you mean. In many cases, trying to describe the question as clearly as possible may lead you to the answer. Dec 26, 2019 at 8:44
• Is the train 20 sample duration? (In which case, what is the pulse frequency?) Or are the pulses 20 sample duration? (Meaning half-wavelength? How many pulses?) Since this is for audio, do you want the pulses bandlimited? Jan 28, 2020 at 19:40
• 0.8 #-1dBFS is not correct. -2 dBFS is an amplitude of 0.794328 Jan 28, 2020 at 19:42
• @endolith: how did you get that number? Jan 30, 2020 at 3:39
• 1.0 = 0 dBFS, and dB is 20*log10(number), so inverse is 10^(number/20) Jan 30, 2020 at 17:36

Actually, as mention by @applesoup your question is not clear but as far as I understood you can repeat the signal using

numpy.matlib.repmat(a, m, n)
Repeat a 0-D to a 2-D array or matrix MxN times.
Parameters:
a : array_like
The array or matrix to be repeated.
m, n : int
The number of times a is repeated along the first and second axes.
Returns:
out : ndarray
The result of repeating a.


For further better understanding, you can look this link

• I don't think this is what I am looking for. I have updated the question. Dec 29, 2019 at 5:34