SAR ADC系列4:SAR ADC简介+Matlab建模(7月11日更新版)

目录:
        SAR ADC工作原理
        SAR ADC工作过程
·       SAR ADC基本结构
        SAR ADC工作示例
        单端输入SAR ADC MATLAB 建模程序代码
        差分输入SAR ADC MATLAB 建模程序代码
        SAR ADC MATLAB 建模Sim
        SAR ADC 动态指标计算MATLAB程序代码
        SAR ADC 静态指标计算MATLAB程序代码


b5a67ad3939f49c6937b441db1acf140.png

 0b828a484d484ed69218430d5404cbb2.png

单端输入SAR ADC MATLAB 建模程序代码:

以下是一个单端输入SAR ADC MATLAB 建模程序代码,可使能输入Noise和电容Mismatch
(完整版代码看个人简介)

% ------------------------------------------------------
% Description:
%        This progran shows a Nbit-bit binary weighted SAR ADC behave model
%
% Input:
%    -Avin : the analog input signals
%           the magnitude of input signal should be [0,1]
%    -Nbit : ADC resulotion
%    -noise :When high,would add random gauss noise to input signal and 
% Output:
%    -Dout : Nbit-bit ADC quantization output data
% Author:
%    xsjkk
% Modified data:
%    2023-7-10 original version。
% ------------------------------------------------------

function [dout,cap_redunt] = sar_adc_ideal(Avin , Nbit , noise , mismatch)

%=======================================================
%            Check Input Variable
%=======================================================
if nargin <4 , mismatch = 0;  end   % mismatch默认值为0
if nargin <3 , noise    = 0;  end   % noise默认值为0
if nargin <2 , Nbit     = 12; end   % 默认12位
if nargin <1 , Avin     = []; end   % 默认无输入,必须要外加输入信号,一般是sin波

if isempty(Avin)
    error('No input signal')    % 检测有无输入信号
end

if (Nbit < 2)
    error('Increase ADC resolution')    % 检测位数
end

%=======================================================
%            Add Noise to Input Signal
%=======================================================
% When enabled, this function is uesed to model ADC noise, like refer-
% -buffer, comparator, etc
% Noise is confined within 2LSBs
if (noise ~=0)
    sprintf('Noise feature have been enabled');
%   Missing codes
else
    fprintf('noise feature is NOT enabled, \n');
end

%=======================================================
%            SAR ADC Modeling
%=======================================================
cap = zeros(1,Nbit);        % 根据位数确定reference的长度
for cnt = 1:Nbit
%   Missing codes
end
cap_redunt = cap;

%=======================================================
%            Add mismatch to Cap
%=======================================================
LSB = 1/2^Nbit;          % 定义LSB
%   Missing codes
cap_mis = zeros(1,Nbit);
for cnt = 1:Nbit
%   Missing codes
end
% adding mismatch to SAR ADC if this feature is enabled
if (mismatch ~= 0)
    cap_redunt = cap_redunt + cap_mis;
end

%=======================================================
%            SAR ADC A-D Conversion
%=======================================================
%Avin = Avin + cap_r/cap_shift;
dout = zeros(length(Avin),Nbit);
%therm = cumsum(cap_redunt(1:7));
for j = 1:length(Avin)  
%   Missing codes
end
%=========SAR ADC Model Finished=======================

差分输入SAR ADC MATLAB 建模程序代码:

以下是一个差分输入SAR ADC MATLAB 建模程序代码,可使能输入Noise和电容Mismatch
(完整版代码看个人简介)

% ------------------------------------------------------
% Description:
%        This progran shows a Nbit-bit binary weighted SAR ADC behave model-
%        -with Vcm-based switching
%        -and obtain SNDR,ENOB,SFDR for a given sine input
%
% Note: The pre-requisite for this function to work properly is coherent
% sampling - in other words, input must be integer number of input cycles.
%
% Perform FFT and plot the figure
%
% Author:
%    xsjkk
% Modified data:
%    2023-7-11 original version。
% ------------------------------------------------------

%%
clc;
clear;
N=5; % ADC resolution
M=10^6; % unit: M
n=10^-9; % unit: n
m=10^-6; % unit: m
num=2^14; % FFT number
vdd=1.2; % supply voltage
Vfs=1.2; % signal swing
Vref=1.2; % reference voltage
Vcm=Vref/2; % common mode voltage
%    Missing Code
% Version 1:Without Noise
Vin_p=Vfs/2+Missing Code
Vin_n=Vfs/2-Missing Code
% Verison 2:With Noise
%    Missing Code

%%
sig_c=0.001; % capacitor mismatch
C_arr_1=Missing Code
C_arr_2=Missing Code
C_dev_1=Missing Code
C_dev_2=Missing Code
%    Missing Code

%%
for j=1:num
    Vxp=Vin_p(j);
    Vxn=Vin_n(j);
for i=1:N-1
%    Missing Code
end
%    Missing Code

D(j,:)=B;
end

Dout= D*2.^[(N-1):-1:0]';

%%
%%%%%%  FFT calculation  %%%%%%%%%%%
numpt=length(Dout);
spect=fft(Dout);
dB1=20*log10(abs(spect));
%    Missing Code

figure;
set(gcf,'Units','centimeters','position',[25,10,15,8]);
%    Missing Code
grid on;
zoom;
% axis tight;
set(gca,'linewidth',2);
set(gca,'fontsize',14,'fontname','Times New Roman');
set(Q,'linewidth',1.5);
xlabel('ANALOG INPUT FREQUENCY (MHz)','fontsize',14,'fontname','Times New Roman'); 
ylabel('AMPLITUDE (dB)','fontsize',14,'fontname','Times New Roman'); 
a1=axis;

%%
% 找出输入频率并计算功率谱
%    Missing Code
span=0;%输入频谱范围
%    Missing Code
%%
%    Missing Code

%%
%求动态参数
%    Missing Code
SNDR=10*log10(Ps/(Psum-Ps));
ENOB=(SNDR-1.76)/6.02;

%%
text(a1(2)/5,a1(3)/5, sprintf('SFDR=%3.2fdB\nSNDR=%3.2fdB\nENOB=%3.2fbit@%3.4fMHz',...
   SFDR,SNDR,ENOB,fin),...
    'EdgeColor','black','LineWidth',2,'fontsize',14,'BackgroundColor',...
      [1 1 1],'Margin',5,'fontname','Times New Roman');




SAR ADC MATLAB 建模Sim:

(7.12日先欠着,睡觉了,下次更新)

99aece8a5f784b408786c1297bd25a87.png

d44237c96d5a4dd895436845de3ac745.png

Matlab2019版本之后带一个SARADC的模型,理想的性能。

 

 

 

 

 

 

 

SAR ADC 动态指标计算MATLAB程序代码:

上文的差分SAR ADC中已经涉及到了,下面再给出两种方法:
(同样完整代码看个人简介)

clear;clc;
N = 1024;
M = 37;
fin = 1e6;

fs = N*fin/M;
Ts = 1/fs;
%    Missing Code
LSB = 2/2^10;
vin = sin(2*pi*fin*t);
%    Missing Codes
figure(1);
plot(t,vin);

s = fft(vin);
s = abs(s) + 1e-6;
s_dB = 20*log10(s);
%    Missing Code
figure(2);
%    Missing Code
plot(1:N/2,s_dB);

% 计算SNR
%    Missing Code
power_sig = s(sig_bin);
power_noise = sum(s) - power_sig;
snr = 10*log10(power_sig/power_noise)
clear
close all
%-----------生成测试文本-------------%
%---------- 用仿真输出文本取代---------------%
% fs = 1E6;  %采样率
% fsig = 10E3; %信号频率
% ts = 1E-3; %仿真时间
% snr = 1E3;
%     Missing Codes
% noise_source = randn(1,Ns);  %噪声源
%     Missing Codes
% fid1=fopen('E:\sin_wave.txt','w');                                                  
% count=fprintf(fid1,' %f \n',wave);     
% plot (tsim,wave)
% fclose(fid1);
%--------------------------------------------------------%


result = importdata('E:\sin_wave.txt'); %ADC仿真路径下结果
figure(1);
plot(result);
% result = result(11:138);
d_len = length(result);
%     Missing Codes

%***************** 画出功率谱 **************************************
%     Missing Codes
figure(2);
plot(xz,10*log10(pow_spec)) %画功率谱图,Y轴是对数刻度
title('ADC Output Spectrum') 
xlabel('fi/fs')
ylabel('Power (dB)')
axis([0,0.5,-120,0])
grid
%***************** 求SNDR *****************************************
%     Missing Codes
sndr = 10*log10(ps/(sum(pow_spec)-ps))  %求SNDR
%***************** 求SFDR *****************************************
%     Missing Codes
sfdr = -10*log10(max(pow_spec))   %现在SFDR就是最大的杂波幅度了




SAR ADC 静态指标计算MATLAB程序代码:

太晚了,明天更。

PS:

88e59d758bdb4fb884eb272307d3c31c.png

一般,动态性能和静态性能不同时测,因为:动态性能测试时—>想要动态性能好,就不能满量程输入;而静态性能测试时—>想要不缺码,就需要超量程输入。

校准:

82f0f3a1bd6e4bc5b663fbfdfa52ffba.png  0594994c09164c649b3da2092be7069e.png

校准前的INLDNL,可以看到DNL和INL0有好多超过0.5LSB的,INL还有超过1的。校准之后好很多

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 14
    点赞
  • 92
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
SAR ADC (Successive Approximation Register Analog-to-Digital Converter) 是一种常用的模数转换器电路,可以将模拟电压信号转换为数字信号。在MATLAB建模SAR ADC可以遵循以下步骤: 1. 确定采样率和位数:根据需要的转换精度和采样频率确定ADC的位数和采样率。比如,可以选择12位的ADC和10MHz的采样率。 2. 建立模拟输入:使用MATLAB的信号生成函数,通过产生要转换的模拟电压信号。可以选择常见的信号类型,例如正弦波、方波或随机信号。 3. 设计SAR ADC的数字控制逻辑:SAR ADC使用逐次逼近的过程来估计输入电压。在MATLAB中,可以使用逻辑编程语言设计SAR ADC的数字控制逻辑,实现逐位逼近逻辑。 4. 设计比较器和D/A转换器:SAR ADC需要比较器和数字/模拟转换器(D/A Converter),以便在逐次逼近过程中进行比较和更新。MATLAB提供了各种比较器和D/A转换器的建模函数,可以根据需求选择适当的组件。 5. 模拟ADC性能:通过MATLAB的仿真工具,可以模拟SAR ADC的性能指标,如信噪比(SNR)、总谐波失真(THD)和有效位数(ENOB)。通过调整ADC的设计参数,优化性能。 6. 分析和优化:根据模拟结果,分析ADC的性能不足,并根据需要对电路进行优化。可以尝试改变采样时钟频率、增加比较器精度或改善电源噪声抑制等方法。 总之,通过遵循以上步骤,可以在MATLAB建模SAR ADC电路,并通过仿真分析和优化,得出设计参数和性能指标,以满足实际应用的要求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小生就看看

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值