MATLAB Answers

How do I implement this code to the example called Active Noise Control Using a Filtered-X LMS FIR Adaptive Filter?

11 views (last 30 days)
Sean Roh
Sean Roh on 28 Jan 2021
Commented: Jimmy Lapierre on 2 Feb 2021
close all; clear all;
% get device information
dev = audiodevinfo;
% create recorder object
Sound = audiorecorder(44100, 16, 1);
% start recording
disp('start speaking');
%record(rec, 5); % will record for 5sec. for this command pause needs to be added
recordblocking(Sound, 5);
% stop recording
disp('Stop recording');
% Play recorded sound
play(Sound);
% get audio data
y = getaudiodata(Sound);
% plot the sound
plot(y);
%Save the sound as a .wav
audiowrite('Noise.m4a', y, 44100);
This is the link to the example.

Answers (1)

Jimmy Lapierre
Jimmy Lapierre on 29 Jan 2021
Hi Sean, I'll suggest that you also have a look at the Real-Time Example (linked here). The beginning of that example gives details on how this algorithm should work and it also has a simulink model (no need for the real-time system at that point). To better answer your question, I'd like to have more details on what you'd like to acheive.
  2 Comments
Jimmy Lapierre
Jimmy Lapierre on 2 Feb 2021
There are a few things to understand before attempting to realize this in real-time, just so your expectations are realistic. In addition to the other example I pointed out, I also recommend this video we made.
But I'll try to summarize. It might be helpful to use an illustration from that other example I refered to:
In this system, you have a noise source that is measured with a reference microphone. The system must produce a "cancellation" sound from the ANC loudspeaker. The goal is to have silence at the error microphone. To do so, you must account for the filtering effects of both paths (primary and secondary). In other words, not only you must predict how the sound will propagate from the reference mic to the error mic, but you must also take into account that what you play on the ANC loudspeaker will be modified before getting to the error mic as well. For measuring the secondary path, you'd still use white noise. It's the noise source here that you want to replace.
Then, to realize this in realtime, there are two possibilities.
  1. If the noise source is tonal and stationary (i.e. not your voice, but let's say some constant humming), then you timing doesn't matter as much. You'll end up cancelling a later noise cycle, but that's fine because the noise is repetitive.
  2. If the noise is non-stationary, you have very limited time (latency). From the time the sound wave enters the reference microphone to the time the ANC loudspeaker must counteract it, that's all you have. Here, that's approximately the distance between the reference mic and the "i" of the word Primary. That's why we used a Speedgoat in that example, because it allows us to have a latency of only a couple samples.
I hope this helps understand the ANC problem and how you can simulate this depending on the equipement you have. If you have a "normal" sound card, you can try option (1), but option (2) might be impossible because of the latency.

Sign in to comment.

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!