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)

댓글 수: 5

Mathieu NOE
Mathieu NOE 2020년 10월 15일
hello
I do not get any error
where do you have an error ?
clc
clear
[y,Fs] =audioread('music.wav')
N=length(y);
[f0,idx] = pitch(y,Fs);
subplot(2,1,1)
plot(y)
ylabel('Amplitude')
xlabel('Sample Number')
x=[y];
n=round(length(x)/40);
p=zeros(n,40);
for k=0:39
p(:,k+1)=x(1+n*k:n*(k+1));
end
framesize=N/Fs;
M=round(y/framesize);
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
X=dct(y,32768);
s=framesize*X;
b=length(s');
ratio=N/b;
A=idct(X,32768);
[rows,columns]= size(A)
extra = rows*ceil(numel(A)/rows) - numel(A);
MU=reshape([X(:);nan(extra,1)],rows,columns)
for...
i=1:1:M
if (i==M)
frame1=MU([(framesize*(i-1)+1):length(MU)]);
else
frame1=MU([(framesize*(i-1)+1):framesize*i]);
end
end
[R,C]= size(y);
err = (((y-MU).^2)/(R*C)); % error in this line
MSE=sqrt(err)
subplot(2,1,2)
plot(MU)
ylabel('Amplitude')
This is the code I wrote. Executing this gives me an error. Also, the size of MSE is very large.
Mathieu NOE
Mathieu NOE 2020년 10월 16일
hi
what is the error prompted at the command window ?
Mathieu NOE
Mathieu NOE 2020년 10월 16일
hum
I tried to help but I am blocked because I don't have the Aufio Toolbox
function pitch is notin my path
hope someone else will help you
rachel cn
rachel cn 2020년 10월 16일
Okay..Thank you.

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2020년 10월 16일

2 개 추천

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.

댓글 수: 6

rachel cn
rachel cn 2020년 10월 16일
편집: rachel cn 2020년 10월 16일
Thank you sir. Could you please tell me how do I reconstruct from the dct coefficients back to the full size of y and also how to stop frames from overwriting? I was actually trying to create frames and define them.
Walter Roberson
Walter Roberson 2020년 10월 16일
When you idct instead of passing in 32768, pass in the number of elements in y.
rachel cn
rachel cn 2020년 10월 17일
Thank you sir, it worked
rachel cn
rachel cn 2020년 10월 17일
Can audio compression be performed without creating frames?
Walter Roberson
Walter Roberson 2020년 10월 17일
Yes, certainly, you can compress the entire signal at one time.
However, audio tends to change over time, and wavelets are analyzing patterns that occur over the length of the entire section being analyzed. Imagine for a moment examining the opening notes of Beethoven's Fifth, and then a bit later on when the music has changed a fair bit. Trying to find a pattern that accounts for the entire symphony probably is not going to be as effective as breaking it up into segments so that you only need to worry about shorter-term patterns.
rachel cn
rachel cn 2020년 10월 17일
Thank you sir.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

태그

질문:

2020년 10월 15일

댓글:

2020년 10월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by