<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258858</link>
    <title>MATLAB Central Newsreader - How to change the resolution of audio data using MATLAB?</title>
    <description>Feed for thread: How to change the resolution of audio data using MATLAB?</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 19 Aug 2009 11:02:02 -0400</pubDate>
      <title>How to change the resolution of audio data using MATLAB?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258858#674195</link>
      <author>jean young</author>
      <description>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.&lt;br&gt;
&lt;br&gt;
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).&lt;br&gt;
%-------------------------------------------------------&lt;br&gt;
nbits = 10;	% resolution after transform&lt;br&gt;
[src,fs,bits] = wavread('audio'); &lt;br&gt;
y = src(:);&lt;br&gt;
y1 = y*(2^bits/2)+(2^bits/2);&lt;br&gt;
numSnapshot = size(y1,1);&lt;br&gt;
ini = bits-nbits+1;&lt;br&gt;
for n = 1:numSnapshot&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x1 = dec2binvec(y1(n));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x2 = x1(ini:end);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x3(n,1) = binvec2dec(x2);&lt;br&gt;
end&lt;br&gt;
y2 = (x3-(2^nbits/2))/(2^nbits/2);&lt;br&gt;
dif = y-y2;&lt;br&gt;
plot(1:numSnapshot,y2,'k-',1:numSnapshot,dif,'r-')&lt;br&gt;
%-------------------------------------------------------&lt;br&gt;
However, I feel this method is somewhat stupid because it takes long time in the loops, especially when the audio data has large size. :-(&lt;br&gt;
&lt;br&gt;
Anyone knows better method? Any help is highly appreciated!</description>
    </item>
    <item>
      <pubDate>Wed, 19 Aug 2009 15:44:40 -0400</pubDate>
      <title>Re: How to change the resolution of audio data using MATLAB?</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/258858#674260</link>
      <author>dbd</author>
      <description>On Aug 19, 4:02 am, &quot;jean young&quot; &amp;lt;jean_young...@yahoo.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; 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).&lt;br&gt;
&amp;gt; ...&lt;br&gt;
&amp;gt; Anyone knows better method? Any help is highly appreciated!&lt;br&gt;
&lt;br&gt;
A faster approximate method might be:&lt;br&gt;
&lt;br&gt;
nbitdata = round(2^(nbit-1)*src)/2^(nbit-1);&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Dale B. Dalrymple</description>
    </item>
  </channel>
</rss>

