Upsampling algorithm too slow I have to come up with an upsampling algorithm for a project and cannot use Matlab's built in upsample function. I came up with the following function but it just runs forever when I use a 13 second, 16-bit song sampled at 44.1kHz. Please let me know how I can improve the efficiency of this algorithm: 

    x = desired_Fs/original_Fs; %desired and original sampling frequencies
    len = x * length(y); %y is the input signal
    q = x - 1;

    for i = 1:x:len
       for j = length(y):-1:i+1
            y(j + q) = y(j);
       end
       for k = i+1:1:i+q
            y(k) = 0;
       end
    end `
    upsampled_audio = y;
First, you should use informative variable names. For example, use "upsample_ratio" instead of x, "inSignal" instead of y etc. This will make your code much easier to read and understand.

Second, you should avoid using for loops in matlab if possible, and especially don't use nested for loops, since they take very long time in matlab.

Third, you overuse the variable y. Use intermediate variables to keep temporary and result values. 

Forth, your algorithm concept is wrong in case the upsampling ratio is not a whole number.

Specifically for your code, start by replacing the inner loops with array operations:

vec = length(y):-1:i+1;
y(vec+q) = y(vec);
y(i+1:1:i+1) = 0;