CWT on each frequency one at a time
Show older comments
I have a very large matrix (512x1500000) and I want to run CWT on each row. However, since CWT creates a new dimension with its frequency bands, I am running into memory issues. I do not need to store all frequency bands; I just need to run the analysis on each frequency band individually. So, I am wondering if there is a way to run CWT on each frequency band one at a time in a for loop.
3 Comments
Umar
on 5 Jun 2024
To address this issue, you can indeed run CWT on each frequency band one at a time in a for loop. This approach allows you to process the data sequentially, focusing on one frequency band at a time without the need to store all frequency bands simultaneously in memory. By implementing a for loop to iterate through each frequency band, you can apply the CWT analysis on a per-band basis, effectively managing memory usage and avoiding overload. This method enables you to conduct the analysis efficiently and effectively while optimizing memory utilization. Furthermore, utilizing this iterative approach in a for loop allows you to customize the processing of each frequency band, enabling more targeted and specific analysis tailored to your requirements. By executing CWT on individual frequency bands sequentially, you can achieve your desired outcome without encountering memory constraints. In conclusion, running CWT on each frequency band one at a time in a for loop is a practical solution to address your memory issues and perform the analysis efficiently. This method offers flexibility, control, and optimized memory management, allowing you to focus on analyzing specific frequency bands without overwhelming system resources. Consider implementing this approach to streamline your CWT analysis process effectively.
ryoroy
on 5 Jun 2024
Mathieu NOE
on 6 Jun 2024
I wonder if you could also do a n th octave analysis , so passing each data (channel) inside bandpass filter (with a for loop to switch to the next band) , then you could buffer the output of the filter and take the rms for a given time period and you would end up with a kind of n th octave spectrogram
you can then fine tune your frequency and time resoltion by playing with n (the 1/n octave band) , the buffer size and overlap.
just my 2 cents
Answers (1)
Swastik Sarkar
on 20 Aug 2024
I attempted to replicate your issue by creating a random matrix “data” of dimension 512x1500000 and running the Continuous Wavelet Transform (CWT) on each row. Here's the sample code I used:
numRows = 512;
numCols = 1500000;
data = randn(numRows, numCols);
for i=1:numRows
disp(i)
cwt(data(i,:))
end
I observed that the memory usage fluctuated between two values, likely due to memory allocation and deallocation during each loop iteration. Initially, the MATLAB process consumed 18GB, which increased to 27GB during the CWT operation on a row.
To optimize the process, I modified the MATLAB code to perform CWT not only row by row but also for each frequency band. This approach reduced the RAM consumption to a constant 11GB, although it increased the computation time.
numRows = 512;
numCols = 150000;
data = rand(numRows, numCols);
scales = 1:10; % Adjust Scales accordingly
cwtResults = cell(numRows, 1);
for i = 1:numRows
cwtRow = cell(1, numCols);
for j = 1:numCols
cwtRow{j} = cwt(data(i, j), scales, ‘morl’);
end
cwtResults{i} = cwtRow;
end
To address your query about performing CWT for a single frequency band, you can use the following approach:
desiredFrequency = 10; % Desired frequency in Hz
desiredTimeScale = 1 / (desiredFrequency * waveletScale);
cwtResult = cwt(data, desiredTimeScale, waveletAlgo);
I hope you find a similar outcome, and this helps you.
Categories
Find more on Continuous Wavelet Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!