資源描述:
《輸出信噪比計(jì)算.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、functionsnr_vec=fftdisto(x,C,varargin)%FFTDISTOcomputedistortionofsinusoidalsignal%SNR_VEC=FFTDISTO(X,C,N)%input:%xsignalvector%CnumberoffullsinusoidsinX%Nlengthofsignaltoconsider(mustbeapowerof2)%onlyNlastsamplesinxareusedinfft%outputvector:%1pwrsignalpower[dB](ampli
2、tude1-->0dB)%2sndrsignal-to-noise+distortionratio(DComitted)[dB]%3snronlyuncorrelatednoise(harmonics+DComitted)[dB]%4sdrsignal-to-distortion(onlyharmonics,noise+DComitted)[dB]%5tdhtotalharmonicdistortion[%]%NOTE:makeN>6*C-->%considersonlyapprox.firstN/2Charmonics,%res
3、taretreatedasnoiseifnargin>3fprintf('nargin=%d',nargin)error('Toomanyarguments.');endN=length(x);ifnargin==3ifvarargin{1}>Nerror('Nexceedslength(x)');endlenx=N;N=varargin{1};iflenx>Nx(1:(lenx-N))=[];endendN2=0.5*N;iflog2(N2)~=round(log2(N2))error('Nmustbepowerof2');
4、endifC>N2error('C>N/2(signalfrequency>samplingfrequency');endifN<6*C%warning('computinglessthan3harmonics!');enda=abs(fft(x))/N2;%amplitudevectorp=a.*a;%powervectordc=1;%indexofDCcomponentsig=C+1;%indexofsignalharm=(2*C+1):C:N2;%indicesofharmonicsnoise=1:N2;noise([dcs
5、igharm])=[];%indicesofnoisesp=p(sig)+1e-100;%signalpowerdp=sum(p(harm))+1e-100;%distortionpowernp=sum(p(noise))+1e-100;%noisepower(notincludingdistortion)snr_vec=zeros(1,5);snr_vec(1)=dB10(sp);snr_vec(2)=dB10(sp/(np+dp));snr_vec(3)=dB10(sp/np);snr_vec(4)=dB10(sp/dp);s
6、nr_vec(5)=100*sqrt(dp/sp);matlab中的信噪比(2011-03-2219:52:49)標(biāo)簽:信噪比雜談分類:學(xué)習(xí)以高斯噪聲為例:若有用信號(hào)s(n)的最大幅度am,要求得到的信噪比為p,則p=10log10[(am^2)/b^2],用這個(gè)公式反推出高斯噪聲的方差b^2,若s(n)單通道實(shí)信號(hào),則Matlab程序就是x=s+b*randn(size(s));若s(n)是正交雙通道信號(hào),則Matlab程序就是x=s+b/sqrt(2)*randn(size(s))。如果s(n)是一個(gè)N行、2列的復(fù)信號(hào),前后兩
7、列各表示實(shí)部和虛部,則b/sqrt(2)*randn(size(s))產(chǎn)生的也是N×2的高斯分布噪聲,實(shí)部和虛部的方差均為b/sqrt(2)。實(shí)部和虛部分別產(chǎn)生也可以,但不能用b*randn(size(s))。第一,如果這樣產(chǎn)生噪聲,那么最終信號(hào)的信噪比應(yīng)該用p=10log10[(am^2)/(2*b^2)];第二,不能用size(s),應(yīng)該用size(c),c為s(n)的實(shí)(虛)部列矢量的長度。Matlab中計(jì)算信噪比方式:%===========================Happy====================
8、===============%functionsnr=SNR(I,In)%計(jì)算信號(hào)噪聲比函數(shù)%byQulei%I:originalsignal%In:noisysignal(ie.Originalsignal+noisesignal)%snr=1