function scalogram = computeScalogram(waveform,opt)
% Build the filter bank for the scalogram
scalogram_filter_options.Q = opt.nFilters_per_octave; % number of filters per octave
scalogram_filter_options.B = opt.quality_factor; % reciprocal octave bandwidth
scalogram_filter_options.P = 0; % no equally-spaced filters
scalogram_filter_options.J = T_to_J(opt.averaging_length(1),scalogram_filter_options);
scalogram_scattering_options.phi_renormalize = false;
waveform_length = length(waveform);
scalogram_filterbank_cell = ...
        filter_bank(waveform_length,scalogram_filter_options);

% Initialize scattering network with a single cell: the waveform
waveform_cell{1}.signal{1} = waveform;
waveform_cell{1}.meta.j = zeros(0,1);
waveform_cell{1}.meta.q = zeros(0,1);
waveform_cell{1}.meta.resolution = 0;

% Perform complex wavelet transform
[~,wavelet_transform] = wavelet_layer_1d(waveform_cell{1},scalogram_filterbank_cell{1});

% Get scalogram with element-wise modulus
scalogram = modulus_layer(wavelet_transform);

% Perform loudness compression of the scalogram
if isfield(opt,'compression_exponent')
	scalogram.signal = ...
		cellfun(@(x) x.^opt.compression_exponent,scalogram.signal,'UniformOutput',false);
end

end
