How do I implement this code to the example called Active Noise Control Using a Filtered-X LMS FIR Adaptive Filter?
5 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
Jimmy Lapierre
2021-1-29
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 个评论
Jimmy Lapierre
2021-2-2
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/507755/image.jpeg)
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.
- 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.
- 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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!