samples = int(duration * fs)


c = 343.0
mean_mu_squared = 3.0e-6
distance = 2000.0
f0 = 200.0
L = 12.0

t = np.arange(samples) / fs

x = np.sin(2.0*np.pi*f0*t)

spacing = np.zeros(samples)
turbulence = Turbulence(spacing, c, target_max_frequency, mean_mu_squared, distance, f0, L, samples, saturation=True)
turbulence.randomize().generate()
y = turbulence.apply_single_modulation(x)

from acoustics.standards.iec_61672_1_2013 import fast

fig = plt.figure()

ax0 = fig.add_subplot(211)
ax0.plot(t, x, linestyle='-', label='$x(t)$')
ax0.plot(t, y, linestyle='--', label='$y(t)$')
ax0.set_title("Instantaneous pressure $p(t)$")
ax0.set_xlim(0.0, f0/fs)
ax0.set_xlabel('$t$ in s')
ax0.set_ylabel('$p$ in Pa')
ax0.grid()
target_max_frequency = 5000.0 # Max valid frequency in Hz
duration = 10.0 # Duration of the signal

fs = 2.0 * target_max_frequency

samples = int(duration * fs)


c = 343.0
mean_mu_squared = 3.0e-6
distance = 2000.0
f0 = 200.0
L = 12.0

spacing = np.zeros(samples)
t = Turbulence(spacing, c, target_max_frequency, mean_mu_squared, distance, f0, L, samples, saturation=True)

t.randomize().generate()
#t.plot_modulation_signal('../figures/modulations.png')

x = t.modulation_signal
t= t.times

fig = plt.figure()

ax0 = fig.add_subplot(211)
ax0.plot(t, np.abs(x), linestyle='-')
ax0.set_title("Amplitude modulation $e^{\chi (t)}$")
ax0.set_xlabel('$t$ in s')
ax0.set_ylabel('$e^{\chi}$ in Pa')
ax0.grid()
c = 343.0
mean_mu_squared = 3.0e-6
distance = 2000.0
f0 = 200.0
L = 12.0

t = np.arange(samples) / fs

x = np.sin(2.0 * np.pi * f0 * t)

spacing = np.zeros(samples)
turbulence = Turbulence(spacing,
                        c,
                        target_max_frequency,
                        mean_mu_squared,
                        distance,
                        f0,
                        L,
                        samples,
                        saturation=True)
turbulence.randomize().generate()
y = turbulence.apply_single_modulation(x)

from acoustics.standards.iec_61672_1_2013 import fast

fig = plt.figure()

ax0 = fig.add_subplot(211)
ax0.plot(t, x, linestyle='-', label='$x(t)$')
ax0.plot(t, y, linestyle='--', label='$y(t)$')
ax0.set_title("Instantaneous pressure $p(t)$")