Plot Quantization Error Matlab
Contents |
Search All Support Resources Support Documentation MathWorks Search MathWorks.com MathWorks Documentation Support Documentation Toggle navigation Trial Software Product Updates Documentation Home Fixed-Point Designer Examples Functions and matlab quantization error Other Reference Release Notes PDF Documentation Fixed-Point Design for MATLAB Code
Matlab Code For Quantization Of Sine Wave
Algorithm Conversion Manual Conversion Compute Quantization Error On this page Uniformly Distributed Random Signal Fix: Round Towards Zero. quantization error using matlab Floor: Round Towards Minus Infinity. Ceil: Round Towards Plus Infinity. Round: Round to Nearest. In a Tie, Round to Largest Magnitude. Convergent: Round to Nearest. In a Tie, Round to
Matlab Quantizer
Even. Comparison of Nearest vs. Convergent Plot Helper Function Compute Quantization ErrorOpen Script This example shows how to compute and compare the statistics of the signal quantization error when using various rounding methods. First, a random signal is created that spans the range of the quantizer. Next, the signal is quantized, respectively, with rounding methods 'fix', 'floor', 'ceil', 'nearest', and quantization in matlab code 'convergent', and the statistics of the signal are estimated. The theoretical probability density function of the quantization error will be computed with ERRPDF, the theoretical mean of the quantization error will be computed with ERRMEAN, and the theoretical variance of the quantization error will be computed with ERRVAR. Uniformly Distributed Random SignalFirst we create a uniformly distributed random signal that spans the domain -1 to 1 of the fixed-point quantizers that we will look at.q = quantizer([8 7]); r = realmax(q); u = r*(2*rand(50000,1) - 1); % Uniformly distributed (-1,1) xi=linspace(-2*eps(q),2*eps(q),256); Fix: Round Towards Zero.Notice that with 'fix' rounding, the probability density function is twice as wide as the others. For this reason, the variance is four times that of the others.q = quantizer('fix',[8 7]); err = quantize(q,u) - u; f_t = errpdf(q,xi); mu_t = errmean(q); v_t = errvar(q); % Theoretical variance = eps(q)^2 / 3 % Theoretical mean = 0 fidemo.qerrordemoplot(q,f_t,xi,mu_t,v_t,err) Estimated error variance (dB) = -46.8586 Theoretical error variance (dB) = -46.9154 Estimated mean = 7.788e-06 Theoretical mean = 0 Floor: Round Towards Minus Infinity.Flo
Search All Support Resources Support Documentation MathWorks Search MathWorks.com MathWorks Documentation Support Documentation Toggle navigation Trial Software Product Updates Documentation Home Fixed-Point Designer Examples Functions and Other Reference Release Notes PDF Documentation Fixed-Point
Quantization Error Formula
Design for MATLAB Code Fixed-Point Functions Math Statistics Fixed-Point Designer Functions errpdf On
Sqnr
this page Syntax Description Examples Compute the PDF of the quantization error See Also errpdfProbability density function of quantization errorcollapse quantization noise all in page Syntax[f,x] = errpdf(q)
f = errpdf(q,x)
Description[f,x] = errpdf(q) returns the probability density function f evaluated at the values in x. The vector x contains the uniformly distributed random quantization errors that https://www.mathworks.com/help/fixedpoint/ug/compute-quantization-error.html arise from quantizing a signal by quantizer object q. f = errpdf(q,x) returns the probability density function f evaluated at the values in vector x. Note The results are not exact when the signal precision is close to the precision of the quantizer.Examplescollapse allCompute the PDF of the quantization errorOpen Script q = quantizer('nearest',[4 3]); [f,x] = errpdf(q); subplot(211) plot(x,f) title('Computed PDF of the quantization error.') The http://www.mathworks.com/help/fixedpoint/ref/errpdf.html output plot shows the probability density function of the quantization error. Compare this result to a plot of the sample probability density function from a Monte Carlo experiment: r = realmax(q); u = 2*r*rand(10000,1)-r; % Original signal y = quantize(q,u); % Quantized signal e = y - u; % Error subplot(212) hist(e,20) gca.xlim = [min(x) max(x)]; title('Estimate of the PDF of the quantization error.') See Alsoerrmean | errvar | quantize × MATLAB Command You clicked a link that corresponds to this MATLAB command: Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands. Close Was this topic helpful? × Select Your Country Choose your country to get translated content where available and see local events and offers. Based on your location, we recommend that you select: . You can also select a location from the following list: Americas Canada (English) United States (English) Europe Belgium (English) Denmark (English) Deutschland (Deutsch) España (Español) Finland (English) France (Français) Ireland (English) Italia (Italiano) Luxembourg (English) Netherlands (English) Norway (English) Österreich (Deutsch) Portugal (English) Sweden (English) Switzerland Deutsch Français United Kingdom (English) Asia Pacific Australia (English) India (English) New Zealand (English) ä¸å›½ (简体ä¸æ–‡) 日本 (日本èª
very similar. As the number of bits increased, so did the SQNR as we would expect. The graphs and the results http://dluong1.bol.ucla.edu/swarthmore/e71/lab3/lab3.htm in the table are generated using the Matlab script. Note: X denotes the original signal and xd is the quantized signal for all graphs in this lab. Bits Experimental SQNR (dB) Theoretical SQNR (dB) Mean Quantization Noise Variance in Quantization Noise 4 26.201 25.84 2.89E-02 1.20E-03 8 49.7767 49.92 1.98E-03 5.17E-06 12 74.8614 74.00 1.07E-04 quantization error 1.63E-08 16 98.0608 98.08 7.59E-06 7.85E-11 t=0:0.1:4*pi; fprintf('Exp\t\tTh\t\tMean\t\tVar\n'); for n=4:4:16, x=sin(t); xd=round(x*2^(n-1))/2^(n-1); error=xd-x; error_mean=mean(abs(error)); error_variance=var(error); figure; plot(t,x,t,xd,t,error) legend('x','xd','error') SQNR=10*log10(sum(x.^2)/sum(error.^2)); SQNR_eqn=1.76+6.02*n; title(strcat(num2str(n),' bits. SQNR=',num2str(SQNR),' dB.')) fprintf('%0.4f\t%0.4f\t%0.3e\t%0.3e\n',SQNR,SQNR_eqn,error_mean,error_variance); end 2. Quantization of Sinusoidal Signal (truncating to integer bit) The experimental SQNR was always lower than the theoretical plot quantization error value. This was expected because instead of rounding the data as in part 1, we truncated, which leads to less accurate quantization of the signal and a lower SQNR. Bits Experimental SQNR (dB) Theoretical SQNR (dB) Mean Quantization Noise Variance in Quantization Noise 4 19.3759 25.84 6.54E-02 1.49E-03 8 44.0569 49.92 3.82E-03 5.06E-06 12 68.1629 74 2.29E-04 2.38E-08 16 91.9115 98.08 1.56E-05 7.97E-11 t=0:0.1:4*pi; fprintf('Exp\t\tTh\t\tMean\t\tVar\n'); for n=4:4:16, x=sin(t); xd=floor(x*2^(n-1))/2^(n-1); error=xd-x; error_mean=mean(abs(error)); error_variance=var(error); figure; plot(t,x,t,xd,t,error) legend('x','xd','error') SQNR=10*log10(sum(x.^2)/sum(error.^2)); SQNR_eqn=1.76+6.02*n; title(strcat(num2str(n),' bits. SQNR=',num2str(SQNR),' dB.')) fprintf('%0.4f\t%0.4f\t%0.3e\t%0.3e\n',SQNR,SQNR_eqn,error_mean,error_variance); end 3. Quantization of Gaussian Noise Signal As expected, the SQNR tends to increase with the number of bits used to quantize the signal. Bits Experimental SQNR (dB) Mean Quantization Noise Variance in Quantization Noise 4 29.1933 3.22E-02 1.34E-03 8 52.0926 1.86E-03 4.82E-06 12 77.1105 1.23E-04 1.99E-08 16 101.1026 7.33E-06 7.52E-11 t=0:0.1:4*pi; fprintf('Exp\t\tTh\t\tMean\t\tVar\n'); for n=4:4:16, x=randn(1,length(t)); xd=round(x*2^(n-1))/2^(n-1); error=xd-x; error_mean=mean(abs(error)); error_variance=var(error); figure; plot(t,x,t,xd,t,error) legend('x','xd
be down. Please try the request again. Your cache administrator is webmaster. Generated Mon, 24 Oct 2016 06:54:49 GMT by s_wx1062 (squid/3.5.20)