matlab定点化的作用,【请教】HDL的matlab定点化算法仿真怎么做?

如果theta是固定的话,可以先用matlab生成一个表,然后查表就可以了。如果每次用到 floor( theta/unit )  * unit都需要计算的话可能比较慢。或者你可以这样考虑,不是每一步都需要把数这样处理,干脆整数化,最后在乘以相应的Scaling. 以下就是一个NCO的例子,里面的变量都整数化了。

% Phase Truncation DDS

clear;clc;

% declare parameter for phase accumulator

fclk = 100e6;

phase_depth = 32;

fout = 20e6;

% declare parameter for lookup table

table_depth = 16;

output_precision = 16;

% phase increment calculation

phase_inc = fout*2^phase_depth/fclk;

phase_inc = floor(phase_inc);

actual_freq = phase_inc*fclk/2^phase_depth;

fprintf('For output frequcecy = %d Hz\n',fout);

fprintf('With clock frequcecy = %d Hz\n',fclk);

fprintf('With phase bit width = %d bit\n',phase_depth);

fprintf('Phase inc value is   = %d\n',phase_inc);

fprintf('Aactual frequency is = %d\n',actual_freq);

% build lookup table

N = 2^table_depth;

t = (0:N-1)*2*pi/N;

% sine/cosine calculation

cos_lut = cos(t);

sin_lut = sin(t);

% output scaling

lut_max = 2^(output_precision-1) - 1;

lut_min =-2^(output_precision-1) + 1;

cos_lut = round(cos_lut*2^(output_precision-1));

cos_lut(cos_lut>lut_max) = lut_max;

cos_lut(cos_lut

sin_lut = round(sin_lut*2^(output_precision-1));

sin_lut(sin_lut>lut_max) = lut_max;

cos_lut(cos_lut

% phase accumulator

M = 2^phase_depth;

acc = 0;

num_of_sample = 2^14; % number of samples

l = zeros(1,num_of_sample);

for i = 1:num_of_sample

acc = acc + phase_inc;

l(i) = mod(acc,M);

end

% phase quantization

l = floor(l./2^(phase_depth-table_depth)) + 1;

% sine/cosine output

cos_out = cos_lut(l);

sin_out = sin_lut(l);

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值