# Is there a way to use decimation or linear interpolation to shrink or stretch an audio signal in the time domain?

I am able to shrink/stretch an audio signal using Python code for a phase vocoder, as well as the stretchAudio function from Matlab's Audio Toolbox. Although both methods do indeed alter the audio signal in the time domain without changing the pitch (which is what I want), both methods damage the spectral structure enough that the sound quality becomes metallic and reverberant, which is not acceptable for the experiment I need to conduct.

I have been told that it is possible (though unorthodox) to shrink and stretch the signal with no unwanted artifacts by using decimation and linear interpolation. Unfortunately I cannot imagine how to do this. I'll appreciate any information or explanations you can offer. Ideally I'll be able to implement this in Python or Matlab.

• are you trying to shrink or stretch an audio signal in length without changing the pitch? you need a lot more than decimation or linear interpolation. a phase vocoder is one way to do it. there are other ways. – robert bristow-johnson Apr 7 at 16:08

If you are resampling by an integer factor you can simply decimate the audio.

If you want to down sample directly in the time domain you can apply interpolation. One type of interpolation is the linear interpolation, but you have others, MATLAB provides interpolation out of the box with the interp1 function.

If you have sampled wave data, you can separate each channel you can get the resampled data as

resampled = interp1(y, 1:interval:length(y), smoothing);


The interval is the fined as (1 + speedup) * Fs / Ft where Fs is the sampling frequency and Ft is the target sampling frequency, and speedup makes the playback faster or slower (same if speedup=0)

Here an example use of interp1

y = randn(1, 10);
t = linspace(1, 10, 1000);
hold all;
plot(t, interp1(t, y, 'linear'))
plot(t, interp1(t, y, 'linear'))
plot(t, interp1(y, t, 'linear'))
plot(t, interp1(y, t, 'cubic'))
plot(y, 'or')
l = legend('linear', 'cubic', 'spline')
set(l, 'fontsize', 12)


The same is possible in python using scipy.interpolate functions. But in that case you first create a sampler and then you call it how many times you want.

You can stretch or shrink it this way, but it will be like speeding up or slowing down a tape: the pitch will change as well. You are resampling the signal, badly.

Using decimation to shorten will result in aliasing and using linear interpolation to lengthen will result in unwanted spectral images. You'd be better using the resample function in Matlab, which at least uses a somewhat decent resampling filter.