MATLAB: Audio compression using DCT

dct

I'm working on Audio Compression using DCT. How do i expand the size of my sample after performing Inverse Discrete Cosine Transform? The code i have written produces an error saying "matrix dimensions must agree" when i try to find the MSE.
X=dct(y,32768);
s=framesize*X;
b=length(s');
ratio=N/b; % N is the length of the original sample
A=idct(X,32768);
[rows,columns]= size(A)
extra = rows*ceil(numel(X)/rows) - numel(X);
MU=reshape([X(:);nan(extra,1)],rows,columns)

Best Answer

M=round(y/framesize);
You have a problem there. You use M as a size in the code, but you calculate it based upon the content of y and y is a vector, so your M is a vector the same size as y.
for...
i=1:1:M
if (i==M)
frame=y([(framesize*(i-1)+1):length(y)]);
else
frame=y([(framesize*(i-1)+1):framesize*i]);
end
end
You overwrite all of frame in each iteration. If that is your intention, you might as well do only the last iteration, i=M
Likewise your later code overwrites all of frame1
X=dct(y,32768);
Your y is a vector so your X is a vector.
A=idct(X,32768);
Your X is a vector so your A is a vector.
[rows,columns]= size(A)
extra = rows*ceil(numel(A)/rows) - numel(A);
That is a waste of code. numel(A) is always going to be exactly divisible by rows unless rows is 0, so extra is going to always be 0.
MU=reshape([X(:);nan(extra,1)],rows,columns)
With extra being 0, that is just the same as reshape(X(:), rows, columns) but because of the way that X and A are built, X and A are already going to be the same shape.
err = (((y-MU).^2)/(R*C)); % error in this line
y is your original signal, of whatever size it is. You took a 32768 point dct to build X and Mu comes out the same as X, so MU is going to be a vector of length 32768. And it happens that both y and Mu are column vectors. But they are different lengths, y being the original size and MU being the 32768 length. You have a subtraction problem.
Perhaps you want
extra = numel(y) - numel(X);
MU = reshape([X(:), nan(extra,1)], size(y));
err = (((y-MU).^2)/numel(X); %?? numel(y) ??
but it seems pretty strange to deliberately do a lot of subtractions of nan. It would make more sense to subtract X from the first 32768 entries of y, or else to reconstruct from the dct coefficients back to the full size of y.