Can you help us debug and fix this code entirely?
    4 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
%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' ); 
25 
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); 
26 
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 
27 
#% 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,... 
28 
'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'); 
main issue we keep facing is
Error using load
Unable to find file or directory 'nearspeech'.
Error in OG (line 30)
load nearspeech
0 commentaires
Réponses (1)
  Walter Roberson
      
      
 le 18 Mai 2025
        You can get nearspeech.mat and farspeech.mat as part of the example
openExample('audio/AcousticEchoCancellationAecExample')
5 commentaires
  Walter Roberson
      
      
 le 18 Mai 2025
				I have no reason to doubt the correctness of the code from https://www.scribd.com/document/563550610/project-paper  
Voir également
Catégories
				En savoir plus sur Audio Processing Algorithm Design dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

