import%20marimo%0A%0A__generated_with%20%3D%20%220.23.9%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20from%20scripts.learning_path_i18n%20import%20(%0A%20%20%20%20%20%20%20%20language_switch_markdown%2C%0A%20%20%20%20%20%20%20%20load_catalog%2C%0A%20%20%20%20%20%20%20%20locale_from_argv%2C%0A%20%20%20%20%20%20%20%20navigation_markdown%2C%0A%20%20%20%20)%0A%0A%20%20%20%20locale%20%3D%20locale_from_argv()%0A%20%20%20%20catalog%20%3D%20load_catalog(%2200_why_wandas%22%2C%20locale)%0A%0A%20%20%20%20def%20t(key%2C%20**values)%3A%0A%20%20%20%20%20%20%20%20return%20catalog.text(key%2C%20**values)%0A%0A%20%20%20%20return%20language_switch_markdown%2C%20locale%2C%20mo%2C%20navigation_markdown%2C%20t%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(f%22%23%20%7Bt('title')%7D%5Cn%5Cn%7Bt('intro')%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(language_switch_markdown%2C%20locale%2C%20mo)%3A%0A%20%20%20%20mo.md(language_switch_markdown(%2200_why_wandas%22%2C%20locale))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20scipy.signal%0A%0A%20%20%20%20import%20wandas%20as%20wd%0A%0A%20%20%20%20return%20np%2C%20plt%2C%20scipy%2C%20wd%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22challenge_toolchain%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22challenge_data_management%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22challenge_reproducibility%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22traditional_example%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plt%2C%20scipy%2C%20wd)%3A%0A%20%20%20%20_sampling_rate%20%3D%2016000%0A%20%20%20%20_duration%20%3D%201.0%0A%20%20%20%20generated%20%3D%20np.asarray(wd.generate_sin(freqs%3D%5B440%5D%2C%20duration%3D1.0%2C%20sampling_rate%3D16000).data)%0A%20%20%20%20waveform%20%3D%20generated%5B0%5D%20if%20generated.ndim%20%3D%3D%202%20else%20generated%0A%20%20%20%20_rng%20%3D%20np.random.default_rng(42)%0A%20%20%20%20waveform%20%3D%20waveform%20%2B%20_rng.normal(size%3Dwaveform.size)%0A%20%20%20%20(b%2C%20a)%20%3D%20scipy.signal.butter(4%2C%201000%20%2F%20(_sampling_rate%20%2F%202))%0A%20%20%20%20filtered%20%3D%20scipy.signal.filtfilt(b%2C%20a%2C%20waveform)%0A%20%20%20%20window%20%3D%20scipy.signal.windows.hann(len(filtered))%0A%20%20%20%20windowed%20%3D%20filtered%20*%20window%0A%20%20%20%20fft_result%20%3D%20np.fft.rfft(windowed%2C%20norm%3D%22forward%22)%0A%20%20%20%20_freqs%20%3D%20np.fft.rfftfreq(windowed.size%2C%20d%3D1%20%2F%20_sampling_rate)%0A%20%20%20%20(_fig%2C%20(_ax1%2C%20_ax2))%20%3D%20plt.subplots(2%2C%201%2C%20figsize%3D(10%2C%208))%0A%20%20%20%20_fig.suptitle(%22Traditional%20Approach%22)%0A%20%20%20%20time_axis%20%3D%20np.arange(filtered.size)%20%2F%20_sampling_rate%0A%20%20%20%20_ax1.plot(time_axis%2C%20filtered)%0A%20%20%20%20_ax1.set(title%3D%22Time%20Domain%20Signal%22)%0A%20%20%20%20_ax1.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20magnitude_db%20%3D%2020%20*%20np.log10(np.abs(fft_result)%20%2B%201e-10)%0A%20%20%20%20_ax2.plot(_freqs%2C%20magnitude_db)%0A%20%20%20%20_ax2.set(title%3D%22Filtered%20Spectrum%22%2C%20ylim%3D(-60%2C%200))%0A%20%20%20%20_ax2.grid(True%2C%20alpha%3D0.3)%0A%20%20%20%20plt.tight_layout()%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22wandas_approach%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plt%2C%20wd)%3A%0A%20%20%20%20signal%20%3D%20wd.generate_sin(freqs%3D%5B440%5D%2C%20duration%3D1.0%2C%20sampling_rate%3D16000)%0A%20%20%20%20signal%20%3D%20signal%20%2B%20np.random.randn(signal.n_samples)%0A%20%20%20%20result%20%3D%20signal.low_pass_filter(cutoff%3D1000).fft()%0A%20%20%20%20(_fig%2C%20(_ax1%2C%20_ax2))%20%3D%20plt.subplots(2%2C%201%2C%20figsize%3D(10%2C%208))%0A%20%20%20%20_fig.suptitle(%22Wandas%20Approach%22)%0A%20%20%20%20result.previous.plot(ax%3D_ax1%2C%20title%3D%22Time%20Domain%20Signal%22)%0A%20%20%20%20result.plot(ax%3D_ax2%2C%20title%3D%22Filtered%20Spectrum%22%2C%20ylim%3D(-50%2C%2010))%0A%20%20%20%20plt.tight_layout()%0A%20%20%20%20result.info()%0A%20%20%20%20_fig%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22integrated_frame%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22visualization%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(wd)%3A%0A%20%20%20%20signal_1%20%3D%20wd.generate_sin(freqs%3D%5B440%2C%20880%5D%2C%20duration%3D2.0%2C%20sampling_rate%3D16000)%0A%20%20%20%20signal_1.describe()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22environmental_analysis%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20wd)%3A%0A%20%20%20%20fs%20%3D%2051200%0A%20%20%20%20_duration%20%3D%2010%0A%20%20%20%20_time%20%3D%20np.arange(fs%20*%20_duration)%20%2F%20fs%0A%20%20%20%20np.random.seed(42)%0A%20%20%20%20ch1_noise%20%3D%20np.random.randn(fs%20*%20_duration)%20*%200.1%20%2B%200.05%20*%20np.sin(2%20*%20np.pi%20*%200.2%20*%20_time)%0A%20%20%20%20ch2_noise%20%3D%20np.random.randn(fs%20*%20_duration)%20*%200.15%0A%20%20%20%20ch3_noise%20%3D%20np.random.randn(fs%20*%20_duration)%20*%200.08%20%2B%200.03%20*%20np.sin(2%20*%20np.pi%20*%200.4%20*%20_time)%0A%20%20%20%20recording%20%3D%20wd.from_numpy(%0A%20%20%20%20%20%20%20%20data%3Dnp.array(%5Bch1_noise%2C%20ch2_noise%2C%20ch3_noise%5D)%2C%0A%20%20%20%20%20%20%20%20sampling_rate%3Dfs%2C%0A%20%20%20%20%20%20%20%20ch_labels%3D%5B%22Location%20A%22%2C%20%22Location%20B%22%2C%20%22Location%20C%22%5D%2C%0A%20%20%20%20%20%20%20%20ch_units%3D%22Pa%22%2C%0A%20%20%20%20)%0A%20%20%20%20a_weighted_rms_pa%20%3D%20recording.a_weighting().rms%0A%20%20%20%20reference_pressure_pa%20%3D%20recording.channels%5B0%5D.ref%0A%20%20%20%20a_fast_level_db_spl%20%3D%20recording.sound_level(%0A%20%20%20%20%20%20%20%20freq_weighting%3D%22A%22%2C%0A%20%20%20%20%20%20%20%20time_weighting%3D%22Fast%22%2C%0A%20%20%20%20%20%20%20%20dB%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20a_fast_level_db_spl.plot(%0A%20%20%20%20%20%20%20%20title%3Df%22A%2FF-weighted%20level%20(reference%20%7Breference_pressure_pa%3Ag%7D%20Pa)%22%2C%0A%20%20%20%20%20%20%20%20ylabel%3Df%22Level%20%5BdB%20SPL%20re%20%7Breference_pressure_pa%3Ag%7D%20Pa%5D%22%2C%0A%20%20%20%20)%0A%20%20%20%20recording.noct_spectrum().plot(%0A%20%20%20%20%20%20%20%20title%3D%22One-Third-Octave%20Band%20Spectrum%20of%20Ambient%20Recording%22%2C%0A%20%20%20%20%20%20%20%20Aw%3DTrue%2C%0A%20%20%20%20%20%20%20%20overlay%3DTrue%2C%0A%20%20%20%20%20%20%20%20ylim%3D(20%2C%2080)%2C%0A%20%20%20%20)%0A%20%20%20%20return%20a_weighted_rms_pa%2C%20recording%2C%20reference_pressure_pa%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(a_weighted_rms_pa%2C%20mo%2C%20recording%2C%20reference_pressure_pa%2C%20t)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20t(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22environment_result%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20channel_count%3Drecording.n_channels%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20labels%3D%22%2C%20%22.join(map(str%2C%20recording.labels))%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20rms%3Dstr(a_weighted_rms_pa)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20reference_pressure%3Df%22%7Breference_pressure_pa%3Ag%7D%22%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22ml_overview%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22ml_dataset_setup%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20wd)%3A%0A%20%20%20%20import%20os%0A%20%20%20%20import%20tempfile%0A%0A%20%20%20%20temp_dir%20%3D%20tempfile.mkdtemp()%0A%20%20%20%20_sampling_rate%20%3D%2016000%0A%20%20%20%20_duration%20%3D%2010.0%0A%20%20%20%20n_files%20%3D%2010%0A%20%20%20%20for%20i%20in%20range(n_files)%3A%0A%20%20%20%20%20%20%20%20_split%20%3D%20%22train%22%20if%20i%20%3C%208%20else%20%22validation%22%0A%20%20%20%20%20%20%20%20_split_dir%20%3D%20os.path.join(temp_dir%2C%20f%22split%3D%7B_split%7D%22)%0A%20%20%20%20%20%20%20%20os.makedirs(_split_dir%2C%20exist_ok%3DTrue)%0A%20%20%20%20%20%20%20%20_freqs%20%3D%20%5B440%20%2B%20i%20*%20100%2C%20880%20%2B%20i%20*%2050%5D%0A%20%20%20%20%20%20%20%20audio%20%3D%20wd.generate_sin(freqs%3D_freqs%2C%20duration%3D_duration%2C%20sampling_rate%3D_sampling_rate)%0A%20%20%20%20%20%20%20%20audio%20%3D%20audio%20%2B%20np.random.randn(audio.n_samples)%20*%200.1%0A%20%20%20%20%20%20%20%20filename%20%3D%20os.path.join(_split_dir%2C%20f%22audio_sample_%7Bi%20%2B%201%3A03d%7D.wav%22)%0A%20%20%20%20%20%20%20%20audio.to_wav(filename)%0A%20%20%20%20return%20n_files%2C%20temp_dir%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20n_files%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22dataset_created%22%2C%20file_count%3Dn_files))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22ml_preprocessing%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(temp_dir%2C%20wd)%3A%0A%20%20%20%20dataset%20%3D%20wd.from_folder(%0A%20%20%20%20%20%20%20%20folder_path%3Dtemp_dir%2C%0A%20%20%20%20%20%20%20%20lazy_loading%3DTrue%2C%0A%20%20%20%20%20%20%20%20recursive%3DTrue%2C%0A%20%20%20%20%20%20%20%20path_metadata%3DTrue%2C%0A%20%20%20%20)%0A%20%20%20%20discovered_count%20%3D%20len(dataset)%0A%20%20%20%20selected_dataset%20%3D%20dataset.select(split%3D%22train%22)%0A%0A%20%20%20%20source_frame%20%3D%20selected_dataset%5B0%5D%0A%20%20%20%20if%20source_frame%20is%20None%3A%0A%20%20%20%20%20%20%20%20raise%20RuntimeError(%22The%20first%20selected%20recording%20could%20not%20be%20loaded.%22)%0A%0A%20%20%20%20dataset%20%3D%20selected_dataset.trim(start%3D0%2C%20end%3D5).resample(target_sr%3D8000).normalize()%0A%20%20%20%20processed_frame%20%3D%20dataset%5B0%5D%0A%20%20%20%20if%20processed_frame%20is%20None%3A%0A%20%20%20%20%20%20%20%20raise%20RuntimeError(%22The%20first%20recording%20could%20not%20be%20preprocessed.%22)%0A%0A%20%20%20%20spectrogram_dataset%20%3D%20dataset.stft(n_fft%3D512%2C%20hop_length%3D256)%0A%0A%20%20%20%20spectrogram_frame%20%3D%20spectrogram_dataset%5B0%5D%0A%20%20%20%20if%20spectrogram_frame%20is%20None%3A%0A%20%20%20%20%20%20%20%20raise%20RuntimeError(%22The%20first%20recording%20could%20not%20be%20converted%20to%20a%20spectrogram.%22)%0A%0A%20%20%20%20spectrogram_frame%5B0%5D.plot(title%3D%22Spectrogram%20Sample%20for%20ML%20Input%22)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20dataset%2C%0A%20%20%20%20%20%20%20%20discovered_count%2C%0A%20%20%20%20%20%20%20%20processed_frame%2C%0A%20%20%20%20%20%20%20%20source_frame%2C%0A%20%20%20%20%20%20%20%20spectrogram_dataset%2C%0A%20%20%20%20%20%20%20%20spectrogram_frame%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(%0A%20%20%20%20dataset%2C%0A%20%20%20%20discovered_count%2C%0A%20%20%20%20mo%2C%0A%20%20%20%20processed_frame%2C%0A%20%20%20%20source_frame%2C%0A%20%20%20%20spectrogram_dataset%2C%0A%20%20%20%20spectrogram_frame%2C%0A%20%20%20%20t%2C%0A)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20t(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22preprocessing_result%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20discovered_count%3Ddiscovered_count%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20selected_count%3Dlen(dataset)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20source_sampling_rate%3Dsource_frame.sampling_rate%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20source_duration%3Df%22%7Bsource_frame.duration%3A.1f%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20processed_sampling_rate%3Dprocessed_frame.sampling_rate%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20processed_duration%3Df%22%7Bprocessed_frame.duration%3A.1f%7D%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20spectrogram_count%3Dlen(spectrogram_dataset)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20frequency_bins%3Dspectrogram_frame.n_freq_bins%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20time_frames%3Dspectrogram_frame.n_frames%2C%0A%20%20%20%20%20%20%20%20)%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22ml_spectrogram_processing%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20spectrogram_dataset%2C%20wd)%3A%0A%20%20%20%20def%20threshold_spectrogram(data%2C%20threshold)%3A%0A%20%20%20%20%20%20%20%20return%20np.where(np.abs(data)%20%3C%20threshold%2C%200%2C%20data)%0A%0A%20%20%20%20def%20process_ml(frame)%3A%0A%20%20%20%20%20%20%20%20_ml_values%20%3D%20threshold_spectrogram(frame.data%2C%20threshold%3D0.05)%0A%20%20%20%20%20%20%20%20return%20wd.SpectrogramFrame.from_numpy(%0A%20%20%20%20%20%20%20%20%20%20%20%20data%3D_ml_values%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20sampling_rate%3Dframe.sampling_rate%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20n_fft%3Dframe.n_fft%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20hop_length%3Dframe.hop_length%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20win_length%3Dframe.win_length%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20window%3Dframe.window%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20metadata%3Dframe.metadata%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20channel_metadata%3Dframe.channels%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20previous%3Dframe%2C%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20ml_results%20%3D%20spectrogram_dataset.apply(process_ml)%0A%20%20%20%20_ml_result%20%3D%20ml_results%5B0%5D%0A%20%20%20%20if%20_ml_result%20is%20None%20or%20_ml_result.previous%20is%20None%3A%0A%20%20%20%20%20%20%20%20raise%20RuntimeError(%22The%20first%20spectrogram%20could%20not%20be%20processed.%22)%0A%20%20%20%20_ml_result.previous.plot(vmin%3D-60%2C%20vmax%3D0%2C%20title%3D%22Original%20Spectrogram%22)%0A%20%20%20%20_ml_result.plot(vmin%3D-60%2C%20vmax%3D0%2C%20title%3D%22ML%20Spectrogram%22)%0A%20%20%20%20return%20(ml_results%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22ml_validation%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(ml_results)%3A%0A%20%20%20%20_ml_result%20%3D%20ml_results%5B0%5D%0A%20%20%20%20if%20_ml_result%20is%20None%20or%20_ml_result.previous%20is%20None%3A%0A%20%20%20%20%20%20%20%20raise%20RuntimeError(%22The%20first%20spectrogram%20could%20not%20be%20processed.%22)%0A%20%20%20%20_ml_result.previous.istft().describe()%0A%20%20%20%20_ml_result.istft().describe()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22cleanup%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(temp_dir)%3A%0A%20%20%20%20import%20shutil%0A%0A%20%20%20%20shutil.rmtree(temp_dir)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22quality_control%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20wd)%3A%0A%20%20%20%20np.random.seed(42)%0A%20%20%20%20normal_vibration%20%3D%20wd.from_numpy(%0A%20%20%20%20%20%20%20%20data%3Dnp.random.randn(1%2C%2016000)%20*%200.1%2C%0A%20%20%20%20%20%20%20%20sampling_rate%3D16000%2C%0A%20%20%20%20%20%20%20%20ch_labels%3D%5B%22Normal%20Vibration%22%5D%2C%0A%20%20%20%20)%0A%0A%20%20%20%20_vibration_time%20%3D%20np.arange(16000)%20%2F%2016000%0A%20%20%20%20abnormal_vibration%20%3D%20wd.from_numpy(%0A%20%20%20%20%20%20%20%20data%3Dnp.random.randn(1%2C%2016000)%20*%200.3%20%2B%20np.sin(2%20*%20np.pi%20*%202%20*%20_vibration_time)%2C%0A%20%20%20%20%20%20%20%20sampling_rate%3D16000%2C%0A%20%20%20%20%20%20%20%20ch_labels%3D%5B%22Abnormal%20Vibration%22%5D%2C%0A%20%20%20%20)%0A%0A%20%20%20%20normal_vibration.info()%0A%20%20%20%20abnormal_vibration.info()%0A%0A%20%20%20%20def%20extract_features(vibration_data%3A%20wd.ChannelFrame)%20-%3E%20tuple%5Bfloat%2C%20wd.ChannelFrame%5D%3A%0A%20%20%20%20%20%20%20%20preprocessed%20%3D%20vibration_data.band_pass_filter(20%2C%201000)%0A%20%20%20%20%20%20%20%20rms%20%3D%20preprocessed.rms%0A%20%20%20%20%20%20%20%20return%20(rms%5B0%5D%2C%20preprocessed)%0A%0A%20%20%20%20normal_features%2C%20normal_preprocessed%20%3D%20extract_features(normal_vibration)%0A%20%20%20%20abnormal_features%2C%20abnormal_preprocessed%20%3D%20extract_features(abnormal_vibration)%0A%0A%20%20%20%20threshold%20%3D%20(normal_features%20%2B%20abnormal_features)%20%2F%202%0A%20%20%20%20detected%20%3D%20abnormal_features%20%3E%20threshold%0A%0A%20%20%20%20ax%20%3D%20normal_preprocessed.rms_plot()%0A%20%20%20%20abnormal_preprocessed.rms_plot(ax%3Dax%2C%20title%3D%22RMS%20Comparison%22)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20abnormal_features%2C%0A%20%20%20%20%20%20%20%20abnormal_preprocessed%2C%0A%20%20%20%20%20%20%20%20detected%2C%0A%20%20%20%20%20%20%20%20normal_features%2C%0A%20%20%20%20%20%20%20%20normal_preprocessed%2C%0A%20%20%20%20%20%20%20%20threshold%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(abnormal_features%2C%20detected%2C%20mo%2C%20normal_features%2C%20t%2C%20threshold)%3A%0A%20%20%20%20values%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22abnormal%22%3A%20f%22%7Babnormal_features%3A.3f%7D%22%2C%0A%20%20%20%20%20%20%20%20%22normal%22%3A%20f%22%7Bnormal_features%3A.3f%7D%22%2C%0A%20%20%20%20%20%20%20%20%22threshold%22%3A%20f%22%7Bthreshold%3A.3f%7D%22%2C%0A%20%20%20%20%7D%0A%20%20%20%20if%20detected%3A%0A%20%20%20%20%20%20%20%20message%20%3D%20t(%22quality_detected%22%2C%20**values)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20message%20%3D%20t(%22quality_normal%22%2C%20**values)%0A%20%20%20%20mo.md(message)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(abnormal_preprocessed%2C%20normal_preprocessed)%3A%0A%20%20%20%20normal_preprocessed.describe()%0A%20%20%20%20abnormal_preprocessed.describe()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22first_code%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plt)%3A%0A%20%20%20%20plt.rcParams%5B%22figure.figsize%22%5D%20%3D%20(10%2C%206)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(wd)%3A%0A%20%20%20%20signal_2%20%3D%20wd.generate_sin(freqs%3D%5B1000%2C%204000%5D%2C%20duration%3D2.0%2C%20sampling_rate%3D16000)%0A%20%20%20%20signal_2.info()%0A%20%20%20%20return%20(signal_2%2C)%0A%0A%0A%40app.cell%0Adef%20_(signal_2)%3A%0A%20%20%20%20signal_2.describe()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22describe_result%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(signal_2)%3A%0A%20%20%20%20processed%20%3D%20signal_2.low_pass_filter(cutoff%3D2000).normalize()%0A%20%20%20%20return%20(processed%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20processed%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22chain_result%22%2C%20operations%3D%22%2C%20%22.join(op%5B%22operation%22%5D%20for%20op%20in%20processed.operation_history)))%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(plt%2C%20processed%2C%20signal_2)%3A%0A%20%20%20%20(_fig%2C%20(_ax1%2C%20_ax2))%20%3D%20plt.subplots(1%2C%202%2C%20figsize%3D(12%2C%204))%0A%20%20%20%20signal_2.fft().plot(ax%3D_ax1%2C%20title%3D%22Original%20Signal%20Spectrum%22)%0A%20%20%20%20processed.fft().plot(ax%3D_ax2%2C%20title%3D%22Filtered%20Signal%20Spectrum%22)%0A%20%20%20%20plt.tight_layout()%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22benefits%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22audience%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20t)%3A%0A%20%20%20%20mo.md(t(%22next_steps%22))%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(locale%2C%20mo%2C%20navigation_markdown)%3A%0A%20%20%20%20mo.md(navigation_markdown(%2200_why_wandas%22%2C%20locale))%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
1b613d63c57270a0e5df6783d85d8cd7