SCRIPTS INTERPOLATION basicΒΆ

# -*-Python-*-
# Created by bgrierson at 02 Sep 2017  06:04

"""
This script demonstrates interpolation methods

"""

periods = 2.5

# Create a pulse train
t = linspace(0, 2 * np.pi * periods, int(periods * 100))
pulses = scipy.signal.square(t)

# Interpolate onto a reduced timebase using interp1d
t_ds = linspace(0, 2 * np.pi * periods, 51)
pulses_ds = interpolate.interp1d(t, pulses)(t_ds)

# Interpolate onto a reduced timebase using convolution
pulses_nu_conv_boxcar_ncausal = nu_conv(pulses, xi=t, window_size=np.pi / 2, window_function='boxcar', causal=False, std_dev='population')
pulses_nu_conv_boxcar_causal = nu_conv(pulses, xi=t, window_size=np.pi / 2, window_function='boxcar', causal=True, std_dev='population')
pulses_nu_conv_gaussian_ncausal = nu_conv(
    pulses, xi=t, window_size=np.pi / 2, window_function='gaussian', causal=False, std_dev='population'
)
pulses_nu_conv_gaussian_causal = nu_conv(pulses, xi=t, window_size=np.pi / 2, window_function='gaussian', causal=True, std_dev='population')

fn = FigureNotebook()
fig, ax = fn.subplots()
ax.plot(t, pulses, marker='o', alpha=0.2, label='Pulses')
ax.plot(t_ds, pulses_ds, marker='o', label='Downsampled/10')
ax.set_ylim([-1.5, 1.5])
ax.set_title('Straight interpolation downsample')
ax.legend()

fig, ax = fn.subplots()
ax.plot(t, pulses, marker='o', alpha=0.2, label='Pulses')
uband(t, pulses_nu_conv_boxcar_ncausal, ax=ax, marker='o', label='Downsample/5, boxcar, not causal')
uband(t, pulses_nu_conv_boxcar_causal, ax=ax, marker='o', label='Downsample/5, boxcar, causal')
ax.set_ylim([-1.5, 1.5])
ax.set_title('nu_conv Interpolation')
ax.legend()

fig, ax = fn.subplots()
ax.plot(t, pulses, marker='o', alpha=0.2, label='Pulses')
uband(t, pulses_nu_conv_gaussian_ncausal, ax=ax, marker='o', label='Downsample/5, gaussian, not causal')
uband(t, pulses_nu_conv_gaussian_causal, ax=ax, marker='o', label='Downsample/5, gaussian, causal')
ax.set_ylim([-1.5, 1.5])
ax.set_title('nu_conv Interpolation')
ax.legend()