- https://www.mathworks.com/help/releases/R2023a/matlab/ref/audiorecorder.html
- https://www.mathworks.com/help/releases/R2023a/matlab/ref/audiodevinfo.html
Help us debug the code we attached below. its an Adaptive filter comparing the LMS and NLMS algorithm. but we are not trained in MATLAB and lack expertise.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
%on line sound importing or recourding
recObj = audiorecorder;
recordblocking(recObj, 15);
play(recObj);
y = getaudiodata(recObj);
plot(y);
play(recObj);
y = getaudiodata(recObj);
plot(y);
%code of AEC
M=4001;
fs=8000;
[B,A]=cheby2(4,20,[0.1, 0.7]);
Hd=dfilt.df2t([zeros(1,6) B]);
hFVT=fvtool(Hd);
set(hFVT, 'color' ,[1 1 1])
v=340;
H = filter(Hd,log(0.99*rand(1,M)+0.01).* ...
sign (randn(1,M)).*exp(-0.002*(1:M)));
H = H/norm(H)*4; % Room Impulse Response
plot(0:1/fs:0.5,H);
xlabel('Time [sec]' );
ylabel('Amplitude' );
title( 'Room Impulse Response' );
set(gcf, 'color' , [1 1 1])
figure(1)
hold on
load nearspeech
n = 1: length (v);
t=n/fs;
plot(t,v);
axis([0 33.5 -1 1]);
xlabel('Time [sec]' );
ylabel('Amplitude' );
title('Near-end speech signal' );
set(gcf, 'color' , [1 1 1])
figure(2)
hold on
load farspeech
x =x( 1: length (x));
dhat = filter(H,1,x);
plot(t,dhat);
axis([0 33.5 -1 1]);xlabel('Time [sec]' );
ylabel('Amplitude' );
title('Far-End speech Signal' );
set(gcf, 'color' , [1 1 1])
figure(3)
hold on
d=dhat + v+0.001*randn(length(v),1);
plot(t,d);
axis([0 33.5 -1 1]);
xlabel('Time [sec]' );
ylabel('Amplitude' );
title('Microphon Signal' );
set(gcf, 'color' , [1 1 1])
figure(4)
hold on
mu=0.025;
W0 = zeros(1,2048);
del = 0.01;
lam = 0.98;
x = x(1:length(W0)*floor(length(x)/length(W0)));
d = d(1:length(W0)*floor(length(d)/length(W0)));
% Construct the Frequency-Domain Adaptive Filter
fdafilt = dsp.FrequencyDomainAdaptiveFilter('Length',32,'StepSize',mu);
[y,e] = fdafilt(x,d);
n = 1:length(e);
t = n/fs;
pos = get(gcf,'Position');
set(gcf,'Position',[pos(1), pos(2)-100,pos(3),(pos(4)+111)])
subplot(3,1,1);
plot(t,v(n),'g');
([0 33.5 -1 1]);
xlabel('Time [sec]');
ylabel('Amplitude');
title('Near-End Speech Signal of MR.ABERA');
subplot(3,1,2);
plot(t,d(n),'b');
axis([0 33.5 -1 1]);
ylabel('Amplitude');
title('Microphone Signal Mr. Amex + Mr.Abera');
subplot(3,1,3);
plot(t,v(n),'r');
axis([0 33.5 -1 1]);
ylabel('Amplitude');axis
title('Output of Acoustic Echo Canceller');
set(gcf, 'color' , [1 1 1])
%Normalized LMS method
FrameSize = 102; NIter = 14;
lmsfilt2 = dsp.LMSFilter('Length',11,'Method','Normalized LMS', ...
'StepSize',0.005);
firfilt2 = dsp.FIRFilter('Numerator', fir1(10,[.05, .075]));
sinewave = dsp.SineWave('Frequency',0.001, ...
'SampleRate',1,'SamplesPerFrame',FrameSize);
TS = dsp.TimeScope('TimeSpan',FrameSize*NIter,'TimeUnits','Seconds',...
'YLimits',[-3 3],'BufferLength',2*FrameSize*NIter, ...
'ShowLegend',true,'ChannelNames', ...
{'echo signal', 'Filtered signal'});
%%
% Pass the echo input signal into the LMS filter and view the filtered
% output in the time scope.
for k = 1:NIter
x = randn(FrameSize,1);
% Input signal
d = firfilt2(x) + sinewave(); % echo + Signal
[y,e,w] = lmsfilt2(x,d);
TS([d,e]);
% echo = channel 1; Filtered = channel 2
end
% convergence performance of regular NLMS
x = 0.1*randn(500,1);
[b,err,res] = fircband(12,[0 0.4 0.5 1], [1 1 0 0], [1 0.2],...
{'w' 'c'});
d = filter(b,1,x);
lms_normalized = dsp.LMSFilter(13,'StepSize',mu,...
'Method','Normalized LMS','WeightsOutputPort',true);
[~,e1,~] = lms_normalized(x,d);
plot([e1]);
title('NLMS Conversion Performance');
legend('NLMS Derived Filter Weights');
% convergence performance of regular LMS
x = 0.1*randn(500,1);
[b,err,res] = fircband(12,[0 0.4 0.5 1], [1 1 0 0], [1 0.2],...
{'w' 'c'});
d = filter(b,1,x);
lms_normalized = dsp.LMSFilter(13,'StepSize',mu,...
'Method','LMS','WeightsOutputPort',true);
[~,e2,~] = lms_normalized(x,d);
plot([e2]);
title('LMS Conversion Performance');
legend('LMS Derived Filter Weights');
% comparing the LMS and NLMS convergence performance
x = 0.1*randn(500,1);
[b,err,res] = fircband(12,[0 0.4 0.5 1], [1 1 0 0], [1 0.2],...
{'w' 'c'});
d = filter(b,1,x);
lms = dsp.LMSFilter(13,'StepSize',mu,'Method',...
'Normalized LMS','WeightsOutputPort',true);
lms_normalized = dsp.LMSFilter(13,'StepSize',mu,...
'Method','Normalized LMS','WeightsOutputPort',true);
lms_nonnormalized = dsp.LMSFilter(13,'StepSize',mu,...
'Method','LMS','WeightsOutputPort',true);
[~,e1,~] = lms_normalized(x,d);
[~,e2,~] = lms_nonnormalized(x,d);
plot([e1,e2]);
title('Comparing the LMS and NLMS Conversion Performance');
legend('NLMS Derived Filter Weights', ...
'LMS Derived Filter Weights','Location', 'NorthEast');
Help us debug the above code. its an adaptive filter comparing the performance of NLMS and LMS after taking in near-end, far-end signal as an input. We are not trained in MATLAB, and we risk failing class unless we get it up and running. please lend us a hand.
0 comentarios
Respuestas (1)
Adarsh
el 4 de Jun. de 2025
The error “No audio input device found on this system.” Indicates that MATLAB’s audiorecorder is unable to detect any auto input device for example, microphone present in the system.
You can resolve this error by verifying whether the microphone is connected and enabled in the system.
Following commands can be used to troubleshoot the issue and get the info about the available audio input-output devices:
info = audiodevinfo;
save audioDevice.mat
As an alternative you can use the pre-recorded “.wav” files instead of using live recording to compare the performance and prevent this error related to audio input-output devices as shown in the example below:
[y, fs] = audioread('audiofile.wav');
For more information, refer to the following documentation links:
I hope this helps.
0 comentarios
Ver también
Categorías
Más información sobre Adaptive Filters en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!