输出信噪比计算
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
function snr_vec = fftdisto(x, C, varargin)
% FFTDISTO compute distortion of sinusoidal signal
% SNR_VEC = FFTDISTO(X,C,N)
% input:
% x signal vector
% C number of full sinusoids in X
% N length of signal to consider (must be a power of 2)
% only N last samples in x are used in fft
% output vector:
% 1 pwr signal power [dB] (amplitude 1 --> 0dB)
% 2 sndr signal-to-noise+distortion ratio (DC omitted) [dB]
% 3 snr only uncorrelated noise (harmonics + DC omitted) [dB]
% 4 sdr signal-to-distortion (only harmonics, noise+DC omitted) [dB] % 5 tdh total harmonic distortion [%]
% NOTE: make N > 6 * C -->
% considers only approx. first N/2C harmonics,
% rest are treated as noise
if nargin > 3
fprintf('nargin = %d\n', nargin)
error('Too many arguments.');
end
N = length(x);
if nargin == 3
if varargin{1} > N
error('N exceeds length(x)');
end
lenx = N;
N = varargin{1};
if lenx > N
x(1:(lenx-N)) = [];
end
end
N2 = 0.5 * N;
if log2(N2) ~= round(log2(N2))
error('N must be power of 2');
end
if C > N2
error('C > N/2 (signal frequency > sampling frequency');
end
if N < 6*C
% warning('computing less than 3 harmonics!');
end
a = abs(fft(x))/N2; % amplitude vector
p = a .* a; % power vector
dc = 1; % index of DC component
sig = C+1; % index of signal
harm = (2*C+1):C:N2; % indices of harmonics
noise= 1:N2; noise([ dc sig harm ]) = [];
% indices of noise
sp = p(sig) + 1e-100; % signal power
dp = sum(p(harm)) + 1e-100; % distortion power
np = sum(p(noise)) + 1e-100; % noise power (not including distortion)
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);
snr_vec(5) = 100*sqrt(dp/sp);
matlab中的信噪比
(2011-03-22 19:52:49)
分类:学习
标签:
信噪比
杂谈
以高斯噪声为例:若有用信号s(n)的最大幅度am,要求得到的信噪比为p,则p=10log10[(am^2)/b^2],用这个公式反推出高斯噪声的方差b^2,若s(n)单通道实信号,则Matlab程序就是x=s+b*randn(size(s));若s(n)是正交双通道信号,则Matlab程序就是
x=s+b/sqrt(2)*randn(size(s))。
如果s(n)是一个N行、2列的复信号,前后两列各表示实部和虚部,则b/sqrt(2)*randn(size(s))产生的也是N×2的高斯分布噪声,实部和虚部的方差均为
b/sqrt(2)。实部和虚部分别产生也可以,但不能用
b*randn(size(s))。第一,如果这样产生噪声,那么最终信号的信噪比应该用
p=10log10[(am^2)/(2*b^2)];第二,不能用size(s),应该用size(c),c为s(n)的实(虚)部列矢量的长度。
Matlab中计算信噪比方式:
%===========================Happy===== ==============================%
function snr=SNR(I,In)
% 计算信号噪声比函数
% by Qulei
% I :original signal
% In:noisy signal(ie. Original signal + noise signal)
% snr=10*log10(sigma2(I2)/sigma2(I2-I1))
[row,col,nchannel]=size(I);