0

I have a recorded a sound wave (16-bit single channel) using audiorecorder and I need to quantize it into 15 bits (removing LSB) without using toolboxes other than MATLAB built-in ones. Can anyone help on this?

fs = 8000;
tmax = 2;
nbits = 16;
nchan = 1;
Recorder = audiorecorder(fs, nbits, nchan);
record(Recorder);
pause(tmax);
stop(Recorder);
Bababarghi
  • 571
  • 1
  • 4
  • 23

2 Answers2

0

Ok, since you acknowledge this is a homework question and are asking for a method not a solution, first, you need the signal values

x = Recorder.getaudiodata('int16');

Since you are going to be quantizing you might as well start with values in the right range, as opposed to doubles which would be normalized [-1, 1]

So, next you need to quantize from 16 bits to 15. This is actually pretty easy in matlab, if you're writing a ton of code, it's probably not working. There are several ways you could do it.

Essentially, you're throwing away half the information when you remove 1 bit.

Take the numbers 0, 1, 2, 3 which have 2 bit precision. In binary, 00, 01, 10, 11. If I quantize to one bit, I throw away half the information. Imagine the LSB is gone, I'd have 0, 0, 1, 1. But, my original numbers span 0 to 3... Typically you want your numbers to have the same dynamic range. So, I threw half the numbers away, what if I scale the new numbers by 2? I get 0, 0, 2, 2. This is a correct quantization from 2 to 1 bit.

In your problem, what would happen if all the odd numbers were even?

0

You can use the bitshift function in MATLAB. I believe

Recorder = audiorecorder(fs, nbits, nchan);
data = getaudiodata(Recorder, 'int16');
outData = bitshift(data, -1);

Hope this helps.

Dinesh

Dinesh Iyer
  • 681
  • 3
  • 11