Clear Filters
Clear Filters

Automatic Computation of Interval-Dependent Thresholds on an imported .wav file.

1 view (last 30 days)
I have followed the matlab documentation on this and tried to adapt it to my needs but i get these errors that occur within the functions i am using:
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in wrepcoef (line 37)
varargout{1} = cat(dim,repcoefs{:});
Error in utthrset_cmd (line 24)
details = wrepcoef(coefs,longs);
This is my code:
clc;
[pete1,fs] = audioread("noisypete.wav");
peterch1 = pete1(:,1);
peterch2 = pete1(:,2);
wname = 'sym6';
level = 5;
[coefs,longs] = wavedec(peterch1,level,wname);
siz = size(coefs);
thrParams = utthrset_cmd(coefs,longs);
first = cumsum(longs)+1;
first = first(end-2:-1:1);
tmp = longs(end-1:-1:2);
last = first+tmp-1;
for k = 1:level
thr_par = thrParams{k};
if ~isempty(thr_par)
cfs = coefs(first(k):last(k));
nbCFS = longs(end-k);
NB_int = size(thr_par,1);
x = [thr_par(:,1) ; thr_par(NB_int,2)];
alf = (nbCFS-1)/(x(end)-x(1));
bet = 1 - alf*x(1);
x = round(alf*x+bet);
x(x<1) = 1;
x(x>nbCFS) = nbCFS;
thr = thr_par(:,3);
for j = 1:NB_int
if j==1
d_beg = 0;
else
d_beg = 1;
end
j_beg = x(j)+d_beg;
j_end = x(j+1);
j_ind = (j_beg:j_end);
cfs(j_ind) = wthresh(cfs(j_ind),sorh,thr(j));
end
coefs(first(k):last(k)) = cfs;
end
end
sigden = waverec(coefs,longs,wname);
figure
subplot(2,1,1)
plot(peterch1,'r')
axis tight
hold on
plot(sigden,'k')
title('Original and Denoised Signals')
subplot(2,1,2)
plot(sigden,'k')
axis tight
hold off
title('Denoised Signal')
from inspecting the issue in dimension within the wrepcoef function, it seems that maybe the bookkeeping vector, 'longs' is a double instead of a single as the 'dim' is set to 1 in the wrepcoef function. if so, could you recommend a solution to this? this is for a university project.
thank you

Answers (1)

Sai Pavan
Sai Pavan on 25 Jan 2024
Hello Zayne,
I understand that you want to resolve the error occuring with the use of 'utthrset_cmd' function.
As the error "Dimensions of arrays being concatenated are not consistent" suggests, the issue here is with the dimensions of the input data sent to the function. The issue is resolved by transposing the "coefs" array and sending it as an input to the 'utthrset_cmd' function along with 'longs' array.
Please refer to the modified code snippet shown below:
thrParams = utthrset_cmd(coefs',longs); % coefs array is transposed
Please refer to the below documentation to learn more about transpose operation: https://www.mathworks.com/help/matlab/ref/transpose.html
Hope it helps!

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!