|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
用如下fft代码跑仿真,我之前的数据就能跑通,但是现在数据加进去后,在运行到line22的"Ps = sum(pow_spec(fin-widm:fin+widm))"报错为:下标索引必须为正整数类型或逻辑类型。
同时工作区显示如附件。
d_len:1023 Pdc:2.0883
d_len2:511 power spec:1*511 double
fin:1 vout: 1*1023
widm:6 widmh: 2
求高手指教。
fft代码如下:
clear all;
load('vout.dat');
vout = vout(:,2);
vout = vout(1:length(vout)-1);
vout = rot90(vout);
d_len = length(vout);
vout = vout.*rot90(kaiser(d_len,18));
pow_spec = fft(vout).*conj(fft(vout));
pow_spec = pow_spec/max(pow_spec);
d_len2 = floor(d_len/2);
pow_spec = pow_spec(1:d_len2);
% find the signal bin number
fin = find(pow_spec(1:d_len2)==1);
% set the main lobe width of the input signal
widm = 6; %设置信号的主瓣宽度,主瓣的宽度=2*widm+1,对于整数个周期采样,令widm=0即可
widmh = 2; % 设置用于寻找谐波位置的范围
%*****************求直流失调功率**************************************
Pdc = sum(pow_spec(1:widm));
%*****************求信号总功率****************************************
Ps = sum(pow_spec(fin-widm:fin+widm));
% 定义谐波位置和大小的数组变量
Fh = []; Ph=[];
%*****************寻找谐波位置和其幅值********************************
for har_num=1:10
tone=rem((har_num*(fin-1)+1)/d_len, 1);
if tone>0.5 tone=1-tone; end
Fh = [Fh tone];
har_peak = max(pow_spec(round(tone*d_len)-widmh:round(tone*d_len)+widmh));
har_bin = find(pow_spec(round(tone*d_len)-widmh:round(tone*d_len)+widmh)==har_peak);
har_bin = har_bin+round(tone*d_len)-widmh-1;
Ph = [Ph sum(pow_spec(har_bin-1:har_bin+1))];
end
%*****************求总谐波失真功率********************************
Pd = sum(Ph(2:5));
%*****************求噪声功率********************************
Pn = sum(pow_spec)-Pdc-Ps-Pd;
%*****************求ADC动态指标**********************************
format;
SNDR = 10*log10(Ps/(Pn+Pd)) %求SNDR
SNR = 10*log10(Ps/Pn)
disp('THD is calculated from 2nd through 5th order harmonics');
THD = 10*log10(Pd/Ph(1))
SFDR = 10*log10(Ph(1)/max(Ph(2:10)))
disp('Signal & Harmonic Power Components:');
HD = 10*log10(Ph(1:10)/Ph(1))
%ENOB_EFF = (SNDR-20*log10(vpp)-1.76)/6.02 % 等效分辨率
ENOB = (SNDR-1.76)/6.02
%***************** 画出功率谱 *****************************************
xz = 0:1/d_lend_len2-1)/d_len; %这里的xz只是对X轴坐标进行了重新定义,在最终画功率谱图时将xz作为X轴的坐标
plot(xz,10*log10(pow_spec)) %画功率谱图,Y轴是对数刻度
%title('ADC Output Spectrum')
xlabel('fi/fs')
ylabel('Power (dB)')
axis([0,0.5,-120,0])
grid
|
-
|