%% Perform 1-D Convolution
% Create a formatted dlarray object containing 128 sequences of length 512 containing 5 features. Specify the format 'CBT' (channel, batch, time).

numChannels = 5;
miniBatchSize = 128;
sequenceLength = 512;
X = rand(numChannels,miniBatchSize,sequenceLength);
dlX = dlarray(X,'CBT');

% Initialize the weights and bias for 1-D convolution. For the weights, specify 64 filters with a filter size of 3. For the bias, specify a vector of zeros.

filterSize = 3;
numFilters = 64;
weights = rand(filterSize,numChannels,numFilters);
bias = zeros(1,numFilters);

% Apply 1-D convolution using the dlconv function. To convolve over the 'T' (time) dimension of the input data, specify the weights format 'TCU' (time, channel, unspecified) using the 'WeightsFormat' option.

dlY = dlconv(dlX,weights,bias,'WeightsFormat','TCU');

% View the size and format of the output.

size(dlY)
dims(dlY)

% Copyright 2020 The MathWorks, Inc.