我正在用MATLAB录制一些声音,然后将其从16位降到1位,因此我可以计算SNR,但是我没有获得合理的SNR数字。有人指出我正确的方向吗?
% Store recorded audio signal in numeric array
signal = getaudiodata(recording, 'int16');
quanRate = 16;
quantsignal = signal;
while quanRate ~= 1
quanRate = quanRate - 1;
quantsignalHold = quantsignal;
% Remove LSB using bitshift
quantsignal = bitshift(quantsignal, -1);
% Plot the quantized signal
figure()
plot(quantsignal);
title(['Sample recording at ' num2str(quanRate) '-bits']);
xlabel('Sample number') % x-axis label
ylabel('Sample value') % y-axis label
% Calculate the quantisation error
quantError = quantsignal - signal;
% Calculate the SNR
SNR = snr(signal,quantError);
disp(['The SNR of the ' num2str(quanRate) '-bit recording is: ' num2str(SNR) ' dB'])
end
答案 0 :(得分:2)
通过将信号的样本向右移动,将其除以2。此量化信号与原始信号之间的差总是信号幅度的一半,而不是量化误差。
您可能想用来量化
floor( signal / N ) * N + N/2;
或类似内容(N
为2的幂,每次循环迭代都会增加)。