# How to pad a array representing music to pad the stft of this array?

I have an array named samples of size (2, 1321967) representing an audio file. When I pass it to scipy stft with

f, t, Zxx = scipy.signal.stft(samples, sample_rate, nperseg=254)


My array t is of size (10411). I would like to pad t and Zxx 127 points to the right and to the left. To get my padding, I would like to pad samples and then pass it to stft.

How many points do I need to pad to samples in order to get the right size for t?

After some reading, I found the solution to my problem. In the default mode, windows overlap on half their size. Scipy starts by adding zeroes at the boundaries on the left and on the right so that the first and last window are centered on the first and last point of data. Then it pads the end with zeroes so that the last windows on the right is full of point. So, in order to add a window on the left/right, you have to add nperseg/2(127 in my case) points of data. So to add 127 windows on the right and on the left, you just need to add 127^2 = 16129 points on the right and of the left of the original data.

Edit : Based on how the stft is computed, if the original signal is zero-padded on the right and left, any new window created will be on data points with value 0, and as a result will have a value of 0. This means that it is exactly equivalent to 0-pad the original signal of 127*n points or to 0-pad the stft of n points.