MATLAB ADC 频谱分析问题
时间:10-02
整理:3721RD
点击:
一段做ADC频谱分析的程序,fft的结果出现了-inf,请大家看一下程序有什么问题。
clear;
afs = 1;% 1V full scale
fs = 1e6;%1MHz sample rate
N = 2^10;% number of samples
cyc = 67;
fx = fs*cyc/N;
t = linspace(0,(N-1)/fs,N);
y = afs*sin(2*pi*fx*t);
B = 10;% internal ADC resolution
delta = afs/2^B;
y = cos(2*pi*fx/fs*[0:N-1]);
%quantize samples to delta=1LSB
y=round(y/delta)*delta;
s = 20*log10(abs(fft(y)/N/afs*2));
s = s(1:N/2);% drop redundant half
f = (0:length(s)-1) / N;% frequency vector (normalized to fs)
figure(1);
plot(f,s);
grid on;
clear;
afs = 1;% 1V full scale
fs = 1e6;%1MHz sample rate
N = 2^10;% number of samples
cyc = 67;
fx = fs*cyc/N;
t = linspace(0,(N-1)/fs,N);
y = afs*sin(2*pi*fx*t);
B = 10;% internal ADC resolution
delta = afs/2^B;
y = cos(2*pi*fx/fs*[0:N-1]);
%quantize samples to delta=1LSB
y=round(y/delta)*delta;
s = 20*log10(abs(fft(y)/N/afs*2));
s = s(1:N/2);% drop redundant half
f = (0:length(s)-1) / N;% frequency vector (normalized to fs)
figure(1);
plot(f,s);
grid on;
出现inf是因为fft返回的结果里有很多0,为了避免对0求log,可以在中s = 20*log10(abs(fft(y)/N/afs*2));
加入一个无穷小量eps。也即写成 s = 20*log10( abs( fft( y ) / N / afs * 2+ eps ) );
谢谢回复!
确实是fft结果中有很多0,通过加入eps可以防止出现-inf。
追问:但是按理说对正弦信号量化后做fft不应该出现0吧?
量化时很多bin点上的值太小被round到0了,所以会出现fft返回0的情况
sdfwesdf
栏目分类
射频专业培训教程推荐