|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
x
data_adc=importdata('rlc2_6.txt');
N=8192/2;
dynamic_data=data_adc(1:N,6);
data_size=size(dynamic_data);
N=max(data_size);
% sample_number=input('输入采样点数:');
% if sample_number>N
% display('样本数据数量不够,请检查')
% else data=dynamic_data(1:sample_number);
% N=sample_number;//N
% F_samples=input('输入采样频率:');
F_samples=100e6;
Mean_code=mean(dynamic_data);
V=dynamic_data-Mean_code;
V=V.*hanning(N);
dout_spect=fft(V);
dout_dB=20*log10(abs(dout_spect));
max_dB=max(dout_dB(1:N/2));
x=(0:N/2-1).*F_samples/N;
y=dout_dB(1:N/2)-max_dB;
figure(1)
plot(x,y);
axis([0,F_samples/2,-120,0]);
grid off;
title('FFT图');
xlabel('模拟输入频率(Hz)');
ylabel('幅值(dB)');%fft
F_in=find(dout_dB(1:N/2)==max_dB);%find the point corresponding max_dB
span=max(round(N/200),2);
spanh=2;
spectp=(abs(dout_spect)).*(abs(dout_spect));
Pdc=sum(spectp(1:span));
Ps=sum(spectp(F_in-span:F_in+span));
F_harmonic=[];
P_harmonic=[];
for har_number=1:10
tone=rem((har_number*(F_in-1)+1)/N,1);
if tone>0.5
tone=1-tone;
end
F_harmonic=[F_harmonic tone];
har_peak=max(spectp(round(tone*N)-spanh:round(tone*N)+spanh));
har_bin=find(spectp(round(tone*N)-spanh:round(tone*N)+spanh)==har_peak);
har_bin=har_bin+round(tone*N)-spanh-1;
P_harmonic=[P_harmonic sum(spectp(har_bin-1:har_bin+1))];
end
disp(F_harmonic);
disp(P_harmonic);
Pd=sum(P_harmonic(2:5));
Pn=sum(spectp(1:N/2))-Pdc-Ps-Pd;
format;
SNR=10*log10(Ps/Pn);
SINAD=10*log10(Ps/(Pn+Pd));
SFDR=10*log10(P_harmonic(1)/max(P_harmonic(2:10)));
THD=10*log10(Pd/P_harmonic(1));
ENOB=(SINAD-1.76)/6.02;
A=[SNR,SINAD,SFDR,THD,ENOB]
% xlswrite('D:\major_design9.1\PD_adjust_filter6_sopc530_add3M\data\data.xlsx',A,'sheet2','B6:F6');
程序是下载的,为什么会有’索引超出矩阵维度‘的错误。 |
|