How to process cwt in chunks?

4 vues (au cours des 30 derniers jours)
OPG
OPG le 15 Oct 2024
Hi,
I'm working on applying a cwt (morse wavelet) on large signals. I'm trying to perform the cwt for chunks of the signal, but the results I'm getting look off. I think the issue might be the combination of the results: since I have thousands of chunks, the data, once combined, does not look smooth and might have artifacts. The code I wrote for this is pasted below. Does anyone know how I can fix this issue or process the data in chunks in a more correct manner?
Thanks in advance.
function [combined_wt, combined_f, time_pad] = chunked_cwt(signal, fs, chunk_size)
if nargin < 3
chunk_size = 1e3;
end
if nargin < 2
fs = 0;
chunk_size = 1e3;
end
num_chunks = ceil(length(signal) / chunk_size);
fprintf('Num chunks: %d', num_chunks)
cwt_results = cell(1, num_chunks);
for i = 1:num_chunks
start_idx = (i-1) * chunk_size + 1;
end_idx = min(i * chunk_size, length(signal));
chunk = signal(:,start_idx:end_idx);
if length(chunk) ~= chunk_size
time_pad = chunk_size - length(chunk);
chunk = [chunk, zeros(1,chunk_size-length(chunk))];
end
% Compute the CWT for the current chunk
if fs > 0
% [wt, f] = cwt(chunk,FilterBank=fb);
[wt,f] = cwt(chunk,fs);
else
[wt, f] = cwt(chunk,FilterBank=fb);
end
% Store the result
cwt_results{i} = struct('wt', wt, 'f', f, 'start_idx', start_idx, 'end_idx', end_idx);
end
disp('Aggregating results...')
% Example: Combine scalograms
combined_wt = []; combined_f = [];
for i = 1:num_chunks
combined_wt = [combined_wt, cwt_results{i}.wt];
combined_f = [combined_f, cwt_results{i}.f];
end
end

Réponses (1)

Walter Roberson
Walter Roberson le 15 Oct 2024
since I have thousands of chunks, the data, once combined, does not look smooth and might have artifacts
Consider: if you process your signal as two non-overlapping chunks, then the information returned from the first chunk cannot contain any information related to the second chunk, and the information related to the second chunk cannot contain any information related to the first chunk. Putting the two parts together results in a discontinuity at the chunk boundary.
There are some filtering routines that are able to return a state vector, and that can accept a state vector on input. Such filtering routines are adapted to be able to handle chunks smoothly. Unfortunately, cwt() does not appear to be one of those routines.
The usual work-around to reduce the effects of the discontinuities, is to use overlapping windows onto the signal. Sometimes the overlap is 50%; other times it is considerably smaller (for example, 64 samples.)

Catégories

En savoir plus sur Time-Frequency Analysis dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by