Thread Subject: How to change the resolution of audio data using MATLAB?

Subject: How to change the resolution of audio data using MATLAB?

From: jean young

Date: 19 Aug, 2009 11:02:02

Message: 1 of 2

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!

Subject: How to change the resolution of audio data using MATLAB?

From: dbd

Date: 19 Aug, 2009 15:44:40

Message: 2 of 2

On Aug 19, 4:02 am, "jean young" <jean_young...@yahoo.com> wrote:
> 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).
> ...
> Anyone knows better method? Any help is highly appreciated!

A faster approximate method might be:

nbitdata = round(2^(nbit-1)*src)/2^(nbit-1);


Dale B. Dalrymple

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
wav file jean young 19 Aug, 2009 07:04:03
resolution jean young 19 Aug, 2009 07:04:03
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com