www.gusucode.com > signal 案例源码程序 matlab代码 > signal/SNROfSinusoidUsingPSDExample.m

    %% SNR of Sinusoid Using PSD
% Obtain the periodogram power spectral density (PSD) estimate of a 2.5 kHz
% sinusoid sampled at 48 kHz. Add white noise with standard deviation
% 0.00001. Use this value as input to determine the SNR. Set the random
% number generator to the default settings for reproducible results.

% Copyright 2015 The MathWorks, Inc.


%%

rng default
Fi = 2500;
Fs = 48e3;
N = 1024;
x = sin(2*pi*Fi/Fs*(1:N)) + 0.00001*randn(1,N);

w = kaiser(numel(x),38);
[Pxx, F] = periodogram(x,w,numel(x),Fs);
SNR = snr(Pxx,F,'psd')