Quick Start¶
This guide will help you get started with the Python interface to pydvma quickly — scripting acquisition and analysis in a notebook.
Prefer a point-and-click interface?
For interactive work, use the web logger —
including a no-install browser app at
torebutlin.github.io/pydvma/app/.
You can also have both at once: session = dvma.launch(settings)
starts the web logger from a notebook and hands captures back as
Python objects (session.data) — see
the notebook front door.
The web logger replaced the old desktop Qt Logger, which has
been removed (its last version is the qt-final git tag) — see
From the Qt logger.
Opening the Template¶
The easiest way to get started is to use the provided Jupyter notebook template:
- Navigate to your pydvma installation directory
- Open
pydvma_template.ipynbin Jupyter
Alternatively, you can start from scratch in any Jupyter notebook or Python script.
Basic Setup¶
Import and Configure¶
import pydvma as dvma
import matplotlib.pyplot as plt
import numpy as np
# For interactive plots in Jupyter
%matplotlib widget
Create Settings¶
# Create default settings
settings = dvma.MySettings()
# Customize as needed
settings.fs = 10000 # Sampling frequency in Hz
settings.stored_time = 2.0 # Duration in seconds
settings.channels = 2 # Number of channels
Record data¶
Record straight from Python with log_data. For a point-and-click
interface — live monitoring, view switching, modal fitting — use the
web logger instead; this guide covers the
scripting path.
# Record a dataset using the settings above
dataset = dvma.log_data(settings, test_name="recording_01")
dataset is a DataSet you can analyse, plot, save, and export.
Your First Measurement¶
Programmatic Recording¶
Record data programmatically:
# Record data
dataset = dvma.log_data(settings, test_name="test_01")
# Access the recorded data
time_data = dataset.time_data_list[0]
t = time_data.time_axis
y = time_data.time_data
# Plot
plt.plot(t, y)
plt.xlabel('Time (s)')
plt.ylabel('Amplitude')
plt.show()
Basic Analysis¶
Compute FFT¶
# Calculate FFT
freq_data = dvma.calculate_fft(time_data, window='hann')
# Plot
plt.figure()
plt.plot(freq_data.freq_axis, np.abs(freq_data.freq_data))
plt.xlabel('Frequency (Hz)')
plt.ylabel('Magnitude')
plt.xlim([0, 1000])
plt.yscale('log')
plt.show()
Calculate Transfer Function¶
# For multi-channel data, calculate transfer function
# Channel 0 is input, others are outputs
tf_data = dvma.calculate_tf(time_data, ch_in=0, window='hann')
# Plot magnitude
plt.figure()
plt.plot(tf_data.freq_axis, np.abs(tf_data.tf_data[:, 0]))
plt.xlabel('Frequency (Hz)')
plt.ylabel('|H(f)|')
plt.yscale('log')
plt.show()
Generate Sonogram¶
# Calculate sonogram (spectrogram)
sono_data = dvma.calculate_sonogram(time_data)
# Plot
plt.figure()
plt.pcolormesh(sono_data.time_axis, sono_data.freq_axis,
20*np.log10(np.abs(sono_data.sono_data[:, :, 0])))
plt.ylabel('Frequency (Hz)')
plt.xlabel('Time (s)')
plt.colorbar(label='Magnitude (dB)')
plt.show()
Saving and Loading Data¶
Export to Matlab¶
Export to CSV¶
Next Steps¶
- Explore the User Guide for more detailed information
- Check out Examples for common use cases
- Review the API Reference for function details