nmr sequences contain noise wavelet coefficient as a cnn input and the corresponding clean nmr sequences wavelet coefficient as the output in matlab in matlab in matlab

Here's an example code to use the wavelet transform and CNN for the given problem:

main.m
% Load the data
clean_data = load('clean_NMR.mat');
noisy_data = load('noisy_NMR.mat');

% Define the wavelet parameters
wname = 'sym8';
level = 4;

% Perform wavelet decomposition and thresholding
for i = 1:size(noisy_data, 3)
   % noisy data
   [C, S] = wavedec2(noisy_data(:,:,i), level, wname);
   T = thselect(C,'rigrsure');
   C_t = wthresh(C,'h',T);
   noisy_data_scaled = uint8(waverec2(C_t, S, wname));

   % clean data
   [C, S] = wavedec2(clean_data(:,:,i), level, wname);
   T = thselect(C,'rigrsure');
   C_t = wthresh(C,'h',T);
   clean_data_scaled = uint8(waverec2(C_t, S, wname));

   % store the data
   noisy_data_scaled_all(:,:,i) = noisy_data_scaled;
   clean_data_scaled_all(:,:,i) = clean_data_scaled;
end

% Split the data into training and validation dataset
[trained_cnn, validation_cnn] = trainRatio(0.7);

% Define the CNN architecture
input_layer = imageInputLayer([320 240 1]);
conv_layer1 = convolution2dLayer(3, 32,'Padding', 'same');
relu_layer1 = reluLayer();
max_pool1 = maxPooling2dLayer(2, 'Stride', 2);
conv_layer2 = convolution2dLayer(3, 64, 'Padding', 'same');
relu_layer2 = reluLayer();
max_pool2 = maxPooling2dLayer(2, 'Stride', 2);
fully_connected_layer = fullyConnectedLayer(2);
output_layer = regressionLayer();

layers = [input_layer;
          conv_layer1;
          relu_layer1;
          max_pool1;
          conv_layer2;
          relu_layer2;
          max_pool2;
          fully_connected_layer;
          output_layer];

% Define the training options
options = trainingOptions('adam', ...
                          'MaxEpochs', 10, ...
                          'MiniBatchSize', 50, ...
                          'Shuffle', 'every-epoch', ...
                          'ValidationData', validation_cnn, ...
                          'ValidationFrequency', 30, ...
                          'Verbose', false, ...
                          'Plots', 'training-progress');
            
% Train the CNN
trained_net = trainNetwork(noisy_data_scaled_all, clean_data_scaled_all, layers, options);
2041 chars
64 lines

In this code, we first load the clean and noisy data. We then perform the wavelet decomposition and thresholding on both datasets. After pre-processing, we split the data and define the CNN architecture. Finally, we define the training options and train the CNN using trainNetwork.

Note: The above code is a sample and may require modification according to the size, feature-set of the NMR dataset.

gistlibby LogSnag