⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nco_evaluate.m

📁 利用FPGA实现的DDS
💻 M
字号:
%================================================================
%	nco_evaluate.m is a program that evaluate rom sin output using FFT
%	Copyright :blutea 2004_10_20
%   vionsion:  1.0
%================================================================
%   function nco_evaout=evalu(n,m,FREQWORD,PHASEWORD)

freqword= 1 *2^24 + 0*2^16 + 0*2^8 + 0;
phaseword=16;
nco_out=ncosinwave(6,7);
accum=0;
testnum=1024;
romout=zeros(1,testnum);

for k=1:testnum;
%-------------频率累加 ---------------------------       
    accum=accum+freqword;
    if accum>2^32 
        accum=accum-2^32;
    else
        accum=accum;
    end
%-------------加调制相位 ---------------------------
    modaccum=accum+phaseword*2^24;
    if modaccum>2^32 
        modaccum=modaccum-2^32;
    else
        modaccum=modaccum;
    end
 %-------------求频率累加高8位的值----------------- 
    leftbit=modaccum;
    high8bit=zeros(1,8);   
    for i=1:8;
        high8bit(9-i)=fix(leftbit/2^(32-i));
        leftbit=mod(leftbit,2^(32-i));
    end;
%-------------求ROM中正弦的查表地址-----------------       
    address= high8bit(6)*2^5 + high8bit(5)*2^4 ...
            +high8bit(4)*2^3 + high8bit(3)*2^2 ...
            +high8bit(2)*2^1 + high8bit(1)*2^0;
%-------------输出正弦波形-----------------           
    if  high8bit(7)==0
        if  high8bit(8)==0
            romout(k)=nco_out(address+1);
        else
            romout(k)=-nco_out(address+1);
        end
    else
        if  high8bit(8)==0
            romout(k)=nco_out(2^6-address);
        else
            romout(k)=-nco_out(2^6-address);    
        end
    end
end

%---------用FFT分析动态范围---------
plotin=romout;
figure(102);
subplot(2,1,1),plot(plotin);grid on
title('nco time analyse');
xlabel('time ');
fft_num=testnum;
nco_fft =fft(plotin,fft_num);
nco_fft =nco_fft(1:fft_num/2);
nco_fft = abs(nco_fft);
nco_fft=20*log10(nco_fft+1e-4);%由于nco_out的对称性FFT后隔一位产生一个0
subplot(2,1,2),plot(nco_fft);grid on
title('Frequency content of nco');
xlabel('frequency');
ylabel('Magtitude(dB)');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -