\documentclass[10pt, twocolumn]{article}
\usepackage{hyperref}

\begin{document}
\noindent \textbf{Physics 567}\\
\noindent \textbf{Homework 3}\\
\noindent Due Monday, March 4, 2024

\vspace{0.5in}
In this exercise you will perform wavelet filtering to suppress noise, similar to what was demonstrated in class with the LIGO data. You are given a sample of digital music, \texttt{Lacumparsita-noisy.wav}, sampled at 44.1\,kHz.\footnote{Gerardo Matos Rodríguez (Public domain).} Listen to it, and you will hear the noise problem. Fortunately, we have obtained an example of noise from the recording apparatus, \texttt{noise-sample.wav}, using identical conditions but without the musicians. Of course, the noise is random, so there is no straightforward way to subtract it. 

\noindent{\textbf{Procedure.}} 
Obtain Torrence \& Compo's wavelet software. Verify that you can read, wavelet transform, and accurately reconstruct the data, and save it as a WAVE audio file, \texttt{reconstructed.wav}. Listen to the original and reconstructed WAVE files carefully, to reassure yourself that there is no difference. If they don't match, check whether you allowed a wide enough range of periods to cover the range of human hearing, with dense enough sampling in \texttt{log(period)} to allow accurate reconstruction.

Use the noise sample to calculate an array of power thresholds for significance at each wavelet scale. You could do this by using Torrence \& Compo's routine \texttt{wave\_signif}. It can also be done by finding the average power of the noise for each period, and then setting a threshold at some multiple of this value.

Next, obtain the wavelet transform (I'll call it \texttt{data\_w}) and the wavelet power spectrum (\texttt{data\_wps}) of the data. Use the thresholds you established in the last step to filter the wavelet transform. This entails something like \texttt{mask = (data\_wps < threshold)} and then \texttt{data\_w .*= mask}. Then reconstruct the music from the filtered wavelet transform and save as \texttt{filtered.wav}. Play with the significance threshold a bit to obtain the best sounding result you can. This is not really about statistical significance; it is art, not science. Also save the difference between the filtered data and the original data in \texttt{residuals.wav}.

\emph{Turn in your code(s) and WAVE files electronically to the grader:} 
\begin{itemize}
    \item \texttt{reconstructed.wav}
    \item \texttt{filtered.wav}
    \item \texttt{residuals.wav}
    \item \texttt{filtered.wav}  
\end{itemize}
\emph{If you try the optional part (below), please let me know how it goes. I'd like to listen to your results!}

\vspace{12pt}
\noindent \textbf{Optional.} The wavelet filtered music will exhibit a sort of fluttering sound. This is called ``chatter''. It is the result of sudden transitions in state between sound off and sound on in any of the various wavelet periods. 
If you would like an extra challenge, it is possible to eliminate this problem. My approach was to filter \texttt{mask} along the time axis only, as follows:
\begin{enumerate}
    \item Median filter to remove short positive and negative glitches. This can be time consuming.
    \item Dilate by boxcar smoothing and then setting nonzero values to 1.
    \item Make the filter attack and let-off gradual by again smoothing with a boxcar.
\end{enumerate}
Median smoothing is far slower than all the other operations. My finished code takes about 15 minutes to run.


\end{document}