Files
Masterarbeit/chapter_03.tex
Patrick Hangl d78c2c8245 3.1,3.2,3.3
2025-11-27 18:51:35 +01:00

97 lines
9.3 KiB
TeX

\section{High level simulations}
The main purpose of the high-level simulations is to verify and demonstrate the theoretical approach of the previous chapters and to evaluate the performance of the proposed algorithms under various conditions. The following simulations include different scenarios such as, different types of noise signals and different cosniderations of transfer functions. The goal is to verify different approaches before taking the step to the implementation of said algorithms on the low-power DSP.\\ \\
The implementation is conducted in Python, which provides a flexible environment for numerical computations and data visualization. The simulation is graphically represented using the Python library Matplotlib, allowing for clear visualization of the results.
\subsection{LMS algorithm implementation}
The high-level implementation of the LMS algorithm follows the theoretical framework outlined in Subchapter 2.5, specificially Equation \ref{equation_lms}. The algorithm is designed to adaptively filter out noise from a desired signal using a reference noise input. The implementation of the LMS-function includes the following key steps:
\begin{itemize}
\item Initialization: Define vectors to store the filter coefficients, the output samples, and the updated filter coefficients over time.
\item Filtering Process: After initially enough input samples (= number of filter coeffcients) passed the filter, for each sample in the input sample, the filter coefficients are multiplied with the corresponding reference noise samples before added to an accumulator.
\item Error Calculation: The accumulator is then substracted from the current input sample to produce the output sample, which represents the error signal.
\item Coefficient Update: The filter coefficients are updated by the corrector, which consists out of the error signal, scaled by the step size. The adaption step parameter allows to control how often the coefficients are updated.
\item Iteration: Repeat the process for all samples in the input signal.
\end{itemize}
The flow diagram in Figure \ref{fig:fig_lms_logic} illustrates the logical flow of the LMS algorithm, while the code snippet in Figure \ref{fig:fig_lms_code} provides the concrete code implementation of the LMS-function.
\begin{figure}[H]
\centering
\includegraphics[width=0.9\linewidth]{Bilder/fig_lms_logic.jpg}
\caption{Flow diagram of the code implementation of the LMS algrotihm.}
\label{fig:fig_lms_logic}
\end{figure}
\begin{figure}[H]
\centering
\begin{lstlisting}[language=Python]
def lms_filter(input, ref_noise, coefficients, mu, adaption_step = 1):
coefficient_matrix = np.zeros((len(input), coefficients),
dtype=np.float32)
output = np.zeros(input.shape[0], dtype=np.float32)
filter = np.zeros(coefficients, dtype=np.float32)
for j in range(0, len(input) - len(filter)):
accumulator=0
for i in range(coefficients):
noise=ref_noise[j+i]
accumulator+=filter[i] * noise
output[j] = input[j] - accumulator
corrector = mu * output[j]
if (j % adaption_step) == 0:
for k in range(coefficients):
filter[k] += corrector*ref_noise[j+k]
coefficient_matrix[j, :] = filter[:]
return output, coefficient_matrix
\end{lstlisting}
\label{fig:fig_lms_code}
\caption{Code implementation of the LMS algorithm.}
\end{figure}
\subsection{Simple LMS usecases}
To evaltuate the general functionality and performance of the LMS algorithm from Figure \ref{fig:fig_lms_code} a set of three simple, artificial scenarios are introduced. These examples shall serve as a showcase to demonstrate the general functionality, the possibilities and the limitations of the LMS algorithm. In contrary to a more complex and realistic setup, which will be reviewed afterwards, the clean signals are available, which is in a realistic application not the case.\\ \\
In all three scenarios, a chirp signal with a frequency range from 100-1000 Hz is used as the desired clean signal, which is then corrupted with a sine wave (Usecase 1 and 2) or a gaussian white noise (Usecase 3) as noise signal respectively. Every approach is conducted with 16 filter coefficients and a stepsize of 0.01. The three graphs in the repsective first plot show the corrputed target signal, the noise signal and the filter output. The two graphs in the respective second plot show the performance of the filter in form of the resulting error signal and the evolution of three filter coefficients over time.\\ \\
This artificial setup could be solved analitically, as the signals do not pass seperate, different transfer functions and would not require a LSM approach, but it allows to clearly evaluate the performance of the LMS algorithm, as the clean signal is known and can be compared to the output signal of the LMS filter. \\ \\
\subsubsection{Usecase 1: Sine noise with high frequency}
In the first usecase, a sine wave with a high frequency of 2000 Hz, which lies outside the frequency spectrum of the chirp, is used as noise signal to corrupt the target signal. The filter output in Figure \ref{fig:fig_plot_1_sine_1.png} shows a statisfying performance of the LMS algorithm, as the noise is almost completely removed from the target signal.
\begin{figure}[H]
\centering
\includegraphics[width=1.0\linewidth]{Bilder/fig_plot_1_sine_1.png}
\caption{Corrputed target signal, noise signal and filter output of Usecase 1}
\label{fig:fig_plot_1_sine_1.png}
\end{figure}
\noindent The error signal in Figure \ref{fig:fig_plot_2_sine_1.png} confirms this observation, as the signal converges basically to zero after 200 ms The evolution of the filter coefficients also indicates a quick convergence, meaning that the algorithm has adapted effectively to minimize the error over time.
\begin{figure}[H]
\centering
\includegraphics[width=1.0\linewidth]{Bilder/fig_plot_2_sine_1.png}
\caption{Error signal and filter coefficient evolution of Usecase 1}
\label{fig:fig_plot_2_sine_1.png}
\end{figure}
\subsubsection{Usecase 2: Sine noise with low frequency}
The second usecase resembles the first one, but instead of a high-frequency sine wave, a low-frequency sine wave with a frequency of 500 Hz is used as noise signal. This means, that the noise signal now overlaps with the frequency spectrum of the chirp signal, making the noise cancellation task more challenging, as an osciillation beacon in the area of 500 Hz appears. The filter output in Figure \ref{fig:fig_plot_1_sine_2.png} indicates that the LMS algorithm is still able to significantly reduce the noise from the target signal,
\begin{figure}[H]
\centering
\includegraphics[width=1.0\linewidth]{Bilder/fig_plot_1_sine_2.png}
\caption{Corrputed target signal, noise signal and filter output of Usecase 2}
\label{fig:fig_plot_1_sine_2.png}
\end{figure}
\noindent Figure \ref{fig:fig_plot_2_sine_2.png} shows a significant increase of the amplitude of the error signal compared to Usecase 1, especially around the 500 Hz frequency of the noise signal. Also the adaption of the coefficients shows far more variance compared to Usecase 1, with a complete rearrangement in the area of 500 Hz. This indicates that the LMS algorithm is struggling to adapt effectively in a scenario, where the noise signal overlaps with the target signal.
\begin{figure}[H]
\centering
\includegraphics[width=1.0\linewidth]{Bilder/fig_plot_2_sine_2.png}
\caption{Error signal and filter coefficient evolution of Usecase 2}
\label{fig:fig_plot_2_sine_2.png}
\end{figure}
\subsubsection{Usecase 3: Gaussian white noise}
The last on of our three simplified usecases involves the use of a gaussian white noise signal as the noise signal to corrupt the target signal. This scenario represents a more realistic and complex situation, as white noise contains a broad spectrum of frequencies, making it more challenging for the LMS algorithm to effectively generate a clean output. The filter output in Figure \ref{fig:fig_plot_1_noise.png} demonstrates that the LMS algorithm is capable of significantly reducing the noise from the target signal, although the amplitude of the filter output varies, indicating difficulties adapting due to the broad frequency spectrum of the noise.
\begin{figure}[H]
\centering
\includegraphics[width=1.0\linewidth]{Bilder/fig_plot_1_noise.png}
\caption{Corrputed target signal, noise signal and filter output of Usecase 3}
\label{fig:fig_plot_1_noise.png}
\end{figure}
The error signal in Figure \ref{fig:fig_plot_2_noise.png} shows a noticeable variance compared to the previous usecases, especially at the beginning of the signal, where low frequencies dominate. The evolution of the filter coefficients show an interesting pattern, as only the coefficinet in the beginning adapts significantly, while the others remain relatively stable around zero. This suggests that the LMS algorithm is primarily focusing on adapting to the low-frequency components of the white noise, which are more dominant in the target signal.
\begin{figure}[H]
\centering
\includegraphics[width=1.0\linewidth]{Bilder/fig_plot_2_noise.png}
\caption{Error signal and filter coefficient evolution of Usecase 3}
\label{fig:fig_plot_2_noise.png}
\end{figure}
\subsection{Intermediate LMS usecases}
\subsection{Realisitic LMS usecases}