function cwt_result = cwt_morlet(signal, scales) % CWT with Morlet Wavelet % input: signal vector % scale vector % output: CWT matrix % N = length(signal); % preallocation of the CWT result array cwt_result = zeros(length(scales), N); % calculation of the CWT on different scales for s = 1:length(scales) scale = scales(s); % calculation of the wavelet for each point of the signal for n = 1:N sum_val = 0; % scaled and translated Morlet wavelet for t = 1:N % t is the translation psi_val = morlet_wavelet((t - n) / scale); sum_val = sum_val + signal(t) * psi_val; end cwt_result(s, n) = sum_val / sqrt(scale); end end cwt_magnitude = abs(cwt_result); % compute the magnitude of the CWT result imagesc(cwt_magnitude); xlabel('time'); ylabel('scale'); colorbar; end