|
Hi, I have some audio data stored in .wav file. I got them using wavread function in MATLAB and found the sampling rate is 8-kHz and the resolution is 16 bits. My supervisor asked me to change the resolution to 12 bits and 10 bits then I can see the difference.
The problem is that most softwares (e.g. wavwrite in MATLAB, Cool Edit) only do the transform among 8 bits, 16 bits, 24 bits and 32 bits. Therefore I tried to write code to do this myself (see my code below).
%-------------------------------------------------------
nbits = 10; % resolution after transform
[src,fs,bits] = wavread('audio');
y = src(:);
y1 = y*(2^bits/2)+(2^bits/2);
numSnapshot = size(y1,1);
ini = bits-nbits+1;
for n = 1:numSnapshot
x1 = dec2binvec(y1(n));
x2 = x1(ini:end);
x3(n,1) = binvec2dec(x2);
end
y2 = (x3-(2^nbits/2))/(2^nbits/2);
dif = y-y2;
plot(1:numSnapshot,y2,'k-',1:numSnapshot,dif,'r-')
%-------------------------------------------------------
However, I feel this method is somewhat stupid because it takes long time in the loops, especially when the audio data has large size. :-(
Anyone knows better method? Any help is highly appreciated!
|