Requested 48000x48000 (17.2GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. Error in dtw (line 16) d=(repmat(​t(:),1,M)-​repmat(r(:​)',N,1)).^​2; %t

507 views (last 30 days)
clc,clear, close all
warning off;
[dist,ix,iy] = dtw(audio,speech)
Jan on 1 Jun 2021
Edited: Jan on 5 Apr 2022
Correct. For the dtw() command, a matrix is created, which has the sizes of the inputs as side lengths. This means, that 2 huge signals create a huge^2 matrix. If this exhausts your memory, you need more memory or smaller inputs.There is no magic third way.

Sign in to comment.

Accepted Answer

Chidvi Modala
Chidvi Modala on 3 Jun 2021
This issue could be due to RAM limitations. You may try the following suggestions:
1.Go to MATLAB > Preferences > Workspace and ensure the Maximum array size limit is set to 100%.
Then execute 'memory' command in the Command Window and send the output. Ensure that the Maximum possible array size is larger than the memory required by the data.
2. Also, check that the Java Heap Memory is not set to a very large value because that might restrict the amount of memory available to perform computations.
Walter Roberson
Walter Roberson on 15 Jul 2023
You simply cannot do what you want to do, not unless you have a lot of RAM.
dtw() creates an array that is numel() of the first parameter by numel() of the second parameter. When you are passing in entire audio selections, numel() is often fairly large -- for example, 3 minutes of mono at 44100 samples per second is
format long g
ans =
close to 8 mega-samples, and if you were to try to dynamic time warp against something the same size you would need
ans =
array entries each of which were 8 bytes long.
For this reason, Don't Do That . Instead, divide the signals up into overlapping segments, apply a windowing function to each segment to reduce edge effects, and dtw one segment of the first against one signal of the second. Or if you need to figure out where one starts with respect to another, divide one into segments and xcorr each segment against the whole of the other until you get a match, and then trim appropriately before doing segment-by-segment dtw.
Sathish on 7 Nov 2023
I followed @Chidvi Modala suggestion and along with that I unchecked the Matlab array size limit. Now I dont see any memory issue in my case.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 3 Jun 2021
This is the kind of reason why spectrograms and similar processes take windows into the data.
To prevent artifacts where the windows join, typically overlapping windows are used.
For some kinds of processes, 50% overlap is used -- so for example for [1 2 3 4 5 6], one window would be [1 2 3 4], then the second window would be [3 4 5 6].
For other kinds of processes, a 10% overlap is common.
For audio, instead of a fixed size of overlap, it sometimes make sense to calculate the overlap based upon a particular time. To make up a number, there might be certain cases where some kinds of distortions tend to become perceptible around 5 milliseconds, so the overlap might be chosen in terms of the number of samples that fit 5 milliseconds.
The size of the window, together with the sampling frequency, will determine the frequency resolution.
If you have 48000 samples, then you just might be working with one second of sound at 48000 samples per second. 48000 is one of the "magic numbers" in audio: 48000 samples per second gets used for some kinds of professional audio, such as DVDs, but 24000 samples per second is not nearly as likely to be used. Instead, near that range, 22050 samples per second is more likely, as that is CD quality.
At 48000 Hz, that is about 21 microseconds per sample. says that humans can detect timing differences of 30 microseconds. You just might be studying timing perception, so potentially you might not be able to window much at all.

Community Treasure Hunt

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

Start Hunting!