dds_matlab.m

来自「这里的DDS(直接数字合成)是我在MATLAB中用Simulink基本模块搭建起」· M 代码 · 共 44 行

M
44
字号
function [y,t]=dds_matlab(fout,Fs,Bits,endtime)
% DDS_MATLAB function to generate the DDS sine wave
% in MATLAB language;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   [y,t]=dds_matlab(fout,Fs,Bits,endtime)        %
%   fout      :   Output frequency                %  
%   Fs        :   Sample frequency                %  
%   Bits      :   Number of bits of the LUT       %  
%   endtime   :   Expected simulation endtime     %  
%   y         :   Output sine wave                %
%   t         :   Output time                     %  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Output some infomation
delta_F=Fs/2^Bits;
disp(['The frequency resolution of this DDS is:'...
    ,num2str(delta_F),'Hz']);
disp(['Output frequencies are:0Hz,',num2str(delta_F),'Hz,'...
    num2str(2*delta_F),'Hz,......,',num2str(Fs/2),'Hz']);
% Construct the Sine Wave LUT store in array LUT
t=2*pi*(0:2^Bits-1)/2^Bits;
LUT=sin(t);

t=0:1/Fs:endtime;
N=length(t);
n=1;
y=zeros(1,N);
IND=zeros(1,N);
% Input Frequency Word
k=floor(fout/Fs*2^Bits);
index=0;

while n<=N
    IND(n)=index;
    index=index+k;
    index=mod(index,2^Bits);
    n=n+1;
end
IND=IND+1;
y=LUT(IND);
plot(t,y);
figure(1);
axis([0 endtime -1.2 1.2]);
grid on

⌨️ 快捷键说明

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