[y, fs, nbits]=wavread('project.wav');
N=length(y);
k=log2(nbits);
n = N;
numSamplesPerSymbol = 1;
rng default
dataIn = y;
dataInMatrix = reshape(dataIn,length(dataIn)/k,k);
dataSymbolsIn = bi2de(real(dataInMatrix));
dataMod = qammod(dataSymbolsIn,nbits,0);
dataModG = qammod(dataSymbolsIn,nbits,0,'gray');
disp('Press any Key to Listen to Modulated Voice'); pause
soundsc(real(dataMod,dataModG))
EbNo = 10;
snr = EbNo + 10*log10(k) - 10*log10(numSamplesPerSymbol);
receivedSignal = awgn(dataMod,snr,'measured');
receivedSignalG = awgn(dataModG,snr,'measured');
disp('Press any Key to Listen to noise Voice'); pause
soundsc(real(receivedSignal,receivedSignalG))
dataSymbolsOut = qamdemod(receivedSignal,nbits);
dataSymbolsOutG = qamdemod(receivedSignalG,nbits,0,'gray');
disp('Press any Key to Listen to Demodulated Voice'); pause
soundsc(real(dataSymbolsOu,dataSymbolsOutG))
dataOutMatrix = de2bi(dataSymbolsOut,k);
dataOut = dataOutMatrix(:);
dataOutMatrixG = de2bi(dataSymbolsOutG,k);
dataOutG = dataOutMatrixG(:);
[numErrors,ber] = biterr(dataIn,dataOut);
fprintf('\nThe binary coding bit error rate = %5.2e, based on %d errors\n', ...
ber,numErrors)
[numErrorsG,berG] = biterr(dataIn,dataOutG);
fprintf('\nThe Gray coding bit error rate = %5.2e, based on %d errors\n', ...
berG,numErrorsG)