MATLAB Answers

Obtain SNR for a flat spectrum

2 views (last 30 days)
Tony Tse
Tony Tse on 28 Sep 2018
Answered: Tony Tse on 30 Sep 2018
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')

  0 Comments

Sign in to comment.

Answers (1)

Tony Tse
Tony Tse on 30 Sep 2018
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')

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags

Products


Release

R2018a