码迷,mamicode.com
首页 > 其他好文 > 详细

《DSP using MATLAB》示例Example 6.27

时间:2017-03-23 20:48:34      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:技术   lin   printf   image   plot   idt   example   abs   class   

技术分享

代码:

% 
r = 0.9; theta = (pi/180)*[-55:5:-35, 35:5:55]‘;
p = r*exp(j*theta); a = poly(p); b = 1;
w = [0:500]*pi/500; H = freqz(b*1e-4, a, w);
magH = abs(H); magHdb = 20*log10(magH);

% Direct form: quantized coefficients
N = 15; [ahat, L, B] = QCoeff(a, N);
TITLE = sprintf(‘%i-bit (1+%i+%i) Precision (DF)‘, N+1, L, B);
Hhat = freqz(b*1e-4, ahat, w); magHhat = abs(Hhat);

% Cascade form: quantized coefficients: Same N
[b0, B0, A0] = dir2cas(b, a); [BAhat1, L1, B1] = QCoeff([B0, A0], N);
TITLE1 = sprintf(‘%i-bit (1+%i+%i) Precision (CF)‘, N+1, L1, B1);
Bhat1 = BAhat1(:, 1:3); Ahat1 = BAhat1(:, 4:6);
[bhat1, ahat1] = cas2dir(b0, Bhat1, Ahat1);
Hhat1 = freqz(b*1e-4, ahat1, w); magHhat1 = abs(Hhat1);

% Cascade fomr: quantized coefficients: Same B (N=L1+B)
N1 = L1 + B; [BAhat2, L2, B2] = QCoeff([B0, A0], N1);
TITLE2 = sprintf(‘%i-bit (1+%i+%i) Precision (CF)‘, N1+1, L2, B2);
Bhat2 = BAhat2(:, 1:3); Ahat2 = BAhat2(:, 4:6);
[bhat2, ahat2] = cas2dir(b0, Bhat2, Ahat2);
Hhat2 = freqz(b*1e-4, ahat2, w); magHhat2 = abs(Hhat2);


% Comparison of Magnitude Plots
Hf_1 = figure(‘paperunits‘, ‘inches‘, ‘paperposition‘, [0, 0, 6, 4]);
%figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘Exameple 6.26a‘)
set(gcf,‘Color‘,‘white‘);

subplot(2, 2, 1); plot(w/pi, magH, ‘g‘, ‘linewidth‘, 2); axis([0, 1, 0, 0.7]);
xlabel(‘Digital Frequency in \pi units‘, ‘fontsize‘, 10);
ylabel(‘Magnitude Response‘, ‘fontsize‘, 10); grid on;
title(‘Infinite Precision (DF)‘, ‘fontsize‘, 10, ‘fontweight‘, ‘bold‘);

subplot(2, 2, 2); plot(w/pi, magHhat, ‘r‘, ‘linewidth‘, 2); axis([0, 1, 0, 0.7]);
xlabel(‘Digital Frequency in \pi units‘, ‘fontsize‘, 10);
ylabel(‘Magnitude Response‘, ‘fontsize‘, 10); grid on;
title(TITLE, ‘fontsize‘, 10, ‘fontweight‘, ‘bold‘);

subplot(2, 2, 3); plot(w/pi, magHhat1, ‘r‘, ‘linewidth‘, 2); axis([0, 1, 0, 0.7]);
xlabel(‘Digital Frequency in \pi units‘, ‘fontsize‘, 10);
ylabel(‘Magnitude Response‘, ‘fontsize‘, 10); grid on;
title(TITLE1, ‘fontsize‘, 10, ‘fontweight‘, ‘bold‘);

subplot(2, 2, 4); plot(w/pi, magHhat2, ‘r‘, ‘linewidth‘, 2); axis([0, 1, 0, 0.7]);
xlabel(‘Digital Frequency in \pi units‘, ‘fontsize‘, 10);
ylabel(‘Magnitude Response‘, ‘fontsize‘, 10); grid on;
title(TITLE2, ‘fontsize‘, 10, ‘fontweight‘, ‘bold‘);

 运行结果:

技术分享

 

《DSP using MATLAB》示例Example 6.27

标签:技术   lin   printf   image   plot   idt   example   abs   class   

原文地址:http://www.cnblogs.com/ky027wh-sx/p/6606691.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!