Obtain SNR for a flat spectrum

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')

Réponses (1)

Tony Tse
Tony Tse le 30 Sep 2018

0 votes

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')

Catégories

En savoir plus sur Read, Write, and Modify Image dans Centre d'aide et File Exchange

Produits

Version

R2018a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by