I have been trying to make and understand ADCs using Matlab. I made this little program that allows me to modify the number of bits from the waveform (2^8 , 8 being the No of bits, can go from 1 to 64). However, when playing the sound in the computer, it sounds like if there was something stopping the sound. It's possible to change the frequency however the problem persists. I'm wondering what did I do wrong?
clf %clr screen
t = 0:1:1600
fs = 1000
senial = sin((2*pi*t)/fs)
quant=max(senial)/(2^8) % R/L = size of sep
y=round(senial/quant) % Quantizationto 2^N bit
signe=uint8((sign(y)'+1)/2) % transforms it to int 8 bit
out=[signe] % The first bit represents the sign of the number
sound(y,fs)
plot(y,'b');
A couple of things. First, your generating a sine that is only 1Hz so you're never going to be able to hear it.
t = 0:1:1600
fs = 1000
freq = 440
senial = sin(2*pi*t*freq/fs)
play(senial, 1000)
The next issue is with your quantization. You're almost there except you didn't renormalize the data back to the -1 to 1 range. You're probably hearing clipping. Try something like this:
y = round(senial*2^8)/2^8
Here's an example (1Hz again just to make the plot easier)
plot(round(sin(2*pi*t/1000)*2^4)/2^4)