In: Computer Science
function
X=extractDWT(x_train,startS,endS,wStep,wRange)
% x_train = input signal
% startS = from second
% endS = end second
% wStep = overlapping
% wRange = window size
FS=128;
N=size(x_train,3);
sz=floor((endS-(startS+wRange))/wStep)+1;
X=zeros(sz*140,2);
cn=0;
for i=1:N
for sig=startS:wStep:endS-wRange
sW=sig*FS+1;
eW=(sig+wRange)*FS;
C3Sig=x_train(sW:eW,1,i);
C4Sig=x_train(sW:eW,3,i);
waveletFunction =
'db4';
waveletLevel=3;
[wCoe,L] =
wavedec(C3Sig,waveletLevel,waveletFunction);
C3D3 =
detcoef(wCoe,L,3); % Mu
[wCoe,L] =
wavedec(C4Sig,waveletLevel,waveletFunction);
C4D3 =
detcoef(wCoe,L,3); % Mu
cn=cn+1;
% Mean of the absolute
values
X(cn,1)=sum(C3D3.^2)/numel(C3D3);
X(cn,2)=sum(C4D3.^2)/numel(C4D3);
end
end
end
Need code explanation for above code?
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
Below is your code with full comments at each line for explaination
function X=extractDWT(x_train,startS,endS,wStep,wRange)%A function
with name extractDWT and several inputs
% x_train = input signal
% startS = from second
% endS = end second
% wStep = overlapping
% wRange = window size
FS=128;%define and initialize Fs as 128
N=size(x_train,3);%number of elements in 3rd dimension of input
signal x_train matrix
sz=floor((endS-(startS+wRange))/wStep)+1;%define and initialize sz
as the greatest integer less than the
((endS-(startS+wRange))/wStep)+1
X=zeros(sz*140,2);%define X as the zeros matrix with sz*140 rows
and 2 columns
cn=0;%initialize cn as 0
for i=1:N% a loop to go from 1 to N
for sig=startS:wStep:endS-wRange% a loop with sig values from
startS to endS-wRange in steps of wStep
sW=sig*FS+1;%define sW as sig*Fs+1
eW=(sig+wRange)*FS;%define eW as (sig+wRange)*FS
C3Sig=x_train(sW:eW,1,i);%define C3Sig as the matrix with elements
of x_train matrix from sW to eW rows, 1st column and ith 3
dimensional element
C4Sig=x_train(sW:eW,3,i);%define C4Sig as the matrix with elements
of x_train matrix from sW to eW rows, 3rd column and ith 3
dimensional element
waveletFunction = 'db4';%define waveletFunction as the char array
with characters db4
waveletLevel=3;%define waveletLevel as 3
[wCoe,L] = wavedec(C3Sig,waveletLevel,waveletFunction);%Find the
1-D wavelet decomposition wCoe and L
C3D3 = detcoef(wCoe,L,3); % Mu, finds the wavelet analysis
[wCoe,L] = wavedec(C4Sig,waveletLevel,waveletFunction);%Find the
1-D wavelet decomposition wCoe and L
C4D3 = detcoef(wCoe,L,3); % Mu, finds the wavelet analysis
cn=cn+1;%increment cn by 1
% Mean of the absolute values
X(cn,1)=sum(C3D3.^2)/numel(C3D3);%assign the cn'th row and first
column of X to a value as sum of squares of elements of C3D3
divided by length of C3D3
X(cn,2)=sum(C4D3.^2)/numel(C4D3);%assign the cn'th row and second
column of X to a value as sum of squares of elements of C4D3
divided by length of C4D3
end
end
end
Kindly revert for any queries
Thanks.