Hi Sean,
I understand that you are unsure about the variable 'q' and what it does. Moreover, you want to listen to the Anti-noise signal.
'q' is not related to the anti-noise signal or the active noise cancellation (ANC) process directly. Instead, it is part of the process to visualize the convergence of the error signal over time for different values of the step size 'mu'. The variable 'q' ends up holding the upper envelope of the last calculated mean error signal 'emean' processed in your loop for different 'mu' values.
To listen to the Anti-Noise signal, you would need to explicitly store the output of your adaptive filter (anti-noise signal) in a separate variable during your loop.
Please follow the steps below to modify the loop to include this:
Before the loop, initialize an array to store the anti-noise signal:
antiNoise = zeros(N,1); % Initialize the anti-noise signal storage
Inside your LMS loop, update this 'antiNoise' array with the current output of the adaptive filter:
for n=M:N
xvec=x(n:-1:n-M+1); %input has to be in reverse order
% adaptively update mu
mu(n) = muOG;
e(n)=d(n)-Wz'*xvec; %update error
antiNoise(n) = Wz'*xvec; % Store the current output of the adaptive filter
Wz=Wz+mu(n)*xvec*(e(n)); %update filter coefficient
end
After the loop, you can then play back the 'antiNoise' signal to listen to it:
soundsc(antiNoise, fs);