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

📄 dds_matlab.m

📁 这里的DDS(直接数字合成)是我在MATLAB中用Simulink基本模块搭建起来的模型,仿真DDS信号的产生,并有一个M文件实现与模型同等的功能,MATLAB爱好者一定不要错过
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -