This commit is contained in:
2026-05-17 13:29:48 +02:00
parent edaab00dd2
commit 38aa63d2fc
12 changed files with 100 additions and 103 deletions
+10 -12
View File
@@ -4,7 +4,7 @@ The implementation is conducted in Python, which provides a flexible environment
\subsection{Adaptive noise reduction algorithm implementation}
The high-level implementation of the \ac{ANR} algorithm follows the theoretical framework outlined in Subchapter 2.5, specifically Equation \ref{equation_lms}. The algorithm is designed to adaptively filter out noise from a desired signal using a reference noise signal. The implementation of the \ac{ANR} function includes the following key steps:
\begin{itemize}
\item Initialization: Define arrays to store the reference noise samples (Sample Line), the filter coefficients (Filter Line), the processed output samples (output), and the updated filter coefficients (coefficient\_matrix) over time. Then a sequence of input samples is processed iteratively.
\item Initialization: Define arrays to store the reference noise samples (Sample Line), the filter coefficients (Filter Line) and the processed output samples (Output) over time. Then a sequence of input samples is processed iteratively.
\item Filtering Process: The reference noise samples fill up the Sample Line, the filter coefficients in the Filter Line (initially set to zero) are then multiplied with the corresponding reference noise samples before being added up to an accumulator.
\item Error Calculation: The accumulator is then subtracted from the current input sample to produce the output sample, which represents the error signal.
\item Coefficient Update: Every filter coefficient is then updated, by adding a term, which consists out of the error signal multiplied by the corresponding reference noise sample, scaled by the step size. The adaption step parameter allows controlling how often the coefficients are updated.
@@ -14,36 +14,34 @@ The flow diagram in Figure \ref{fig:fig_anr_logic} illustrates the logical flow
\begin{figure}[H]
\centering
\includegraphics[width=0.9\linewidth]{Bilder/fig_anr_logic.jpg}
\caption{Flow diagram of the code implementation of the \ac{ANR} algorithm.}
\caption{Flow diagram of the code implementation of the \ac{ANR} algorithm}
\label{fig:fig_anr_logic}
\end{figure}
\begin{listing}[H]
\centering
\begin{lstlisting}[style=pythonstyle]
def anr_function(input, ref_noise, coefficients, mu, adaption_step=1):
sample_count = len(input)
def anr_function(Input, ref_noise, coefficients, mu, adaption_step=1):
sample_count = len(Input)
filter_line = np.zeros(coefficients)
sample_line = np.zeros(coefficients)
output = np.zeros(sample_count)
coefficient_matrix = np.zeros((sample_count, coefficients))
Output = np.zeros(sample_count)
for n in range(sample_count):
sample_line = np.roll(sample_line, 1)
sample_line[0] = ref_noise[n]
accumulator = np.dot(filter_line, sample_line)
error = input[n] - accumulator
output[n] = error
error = Input[n] - accumulator
Output[n] = error
filter_line += mu * error * sample_line
coefficient_matrix[n, :] = filter_line
return output, coefficient_matrix
return Output
\end{lstlisting}
\caption{High-level implementation of the \ac{ANR} algorithm in Python}
\label{lst:lst_anr_code}
\end{listing}
\noindent The algorithm implementation shall now be put under test by different use cases to demonstrate the functionality and performance under different scenarios, varying from simple to complex ones. Every use case includes graphical representations of the desired signal, the corrupted signal, the reference noise signal, the filter output, the error signal and the evolution of selected filter coefficients over time. In contrary to a realistic setup, the desired signal is available, allowing to evaluate the performance of the algorithm based on the \ac{SNR}-Gain in dB and also visually by the amplitude of the error signal (difference between the desired signal and the filter output). The error signal and the \ac{SNR}-Gain are calculated as follows:
\noindent The algorithm implementation shall now be put under test by different use cases to demonstrate the functionality and performance under different scenarios, varying from simple to complex. Every use case includes graphical representations of the desired signal, the corrupted signal, the reference noise signal, the filter output, the error signal and the evolution of selected filter coefficients over time. In contrary to a realistic setup, the desired signal is available, allowing to evaluate the performance of the algorithm based on the \ac{SNR}-Gain in dB and also visually by the amplitude of the error signal (difference between the desired signal and the filter output). The error signal and the \ac{SNR}-Gain are calculated as follows:
\begin{gather}
\label{equation_snr_gain_error}
\text{P}_{\text{Error signal}} = \text{P}_{\text{Desired signal}} - \text{P}_{\text{Filter-output}} \\
@@ -53,7 +51,7 @@ def anr_function(input, ref_noise, coefficients, mu, adaption_step=1):
with $\text{P}_{\text{Desired signal}}$ being the power of the desired signal, $\text{P}_{\text{Noise signal}}$ being the power of the noise signal and $\text{P}_{\text{Error signal}}$ being the power of the error signal, which is the difference between the desired signal and the filter output. A positive \ac{SNR}-Gain indicates an improvement in signal quality, while a negative \ac{SNR}-Gain indicates a degradation in signal quality after applying the \ac{ANR} algorithm.
\subsection{Simple ANR use cases}
To evaluate the general functionality and performance of the \ac{ANR} algorithm from Listing \ref{lst:lst_anr_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 \ac{ANR} algorithm.\\ \\
In all three scenarios, a chirp signal with a frequency range from 100-1000 Hz is used as the desired signal, which is then corrupted with a sine wave (Use case 1 and 2) or a Gaussian white noise (Use case 3) as noise signal respectively. In this simple setup, the corruption noise signal is also available as the reference noise signal. Every approach is conducted with 16 filter coefficients and a step size of 0.01. The four graphs in the respective first plot show the desired signal, the corrupted signal, the reference 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 exemplary filter coefficients over time.\\ \\
In all three scenarios, a chirp signal with a frequency range from 100-1000 Hz is used as the desired signal, which is then corrupted with a sine wave (use case 1 and 2) or a Gaussian white noise (use case 3) as noise signal respectively. In this simple setup, the corruption noise signal is also available as the reference noise signal. Every approach is conducted with 16 filter coefficients and a step size of 0.01. The four graphs in the respective first plot show the desired signal, the corrupted signal, the reference 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 exemplary filter coefficients over time.\\ \\
\noindent This artificial setup could be solved analytically, as the signals do not pass separate, different transfer functions, meaning, that the reference noise signal is the same as the corruption noise signal. Though, this simple setup would not require an adaptive filter approach, it nevertheless allows to clearly evaluate the performance of the \ac{ANR} algorithm in different scenarios. Also, due to the fact that the desired signal is known, it is possible to evaluate the performance of the algorithm in a simple way.
\subsubsection{Simple use case 1: Sine noise at 2000 Hz}
In the first use case, a sine wave with a frequency of 2000 Hz, which lies outside the frequency spectrum of the chirp, is used as noise signal to corrupt the desired signal. The shape of the initial desired signal is still clearly recognizable, even if its shape is affected in the higher frequency area. The filter output in Figure \ref{fig:fig_plot_1_sine_1.png} shows a satisfying performance of the \ac{ANR} algorithm, as the noise is almost completely removed from the corrupted signal after the filter coefficients have adapted.