目录:
SAR ADC工作原理
SAR ADC工作过程
· SAR ADC基本结构
SAR ADC工作示例
单端输入SAR ADC MATLAB 建模程序代码
差分输入SAR ADC MATLAB 建模程序代码
SAR ADC MATLAB 建模Sim
SAR ADC 动态指标计算MATLAB程序代码
SAR ADC 静态指标计算MATLAB程序代码
单端输入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日先欠着,睡觉了,下次更新)
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:
一般,动态性能和静态性能不同时测,因为:动态性能测试时—>想要动态性能好,就不能满量程输入;而静态性能测试时—>想要不缺码,就需要超量程输入。
校准:
校准前的INLDNL,可以看到DNL和INL0有好多超过0.5LSB的,INL还有超过1的。校准之后好很多