Contents
clear all
close all
writefiles = 1;
loopcount = 0;
defaultbits = [3 4 6 8 10 12 14];
[speech,fs] = wavread('the pipe began to leak 2.wav');
while 1
new number of bits
loopcount = loopcount + 1;
if loopcount <= length(defaultbits)
thisdefault = loopcount;
end
qtxt = 'The speech file was recorded at 16 bit resolution. You may requantize it to any resolution you choose between 15 and 2 bits. You should at least try 4, 6, 8 and 10 bits. Are you ready to choose a number bits to quantize with? ';
button = questdlg(qtxt,'Ready?','Choose Bits','Quit','Choose Bits');
if strcmp(button,'Quit'), return; end;
bits = 0;
while bits<2 || bits>15
prompt = 'How many bits would you like to use?';
nbitstr = inputdlg(prompt,'Number of bits',1,cellstr(num2str(defaultbits(thisdefault))));
if isempty(nbitstr)
return;
else
[bits status] = str2num(nbitstr{1});
end;
if ~status, bits = 0; end;
if bits<2 || bits>15, errordlg('Choose a value between 2 and 15','Bit Range Error','modal'); end;
end;
intspeech = round(2^(bits-1)*speech);
qspeech = intspeech/2^(bits-1);
if writefiles
qfilename = ['qspeech_' num2str(bits) 'bits.wav'];
err = qspeech-speech;
errfilename = ['norm_errspeech_' num2str(bits) 'bits.wav'];
warning off
wavwrite(qspeech,fs,qfilename)
wavwrite(0.25*err/max(abs(err)),fs,errfilename)
warning on
end
range = 11300:11499;
h1 = figure(1);
op = get(h1,'OuterPosition');
op(1) = 1;
set(h1,'OuterPosition',op)
subplot(311)
plot(speech(range)); title(['Original Speech'])
subplot(312)
plot(qspeech(range)); title(['Quantized Speech - ' num2str(bits) ' bits'])
subplot(313)
plot(err(range)); title(['Quantization Error - ' num2str(bits) ' bits'])
drawnow();
h = msgbox('Playing Original','Info','replace');
player = audioplayer(speech,fs,16);
playblocking(player);
close(h);
h = msgbox('Playing Quantized','Info','replace');
player = audioplayer(qspeech,fs,16);
playblocking(player);
close(h);
h = msgbox('Playing Quantization Error (Normalized for audibility)','Info','replace');
player = audioplayer(0.25*err/max(abs(err)),fs,16);
playblocking(player);
close(h);
qtxt = 'Note that while the quantized speech remains (barely) intelligible at any bit resolution, the signal can be distinguished in the noise at both very high and very low bit resolutions. This is because at low resolutions the quantization steps are large compared to the signal (violating our assumptions), and at high resolutions there are very few total error levels (preventing the error from being approximately uniform). If we were starting with an unquantized waveform the error would become more uniform as the number of bits increased.';
button = questdlg(qtxt,'Info','OK','OK');
disp(textwrap(cellstr(qtxt),80))
'Note that while the quantized speech remains (barely) intelligible at any bit '
'resolution, the signal can be distinguished in the noise at both very high and '
'very low bit resolutions. This is because at low resolutions the quantization '
'steps are large compared to the signal (violating our assumptions), and at high '
'resolutions there are very few total error levels (preventing the error from '
'being approximately uniform). If we were starting with an unquantized waveform '
'the error would become more uniform as the number of bits increased.'
'Note that while the quantized speech remains (barely) intelligible at any bit '
'resolution, the signal can be distinguished in the noise at both very high and '
'very low bit resolutions. This is because at low resolutions the quantization '
'steps are large compared to the signal (violating our assumptions), and at high '
'resolutions there are very few total error levels (preventing the error from '
'being approximately uniform). If we were starting with an unquantized waveform '
'the error would become more uniform as the number of bits increased.'
'Note that while the quantized speech remains (barely) intelligible at any bit '
'resolution, the signal can be distinguished in the noise at both very high and '
'very low bit resolutions. This is because at low resolutions the quantization '
'steps are large compared to the signal (violating our assumptions), and at high '
'resolutions there are very few total error levels (preventing the error from '
'being approximately uniform). If we were starting with an unquantized waveform '
'the error would become more uniform as the number of bits increased.'
'Note that while the quantized speech remains (barely) intelligible at any bit '
'resolution, the signal can be distinguished in the noise at both very high and '
'very low bit resolutions. This is because at low resolutions the quantization '
'steps are large compared to the signal (violating our assumptions), and at high '
'resolutions there are very few total error levels (preventing the error from '
'being approximately uniform). If we were starting with an unquantized waveform '
'the error would become more uniform as the number of bits increased.'
'Note that while the quantized speech remains (barely) intelligible at any bit '
'resolution, the signal can be distinguished in the noise at both very high and '
'very low bit resolutions. This is because at low resolutions the quantization '
'steps are large compared to the signal (violating our assumptions), and at high '
'resolutions there are very few total error levels (preventing the error from '
'being approximately uniform). If we were starting with an unquantized waveform '
'the error would become more uniform as the number of bits increased.'
'Note that while the quantized speech remains (barely) intelligible at any bit '
'resolution, the signal can be distinguished in the noise at both very high and '
'very low bit resolutions. This is because at low resolutions the quantization '
'steps are large compared to the signal (violating our assumptions), and at high '
'resolutions there are very few total error levels (preventing the error from '
'being approximately uniform). If we were starting with an unquantized waveform '
'the error would become more uniform as the number of bits increased.'
'Note that while the quantized speech remains (barely) intelligible at any bit '
'resolution, the signal can be distinguished in the noise at both very high and '
'very low bit resolutions. This is because at low resolutions the quantization '
'steps are large compared to the signal (violating our assumptions), and at high '
'resolutions there are very few total error levels (preventing the error from '
'being approximately uniform). If we were starting with an unquantized waveform '
'the error would become more uniform as the number of bits increased.'
end