Obtain SNR for a flat spectrum

3 次查看(过去 30 天)
Tony Tse
Tony Tse 2018-9-28
回答: Tony Tse 2018-9-30
Hello,
I am trying to construct a power spectrum given a SNR and use Matlab's in-built function SNR (or SINAD) to verify this. It seems that Matlab has issue picking the fundamental power.
I have attached a sample code to demonstrate my problem. How can I get around this?
Thanks.
% check matlab function to obtain snr
sNRdB = 64;
sampleFreq = 16e6;
% generate frequency
fxx = 0:500:sampleFreq/2;
signalP = 1;
% calculate noise power from snr figure
noiseP = signalP/(10^(sNRdB/10));
% assume flat noise power density
noisePD = noiseP/(sampleFreq/2);
% populate spectrum
pxx = ones(1, length(fxx))*noisePD;
% assume signal is at fxx(10000);
pxx(10000) = 1;
figure(1);
sinad(pxx', fxx', 'psd') % or snr
% trick matlab?
pxx(10000-1) = pxx(10000-1) - eps;
pxx(10000+1) = pxx(10000+1) - eps;
figure(2);
sinad(pxx', fxx', 'psd')

回答(1 个)

Tony Tse
Tony Tse 2018-9-30
Just to answer my own question, turned out I needed to divide the signal power by the frequency width. Silly me! Still need to perform the little "trick" to make sure Matlab selects the right signal/noise frequency.
% check matlab function to obtain snr
sNRdB = 64;
sampleFreq = 16e6;
% generate frequency
fxx = 0:500:sampleFreq/2;
signalP = 1;
% populate spectrum with noise
noiseP = signalP/(10^(sNRdB/10)); % calculate noise power from snr figure
noisePD = noiseP/(sampleFreq/2); % noise power density
pxx = ones(1, length(fxx))*noisePD;
% populate spectrum with signal
signalPD = signalP/mean(diff(fxx));
sigFreq = round(length(fxx)/2);
pxx(sigFreq) = signalPD; % assume signal is in the middle of the fxx;
% matlab sinad
figure(1);
sinad(pxx', fxx', 'psd') % or snr
% trick matlab sinad?
pxx(2) = pxx(2) - eps;
pxx(sigFreq-1) = pxx(sigFreq-1) - eps;
pxx(sigFreq+1) = pxx(sigFreq+1) - eps;
figure(2);
sinad(pxx', fxx', 'psd')

类别

Help CenterFile Exchange 中查找有关 Parametric Spectral Estimation 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by