在雙精度浮點中建立表
號令行鍵入:
N = 256;
angle = 2*pi * (0:(N-1))/N;
s = sin( angle )';
thd_ref_1 = ssinthd( s, 1, N, 1, 'direct' )
thd_ref_2p5 = ssinthd( s, 5/2, 2*N, 5, 'linear' )
cs = cordicsin( angle, 50 )';
thd_ref_1c = ssinthd(cs, 1, N, 1, 'direct' )
thd_ref_2p5c = ssinthd(cs, 5/2, 2*N, 5, 'linear' )
如圖1所示。
 將正弦波近似應用于模子中
號令行鍵入:
open_system('sldemo_tonegen');
set_param('sldemo_tonegen', 'StopFcn','');
sim('sldemo_tonegen');
currentFig = figure('Color',[1,1,1]);
subplot(3,1,1), plot(tonegenOut.time, tonegenOut.signals(1).values); grid
title('Difference between direct look-up and reference signal');
subplot(3,1,2), plot(tonegenOut.time, tonegenOut.signals(2).values); grid
title('Difference between interpolated look-up and reference signal');
subplot(3,1,3), plot(tonegenOut.time, tonegenOut.signals(3).values); grid
title('Difference between CORDIC sine and reference signal');
如圖2所示。
 運行這個模子。
如圖3所示。
 細心不雅察波形精度
號令行鍵入:
ax = get(currentFig,'Children');
set(ax(3),'xlim',[4.8, 5.2])
set(ax(2),'xlim',[4.8, 5.2])
set(ax(1),'xlim',[4.8, 5.2])
如圖4所示。
 統一表,固定點實現
號令行鍵入:
bits = 24;
is = num2fixpt( s, sfrac(bits), [], 'Nearest', 'on');
thd_direct1 = ssinthd(is, 1, N, 1, 'direct')
thd_direct2 = ssinthd(is, 2, N, 2, 'direct')
thd_direct3 = ssinthd(is, 3, N, 3, 'direct')
thd_linterp_2p5 = ssinthd(is, 5/2, 2*N, 5, 'fixptlinear')
如圖5所示。
 比力分歧表格和方式的成果
號令行鍵入:
thd_double_direct = ssinthd( s, 33/4, 4*N, 33, 'direct')
thd_sfrac24_direct = ssinthd(is, 33/4, 4*N, 33, 'direct')
thd_double_linear = ssinthd( s, 33/4, 4*N, 33, 'linear')
thd_sfrac24_linear = ssinthd(is, 33/4, 4*N, 33, 'fixptlinear')
如圖6所示。
 利用預先設置裝備擺設的正弦波塊
號令行鍵入:
open_system('sldemo_tonegen_fixpt');
set_param('sldemo_tonegen_fixpt', 'StopFcn','');
sim('sldemo_tonegen_fixpt');
figure('Color',[1,1,1]);
subplot(3,1,1), plot(tonegenOut.time, tonegenOut.signals(1).values); grid
title('Difference between direct look-up and reference signal');
subplot(3,1,2), plot(tonegenOut.time, tonegenOut.signals(2).values); grid
title('Difference between interpolated look-up and reference signal');
subplot(3,1,3), plot(tonegenOut.time, tonegenOut.signals(3).values); grid
title('Difference between CORDIC sine and reference signal');
如圖7、8所示。
 
 帶時鐘輸入的正弦函數的利用
號令行鍵入:
subplot(1,1,1), plot(tonegenOut.time, tonegenOut.signals(4).values); grid
title('Difference between time based sin() and reference signal');
如圖9所示。
 直接查找和線性插值的行為綜述
號令行鍵入:
figure('Color',[1,1,1])
tic, sldemo_sweeptable_thd(24, 256), toc
如圖10所示。
 END0 篇文章
如果覺得我的文章對您有用,請隨意打賞。你的支持將鼓勵我繼續創作!