the nmr sequence wavelet coefficients are input as cnn-resnet, and the corresponding nmr sequence wavelet coefficients are used as cnn-resnet output for denoising in matlab

To use wavelet coefficients as input to a CNN-ResNet in Matlab, you can follow the following steps:

  1. Load and Normalize Data: Load the wavelet coefficients of the NMR sequence and normalize the data. You can use z-score normalization which calculates mean and standard deviation of data and scales the data to have zero mean and unit standard deviation.

    main.m
     load("nmr_wavelet_coeffs.mat")
     % normalizing the data 
     coeffs = zscore(nmr_wavelet_coeffs);
    
    95 chars
    4 lines
  2. Prepare Data for Training: Divide the data set into training, validation and test sets.

    main.m
    %Number of samples
    N = size(coeffs,1);   
    %Time step
    L = size(coeffs,2);  
    % Dividing the data as training, validation, and testing sets. 
    numTrain = round(N*0.60);
    numVal = round(N*0.20);
    numTest = N-numTrain-numVal;
    
    XTrain = coeffs(1:numTrain,1:L-1);
    YTrain = coeffs(1:numTrain,L);
    XValidation = coeffs(numTrain+1:numTrain+numVal,1:L-1);
    YValidation = coeffs(numTrain+1:numTrain+numVal,L);
    XTest = coeffs(numTrain+numVal+1:end,1:L-1);
    YTest = coeffs(numTrain+numVal+1:end,L);
    
    479 chars
    16 lines
  3. Define Layers: Define the layers of the CNN-ResNet. Add Convolution 1D layers, Relu Activation layers, Batch Normalization layers, Residual Connection blocks and Dense layers.

    main.m
     % define layers
     layers = [
         sequenceInputLayer(L-1,'Name','input')   
         convolution1dLayer(32, 4, 'Padding', 'same', 'Name', 'conv1') 
         batchNormalizationLayer('Name','BN1')
         reluLayer('Name','relu1')
         convolution1dLayer(64, 4, 'Padding', 'same', 'Name', 'conv2') 
         batchNormalizationLayer('Name','BN2')
         reluLayer('Name','relu2')
         convolution1dLayer(128, 4, 'Padding', 'same', 'Name', 'conv3') 
         batchNormalizationLayer('Name','BN3')
         reluLayer('Name','relu3')
         convolution1dLayer(256, 4, 'Padding', 'same', 'Name', 'conv4') 
         batchNormalizationLayer('Name','BN4')
         reluLayer('Name','relu4')
         sequenceFoldingLayer('Name','fold')
         ];
    
     b = [
         batchNormalizationLayer('Name','BN5')
         reluLayer('Name','relu5')
         convolution1dLayer(1, 4, 'Padding', 'same', 'Name', 'conv5') 
         regressionLayer('Name','output')
         ];
    
     layers = [layers b];
    
    913 chars
    27 lines
  4. Train the model: Train the CNN-ResNet model using training and validation data.

    main.m
    options = trainingOptions("adam", ...
     "ExecutionEnvironment",'auto', ...
     "MaxEpochs",30, ...
     "MiniBatchSize",256, ...     
     "SequenceLength",'longest', ...
     "Shuffle","every-epoch", ...
     "ValidationData",{XValidation,YValidation}, ...
     "ValidationFrequency",10, ...
     "ValidationPatience",Inf, ...
     "Verbose",false, ...
     "Plots","training-progress");
         
    
     net = trainNetwork(XTrain',YTrain',layers,options);
    
    413 chars
    15 lines
  5. Test the model: Test the model using the test data.

    main.m
    YPred = classify(net,XTest');
    YTest = categorical(YTest);
    
    accuracy = sum(YPred==YTest)/numel(YTest);
    
    102 chars
    5 lines
  6. Evaluate the model: Evaluate the model using different metrics like Mean Squared Error (MSE).

    main.m
     YPred = predict(net,XTest');
     MSE = mean((YPred-YTest').^2);
    
    62 chars
    3 lines

This code will create a CNN-ResNet model for denoising the NMR sequence wavelet coefficients in Matlab.

gistlibby LogSnag