<jupyter_start><jupyter_text>Table of Contents1&nbsp;&nbsp;Import time signal1.1&nbsp;&nbsp;Load signal from .wav file1.2&nbsp;&nbsp;Load signal from a .mat file1.3&nbsp;&nbsp;Load signal from a .uff file2&nbsp;&nbsp;Compute nth octave band spectrum  Basic operations Import time signalIn MOSQITO, time signals from .wav, .mat and .uff files can be loaded. The following commands are used to import the "load" function.<jupyter_code># Add MOSQITO to the Python path
import sys
sys.path.append('..')

# To get inline plots (specific to Jupyter notebook)
%matplotlib notebook

# Import numpy
import numpy as np
# Import plot function
import matplotlib.pyplot as plt
# Import load function
from mosqito.utils import load

# Import MOSQITO color sheme [Optional]
from mosqito import COLORS<jupyter_output><empty_output><jupyter_text>Load signal from .wav fileYou can use any .wav file to perform the tutorial or you can download the [woodpecker audio recording](../validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex%20B.5/Test%20signal%2024%20%28woodpecker%29.wav) that is one of the validation signals delivered with the ISO 532-1 standard. To load a signal from a .wav file, 2 input arguments are needed : - the file path, - a calibration factor in [Pa/FS]For the calibration of the WAVE files, the ISO 532-1 standard specifies that 0 dB (relative to full scale) shall correspond to a sound pressure level of 100 dBSPL. 100 dBSPL being equivalent to 2 Pa_rms or $2\sqrt(2)$ Pa_peak, the calibration factor shall be set to $2\sqrt(2)$ [Pa/FS].Note that only the first channel of mutlichannels files will be loaded.<jupyter_code># define the path to the wav file (to be replaced by your own path)
file_path = "../validations/sq_metrics/loudness_zwtv/input/ISO_532-1/Annex B.5/Test signal 24 (woodpecker).wav"
# load signal
sig_wav, fs_wav = load(file_path, wav_calib=2 * 2 **0.5)
# plot signal
t_wav = np.linspace(0, (len(sig_wav) - 1) / fs_wav, len(sig_wav))
plt.figure(1)
plt.plot(t_wav, sig_wav, color=COLORS[0])
plt.xlabel('Time [s]')
plt.ylabel('Acoustic pressure [Pa]')<jupyter_output><empty_output><jupyter_text>Load signal from a .mat fileYou can use any .mat file to perform the tutorial or you can download the [noise signal](../tests/input/noise_1Pa_RMS.mat) from MOSQITO. To load the signal, 3 input arguments are needed : - the file path, - the name of the time signal matlab variable - the name of the sampling frequency matlab variable<jupyter_code># define the path to the mat file (to be replaced by your own path)
file_path = "../tests/input/noise_1Pa_RMS.mat"
# load signal
sig_mat, fs_mat = load(file_path, mat_signal="signal", mat_fs="fs")
# plot signal
t_mat = np.linspace(0, (len(sig_mat) - 1) / fs_mat, len(sig_mat))
plt.figure(2)
plt.plot(t_mat, sig_mat, color=COLORS[0])
plt.xlabel('Time [s]')
plt.ylabel('Acoustic pressure [Pa]')<jupyter_output>[Info] Signal resampled to 48 kHz to allow calculation.<jupyter_text>Load signal from a .uff fileYou can use any .mat file to perform the tutorial or you can download the [noise signal](../tests/input/noise_1Pa_RMS.uff) from MOSQITO. To load the signal, 1 input arguments is needed : - the file path<jupyter_code># define the path to the uff file (to be replaced by your own path)
file_path = "../tests/input/noise_1Pa_RMS.uff"
# load signal
sig_uff, fs_uff = load(file_path)
# plot signal
t_uff = np.linspace(0, (len(sig_uff) - 1) / fs_uff, len(sig_uff))
plt.figure(3)
plt.plot(t_uff, sig_uff, color=COLORS[0])
plt.xlabel('Time [s]')
plt.ylabel('Acoustic pressure [Pa]')<jupyter_output>[Info] Signal resampled to 48 kHz to allow calculation.<jupyter_text>Compute nth octave band spectrumThe nth octave band spectrum of a signal can be computed by using the noct_spectrum function. The syntax is detailed below.<jupyter_code># Load function
from mosqito.sound_level_meter import noct_spectrum

# Compute third octave band spectrum
spec_3, freq_3 = noct_spectrum(sig_wav, fs_wav, fmin=24, fmax=12600, n=3)

# Compute 24th octave band spectrum
spec_24, freq_24 = noct_spectrum(sig_wav, fs_wav, fmin=24, fmax=12600, n=24)

# plot
plt.figure(4)
plt.semilogx(freq_3, 20*np.log10(spec_3/2e-5), label="1/3 oct.", color=COLORS[0])
plt.semilogx(freq_24, 20*np.log10(spec_24/2e-5), label="1/24 oct.", color=COLORS[1])
plt.legend()
plt.xlabel('Freq [Hz]')
plt.ylabel('Acoustic pressure [dB re. 2e-5 Pa]')<jupyter_output><empty_output><jupyter_text>---<jupyter_code>from datetime import date
print("Tutorial generation date:", date.today().strftime("%B %d, %Y"))<jupyter_output>Tutorial generation date: February 23, 2022
{'fraction_non_alphanumeric': 0.1099236641221374, 'fraction_numerical': 0.030534351145038167, 'mean_word_length': 5.431977559607293, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '417950', 'license': 'Apache-2.0', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1590, 'n_words': 525, 'path': 'tutorials/tuto_signal_basic_operations.ipynb', 'repo_name': 'MitchellAcoustics/MoSQITo', 'size': '4585'}