Ejemplo n.º 1
0
general_options = {"xlabel": "time (seconds)", "ylabel": "Amplitude"}

sawtooth_line_options = [{"label": f"N = {n}"} for n in Ns]
sawtooth_line_options.append({
    "label": "True signal",
    "linewidth": 2.5,
    "color": "black"
})
sq_line_options = [{"label": f"N = {n}"} for n in Ns]
sq_line_options.append({
    "label": "True signal",
    "linewidth": 2,
    "color": "black"
})

# Encapsulate and Plot signals
sawtooth_fig = FigData(
    ts,
    sawtooths,
    line_options=sawtooth_line_options,
    title="Sawtooth wave approximated with a Fourier series",
    **general_options)
square_fig = FigData(ts,
                     squares,
                     line_options=sq_line_options,
                     title="Square wave approximated with a Fourier series",
                     **general_options)

aplot.single_plot(sawtooth_fig)
aplot.single_plot(square_fig)
Ejemplo n.º 2
0
fft_stack_fig = FigData(xs=x,
                        ys=y,
                        zs=[np.abs(np.array(ws_ffts))**2],
                        title="STFT surface from stacking FFT",
                        plot_type="plot_surface",
                        xlabel="Frequency (Hz)",
                        ylabel="Time (s)",
                        zlabel="Normalised Amplitude",
                        line_options=[{"cmap": "viridis"}],
                        options=["invert_xaxis"],
                        figsize=(6, 5),
                        colorbar_params={"pad": 0.1,
                                         "vmax": 0.25})
aplot.single_plot(fft_stack_fig,
                  auto_timestamp=False,
                  folder="stft_schematic",
                  savefig_path="fft_stack.png"
                  )

# Plot the original signal and the STFT
signal_fig = FigData(xs=nst.samp_nums,
                     ys=[nst.data],
                     title="Non stationary signal",
                     plot_type="plot",
                     xlabel="Time (s)",
                     ylabel="Amplitude",
                     figsize=(5, 2.5))
aplot.single_plot(signal_fig,
                  auto_timestamp=False,
                  folder="stft_schematic",
                  # savefig_path="signal.png"
Ejemplo n.º 3
0
    f"STFT Magnitude (Zoomed) of {scale_name} Major scale\n(Artificial clarinet sound)",
    line_options=[{
        "vmin": 0,
        "vmax": Zxx_max,
        "shading": 'gouraud'
    }],
    options=["grid"],
    plot_type="pcolormesh",
    xlabel="Time (s)",
    ylabel="Frequency (Hz)",
    fit_data=False)

#
# Display results
#

aplot.single_plot(fig_data=signal_fig)

aplot.single_subplots(
    grid_size=(2, 2),
    fig_data={
        (0, 0): fft_fig,
        (1, 0): fft_zoomed_fig,
        (0, 1): stft_fig,
        (1, 1): stft_zoomed_fig
    },
    individual_figsize=(6, 4),
    savefig_path=f"STFT_Clarinet_{scale_name}_Major_scale_sampr={samp_rate}")

# wav.write(f"audio/cl_{scale_name}_scale", nst)
Ejemplo n.º 4
0
#
# Generate data
#
signals = [
    ss.SineSignal(freq=freqs[i],
                  duration=durations[i],
                  chop_range=chop_ranges[i]) for i in range(len(freqs))
]
nst = nsts.NonStationarySignal(signals)

#
# Encapsulate data in FigData
#

fig = FigData(xs=nst.samp_nums,
              ys=nst.data,
              title="Non stationary signal",
              plot_type="plot",
              xlabel="Time (s)",
              ylabel="Amplitude")

#
# Plot
#
aplot.single_plot(fig)

#
# Output audio
#
wav.write("audio/nonst8", nst, dtype=np.uint8)
Ejemplo n.º 5
0
duration = 0.01
samp_rate = 44100

cl_f = 466.16 / 2  # written pitch C4, actual pitch is Bb4
cl_pitch_label = "C4"

signal_params = {
    "duration": duration,
    "samp_rate": samp_rate,
    "freq": cl_f,
    "options": {
        "normalize": True
    }
}

# Generate clarinet signal using predefined amplitudes
cl_signal = pcs.ClarinetApproxSignal(**signal_params)

# Figure options
cl_fig = FigData(xs=cl_signal.samp_nums,
                 ys=[cl_signal.data],
                 line_options=[{"label": f"f0 = {cl_f}Hz"}],
                 xlabel="Time (seconds",
                 ylabel="Amplitude",
                 title=f"Synthesized clarinet (written pitch {cl_pitch_label})",
                 figsize=(5, 3)
                 )

# Plot signals
aplot.single_plot(cl_fig)