Skip to content

Instantly share code, notes, and snippets.

@sandyUni
Created December 20, 2013 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandyUni/8053602 to your computer and use it in GitHub Desktop.
Save sandyUni/8053602 to your computer and use it in GitHub Desktop.
quantization Noise Spectrum analysis.Mybe there are bug over there
close all
clear all
% for n=1:10:10000
fsample=1424424;
f=fsample/1020.32;
A=1;
lens=2^20;
N=15;
theta=(2*pi*f/fsample*[1:lens]);
Sig=sin(theta);
quantizedSig=round(2^(N-1)*Sig);
% plot([Sig',quantizedSig']);
% plot(2^(N-1)*Sig(1:10000)-quantizedSig(1:10000));
% figure();
% hist(2^(N-1)*Sig(1:10000)-quantizedSig(1:10000),100);
h2=figure(1);
subplot(211)
plot(2^(N-1)*Sig(1:10000)-quantizedSig(1:10000));
title('量化误差');
subplot(212);
fftvar=abs(fft(2^(N-1)*Sig-quantizedSig).^2);
f=linspace(0,fsample,length(fftvar));
plot(f,fftvar);
title('量化误差功率谱');
filename=strcat('b',num2str(1),'.png');
saveas(h2,filename);
% disp('信号功率:');
% Ps=mean((2^(N-1)*Sig).^2);
% disp(Ps);
% disp('量化噪声功率:');
% Pn=mean((2^(N-1)*Sig-quantizedSig).^2);
% disp(Pn);
% disp('信噪比:');
% disp(10*log(Ps/Pn));
% disp('理论信噪比');
% disp(1.76+6.02*N);
% filename=strcat('b',num2str(n),'.png');
% saveas(h2,filename);
% end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment