|
楼主 |
发表于 2020-10-2 21:38:29
|
显示全部楼层
clear;
clc;
v_slope= xlsread('sh','B2:B301');
figure(1)
plot(v_slope);
a=max(v_slope);
b=min(v_slope);
% vslope_1=(v_slope-b)/(a-b)-0.5;
% vslope_1=v_slope-mean(v_slope);
vslope_1 = v_slope(20:300);
N=256;%FFT点数
spectrum = abs(fft(vslope_1(1:N)));
spectrum = 2/N/1*spectrum(1:N/2);
spectrumdb = 20*log10(spectrum+eps);% eps 防止对数为0
frequency = 1/N*(0:length(spectrumdb)-1);
[fund, fundidx] = max(spectrum);
a=spectrum(2:fundidx-1);
b=spectrum(fundidx+1:end);
tp1=b;
funddb=20*log10(fund);
spec_nodc_nofund = [spectrum(2:fundidx-1) ; spectrum(fundidx+1:end)];
[spur, spuridx] = max (spec_nodc_nofund);
sfdrdb = funddb-20*log10(spur);
tp2=norm(spec_nodc_nofund);
sndr = norm(fund)/norm(spec_nodc_nofund);
sndrdb=20*log10(sndr);
enob = (sndrdb-1.76)/6.02;
fclk = 5* 10^6; %采样频率
[spectrumdb_fin,fin_decision]=max(spectrumdb);%得到的信号频率幅度和在频率数组中的位置
fin=frequency(fin_decision);
fin=fclk*fin;
figure(2);
plot(frequency, spectrumdb, '*-', 'linewidth', 2);%hold on;
%string = sprintf('samplepoint=%0.4g, ENOB=%0.4g,SNDR=%0.4gdB, SFDR=%0.4gdB',N, enob,sndrdb, sfdrdb); %, Fundamental=%0.3gdBV,funddb
text(0.4,-25,sprintf('\\bfsamplepoint=%0.4g\nENOB=%0.4g\nSNDR=%0.4gdB\nSFDR=%0.4gdB\nFin=%3.6f MHz\nFclk=%3.0f MHz',N, enob, sndrdb, sfdrdb, fin/10^6, fclk/10^6),'FontAngle','normal','Fontsize',12,'edgecolor','r','LineWidth',3,'Margin',5,'BackgroundColor','w');
title('FFT PLOT');
xlabel('Frequency [f/fs] ');
ylabel('Amplitude [dBV]');
axis([0 0.5 -150 0]);
grid on;
%hold on; |
|