matlab snr,matlab算adc的snr等动态参数时出错。请懂的帮忙看一下

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?注册

x

之前没接触过matlab,现在做完adc要测参数就很头疼了。在论坛里找了个matlab代码。应该是结合美信的代码写的。仿snr,SINAD,SFDR等参数需要1024个点,但时间太长,就用17个点来试一下,matlab代码可行性。出错在65行,红色位置。错误为:

错误.png (4.66 KB, 下载次数:

45)

2015-4-14 22:19 上传

请大神指导。

付美信错误段代码,看着是一样的,为什么会出错呢。

美信代码.png (56.67 KB, 下载次数:

47)

2015-4-14 22:22 上传

代码为:

[size=12.380952835083px]clear

[size=12.380952835083px]load C:\Users\Administrator\Desktop\verilog3.txt    %WaveScan保存的波形文件,文件必须以英文开头

[size=12.380952835083px]A= verilog3;         %将测量数据赋给A,此时A为N×2的数组

[size=12.380952835083px]x=A(:,1);                     %将A中的第一列赋值给x,形成时间序列

[size=12.380952835083px]x=x';                         %将列向量变成行向量

[size=12.380952835083px]y=A(:,2);                     %将A中的第二列赋值给y,形成被测量序列

[size=12.380952835083px]y=y';                         %将列向量变成行向量

[size=12.380952835083px]%显示原始数据曲线图(时域)

[size=12.380952835083px]subplot(1,1,1);

[size=12.380952835083px]plot(x,y) ;                                                                               %显示原始数据曲线图

[size=12.380952835083px]xlabel('时间 (s)');

[size=12.380952835083px]ylabel('被测变量y');

[size=12.380952835083px]title('原始信号(时域)');

[size=12.380952835083px]grid on;

[size=12.380952835083px]format long;

[size=12.380952835083px]%傅立叶变换

[size=12.380952835083px]y=y-mean(y);                          %消去直流分量,使频谱更能体现有效信息

[size=12.380952835083px]fclk=(length(x)-1)/(max(x)-min(x));   %仪器的采样频率

[size=12.380952835083px]numpt=length(y);                      %data.txt中的被测量个数,即采样个数

[size=12.380952835083px]%If no window function is used, the input tone must be chosen to be unique and with

[size=12.380952835083px]%regard to the sampling frequency. To achieve this prime numbers are introduced and the

[size=12.380952835083px]%input tone is determined by fIN = fSAMPLE * (Prime Number / Data Record Size).

[size=12.380952835083px]%To relax this requirement, window functions such as HANNING and HAMING (see below) can

[size=12.380952835083px]%be introduced, however the fundamental in the resulting FFT spectrum appears 'sharper'

[size=12.380952835083px]%without the use of window functions.

[size=12.380952835083px]Doutw=y;

[size=12.380952835083px]%Doutw=y'.*hanning(numpt);

[size=12.380952835083px]%Doutw=y'.*hamming(numpt);

[size=12.380952835083px]%Performing the Fast Fourier Transform

[size=12.380952835083px]Dout_spect=fft(Doutw);

[size=12.380952835083px]%Recalculate to dB

[size=12.380952835083px]Dout_dB=20*log10(abs(Dout_spect));

[size=12.380952835083px]%Display the results in the frequency domAIn with an FFT plot

[size=12.380952835083px]figure; %建立图形

[size=12.380952835083px]maxdB=max(Dout_dB(1:numpt/2));

[size=12.380952835083px]%For TTIMD, use the following short routine, normalized to —6.5dB full-scale.

[size=12.380952835083px]%plot([0:numpt/2-1].*fclk/numpt,Dout_dB(1:numpt/2)-maxdB-6.5);

[size=12.380952835083px]%plot([0:30/2-1].*fclk/numpt,Dout_dB(1:30/2)-maxdB);

[size=12.380952835083px]plot([0:numpt/2-1].*fclk/numpt,Dout_dB(1:numpt/2)-maxdB);

[size=12.380952835083px]grid on;

[size=12.380952835083px]title('FFT PLOT');

[size=12.380952835083px]xlabel('Analog INPUT FREQUENCY (Hz)');

[size=12.380952835083px]ylabel('AMPLITUDE (dB)');

[size=12.380952835083px]a1=axis; axis([a1(1) a1(2) -120 a1(4)]);

[size=12.380952835083px]%Calculate SNR, SINAD, THD and SFDR values

[size=12.380952835083px]%Find the signal bin number, DC = bin 1

[size=12.380952835083px]fin=find(Dout_dB(1:numpt/2)==maxdB);

[size=12.380952835083px]%Span of the input frequency on each side

[size=12.380952835083px]span=max(round(numpt/200),5);%span=max(round(numpt/200),5);

[size=12.380952835083px]%Approximate search span for harmonics on each side

[size=12.380952835083px]spanh=2;%spanh=2;

[size=12.380952835083px]%Determine power spectrum

[size=12.380952835083px]spectP=(abs(Dout_spect)).*(abs(Dout_spect));

[size=12.380952835083px]%Find DC offset power

[size=12.380952835083px]Pdc=sum(spectP(1:span));

[size=12.380952835083px]%Extract overall signal power

[size=12.380952835083px]Ps=sum(spectP(fin-span:fin+span));

[size=12.380952835083px]%Vector/matrix to store both frequency and power of signal and harmonics

[size=12.380952835083px]Fh=[];

[size=12.380952835083px]%The 1st element in the vector/matrix represents the signal, the next element represents

[size=12.380952835083px]%the 2nd harmonic, etc.

[size=12.380952835083px]Ph=[];

[size=12.380952835083px]%Find harmonic frequencies and power components in the FFT spectrum

[size=12.380952835083px]for har_num=1:10 %har_num谐波总数

[size=12.380952835083px]%Input tones greater than fSAMPLE are aliased back into the spectrum

[size=12.380952835083px]tone=rem((har_num*(fin-1)+1)/numpt,1); %rem(x,y)x除以y的余数  numpt(Number of Points)

[size=12.380952835083px]if tone>0.5

[size=12.380952835083px]%Input tones greater than 0.5*fSAMPLE (after aliasing) are reflected

[size=12.380952835083px]tone=1-tone;

[size=12.380952835083px]end

[size=12.380952835083px]Fh=[Fh tone];

[size=12.380952835083px]%For this procedure to work, ensure the folded back high order harmonics do not overlap

[size=12.380952835083px]%with DC or signal or lower order harmonics

[size=12.380952835083px]%har_peak=max(spectP(round(tone*numpt)-spanh:round(tone*numpt)+spanh));

[size=12.380952835083px]%har_bin=find(spectP(round(tone*numpt)-spanh:round(tone*numpt)+spanh)==har_peak);

[size=12.380952835083px]%har_bin=har_bin+round(tone*numpt)-spanh-1;

[size=12.380952835083px]%Ph=[Ph sum(spectP(har_bin-1:har_bin+1))];

[size=12.380952835083px]Ph=[Ph sum(spectP(har_num*(fin-1):har_num*(fin-1)+2))];

[size=12.380952835083px]end

[size=12.380952835083px]%Determine the total distortion power

[size=12.380952835083px]Pd=sum(Ph(2:10)); %Pd总失真功率  Ph(1) is fundamental harmonic谐波 power

[size=12.380952835083px]%Determine the noise power

[size=12.380952835083px]Pn=sum(spectP(1:numpt/2))-Ps-Pd;  %Pn噪声功率  Ps信号功率

[size=12.380952835083px]format;%设置输出格式

[size=12.380952835083px]SNR = 10*log10(Ps/Pn)    %信噪比

[size=12.380952835083px]SINAD=10*log10(Ps/(Pn+Pd)) % SINAD = 10*log10(Ps/(Pn+Pd))  信号与噪声失真比

[size=12.380952835083px]disp('THD is calculated from 2nd through 10th order harmonics');

[size=12.380952835083px]SFDR=10*log10(Ph(1)/max(Ph(2:10)))  %SFDR无杂散动态范围

[size=12.380952835083px]ENOB = (SINAD-1.76)/6.02

[size=12.380952835083px]disp('Signal & Harmonic Power Components:');

[size=12.380952835083px]HD=10*log10(Ph(1:10)/Ph(1))

SNR代表信噪比(Signal-to-Noise Ratio),是衡量信号质量与噪声干扰程度之比的一个度量指标,用来衡量信号的清晰程度。ADC代表模拟到数字转换器(Analog-to-Digital Converter),即将模拟信号转换为数字信号的装置。 Matlab是一种常用的数学建模和数据分析软件,它具有强大的函数库和工具箱,非常适合进行信号处理的相关计和仿真。 在Matlab中,对于给定的信号,我们可以使用内置函数或者自定义函数来计SNR。一种常用的计方法是通过分析信号的功率和噪声的功率来计SNR值。首先,我们需要使用Matlab来计信号的功率,这可以通过对信号进行平方操作,并取平均值来得到。然后,我们需要计噪声的功率,可以通过对信号中除去信号本身外的部分进行平方操作,并取平均值来得到。最后,将信号的功率除以噪声的功率,即可得到SNR值。 对于ADC的相关处理,Matlab提供了一些函数和工具箱来进行模拟和仿真。我们可以使用Matlab来模拟和验证ADC的工作原理,以及对其进行分析和优化。Matlab提供了多种ADC模型,可以通过设置模拟信号的幅值范围、采样率和位数等参数来进行仿真,得到输出数字信号,进而进行相关的数据分析和处理。 总之,通过Matlab可以方便地进行信号处理和分析,包括计信噪比(SNR)以及模拟和优化模拟到数字转换器(ADC)等相关工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值