1-d wavelet coefficients as a resnet18 input the corresponding as the output in matlab

To transform a 1-D signal using wavelet transform and use it as input to ResNet18 in Matlab, first you need to perform wavelet decomposition on your signal. The following code can be used to perform wavelet decomposition:

main.m
% Wavelet decomposition
[c,l] = wavedec(signal, n, wavelet_name); 
67 chars
3 lines

Here, signal is the input 1-D signal, n is the level of decomposition and wavelet_name is the name of the wavelet.

Once you have computed the wavelet coefficients, you can reshape the output in such a way that it can be used as input to ResNet18. The input to ResNet18 should have three channels, so you can stack the wavelet coefficients three times to create a 3-channel input. To do so, you can reshape the wavelet coefficients using the following code:

main.m
% Reshape wavelet coefficients for ResNet18
input = zeros(l(end), 3, size(c, 2));
for i = 1:size(c, 2)
    temp = reshape(c(:,i), 1, [], l(end));
    input(:,:,i) = repmat(temp, 3, 1)';
end
190 chars
7 lines

Here, l(end) gives the length of the approximation coefficients at the highest level of decomposition. The loop iterates over all the wavelet coefficients and reshapes them into a 3-channel input. The resulting input is a 3D matrix of size (length of approximation coefficients at highest level of decomposition) x 3 x (number of wavelet coefficients).

Finally, you can use the input as input to ResNet18 for inference. The output of ResNet18 can be compared with the original signal to see how well the network has reconstructed it.

gistlibby LogSnag