MATLAB Answers

Audio denoising using wavelet thresholding technique. What does the error mean and how to rectify?

1 view (last 30 days)
vartika Nanda
vartika Nanda on 20 Oct 2020
Answered: Abhishek Kumar on 8 Dec 2020
clc
close all
[file,path] = uigetfile('./Databases/*.wav', 'Select the speech files', 'MultiSelect', 'on');
[ipsignal, Fs] = audioread([path,file]);
ipsignal = ipsignal(1:length(ipsignal)/2);
amp = 100;
ipsignal = amp*ipsignal;
N = length(ipsignal);
sn = 10;
ipsignalN = awgn(ipsignal,sn);
sound(ipsignalN,Fs);
level = 3;
fprintf('\tchoose Wavelet:\n\t1: daubechies-13\n\t2: Daubechies40\n\t3: Symlet-13\n\t4: Symlet-21\n\t');
wname = input('Enter you choice: ');
if wname == 1
wt = 'db13';
elseif wname == 2
wt = 'db40';
elseif wname == 3
wt = 'sym13';
elseif wname == 4
wt = 'sym21';
end
[LoD,HiD,LoR,HiR] = wfilters(wt);
[C,L] = wavedec(ipsignalN,level,LoD,HiD);
cA3 = appcoef(C,L,wt,level);
[cD1,cD2,cD3] = detcoef(C,L,[1,2,3]);
A3 = wrcoef('a',C,L,LoR,HiR,level);
D1 = wrcoef('d',C,L,LoR,HiR,1);
D2 = wrcoef('D',C,L,LoR,HiR,2);
D3 = wrcoef('D',C,L,LoR,HiR,3);
%step 2 - Thresholding
fprintf('\n\tChoose Threshold Rule:\n\t1: Universal\n\t2: Minimax\n\t3: Level dependent threshold\n\t');
tr = input('Enter your choice: ');
if tr == 1
D = [D1 D2 D3];
th = zeros(1,length(D));
Dth = zeros(1,length(D));
fprintf('\n\t choose threshold type:\n\t1: Soft\n\t2: Hard\n\t');
sh = input('Enter you choice: ');
if sh == 1
sorh = 's';
else
sorh = 'h';
end
for g =1:length(D)
th(g) = sqrt(2*log(numel(D(g))));
Dth(g) = wthresh(D(g),sorh,th(g));
end
denoised = A3;
for i=1:length(Dth)
denoised = denoised+Dth(i);
end
customplot(ipsignal,ipsignalN,denoised);
sound(denoised,Fs);
elseif tr == 2
tptr = 'minimaxi';
thr_D1 = thselect(D1,tptr);
thr_D2 = thselect(D2,tptr);
thr_D3 = thselect(D3,tptr);
fprintf('\n\t choose threshold type:\n\t1: Soft\n\t2: Hard\n\t');
sh = input('Enter you choice: ');
if sh == 1
sorh = 's';
else sh == 2
sorh = 'h';
end
%Threshold coefficient of details
tD1 = wthresh(D1,sorh,thr_D1);
tD2 = wthresh(D2,sorh,thr_D2);
tD3 = wthresh(D3,sorh,thr_D3);
%step 3: Compute Inverse DWT
denoised = A3 + tD1 + tD2 + tD3;
customplot(ipsignal,ipsignalN,denoised)
sound(denoised,Fs);
else
D = [D1 D2 D3];
th = zeros(1,length(D));
Dth = zeros(1,length(D));
fprintf('\n\t choose threshold type:\n\t1: Soft\n\t2: Hard\n\t');
sh = input('Enter you choice: ');
if sh == 1
sorh = 's';
else
sorh = 'h';
end
for g =1:length(D)
th(g) = sqrt(2*log(numel(D(g)))/pow2(i));
Dth(g) = wthresh(D(g),sorh,th(g));
end
denoised = A3;
for i=1:length(Dth)
denoised = denoised+Dth(i);
end
customplot(ipsignal,ipsignalN,denoised);
sound(denoised,Fs);
end
function customplot(ipsignal,ipsignalN,denoised)
figure
subplot(3,1,1);
plot(ipsignal);
title('Original Speech Signal');
xlabel('samples');
ylabel('Amplitude');
subplot(3,1,2);
plot(ipsignalN);
title('Noisy Speech Signal');
xlabel('Samples');
ylabel('Amplitude');
subplot(3,1,3);
plot(denoised);ylim([-10 10]);
title('De-noised Speech Signal');
xlabel('Samples');
ylabel('Amplitude');
end
ERRORS
Index exceeds the number of array elements (0).
Error in matlab.ui.internal.dialog.FileChooser/updateFromDialog (line 215)
obj.PathName = filepaths{1};
Error in matlab.ui.internal.dialog.FileChooser/prepareDialog/localupdate (line 95)
updateFromDialog(obj,updateDataObject(obj));

Answers (1)

Abhishek Kumar
Abhishek Kumar on 8 Dec 2020
Hi Vartika, I tried execute you code with another input ".wav" on my machine and it worked just fine. The only reason you can be getting this error is the path of input file you are providing for your input ".wav" file. Please verify the input path you are providing in "uigetfile", do also mention which version of MATLAB you are using.

Community Treasure Hunt

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

Start Hunting!

Translated by