As I am newbie to signals, I have collected an appliance signal in frequency domain as follows: enter image description here

(PSD- Power Spectral Density). So, I need to calculate the SNR (Signal to Noise Ratio) and BER (Bit Error Rate) caused by this signal in Powerline Calculation. So, I have made these codes in Matlab, but what I am stuck with is calculating the SNR and BER.

bits=10000; %number of bit
b=randi([0,1],1,bits); % generate random [0,1]
t=0:1/30:1-1/30; % Time period allocated for the signal

%ASK Carrier Signals
carrier_signa_l= sin(2*pi*t);
carrier_signa_l=carrier_signa_l/sqrt(E1); %unit energy 
carrier_signal_0 =0 * sin(2*pi*t); % zeros for 0 bits in the carrier signal

for i=1:bits
    if b(i)==1 % If bit = 1
        ask=[ask carrier_signa_l];
        ask=[ask carrier_signal_0];
  • $\begingroup$ 1) You have to give the waveform of the "noise"; i.e. turn the appliance off. Or if the noise is part of the appliance then a more in-depth analysis must be done. $\endgroup$
    – rrogers
    Commented Aug 7, 2018 at 19:26
  • $\begingroup$ @rrogers I think the noise waveform can be as a white Gaussian noise. I don't know if this is what you meant by noise waveform. could you please elaborate more? $\endgroup$ Commented Aug 8, 2018 at 14:46
  • $\begingroup$ Well, what does the frequency spectrum look like; signal bandwidth and noise bandwidth? Does it have 1/f noise or "pink noise"? What do you consider "signal". Actually, there is a difference between: "real noise" due to electronics, interfering signals/events. Interferences are things like things banging because of the appliance operation. External things are probably not useful whereas things banging inside the appliance would be pertinent. What I picture is a microphone on an "appliance". Is this wrong? But it doesn't make sense to worry about BER in that case? $\endgroup$
    – rrogers
    Commented Aug 9, 2018 at 18:09

1 Answer 1


If it is a sinusoidal signal, there will be peak (among the frequency bins) in the frequency spectrum corresponding to the tone's frequency.

Ratio of the magnitude of this peak to the sum of the magnitudes of all other bins (which are noise) correspond to Signal to Noise Ratio.

But when its a non sinusoidal signal (like the one in your plot) you have to consider the relevant band of the signal instead of a single peak. you can quantify it by specifying a frequency bin corresponding to the mojor frquency component in the signal plus some leakage (related to bandwidth) into the nearby bins.

Please take a look in the following matlab code.

N               = 8192; % FFT length
leak            = 50; 
% considering a leakage of signal energy to 50 bins on either side of major freq component

fft_s           = fft(inptSignal,N); % analysing freq spectrum
abs_fft_s       = abs(fft_s);

[~,p]           = max(abs_fft_s(1:N/2));
% Finding the peak in the freq spectrum

sigpos          = [p-leak:p+leak N-p-leak:N-p+leak];
% finding the bins corresponding to the signal around the major peak
% including leakage

sig_pow         = sum(abs_fft_s(sigpos)); % signal power = sum of magnitudes of bins conrresponding to signal
abs_fft_s([sigpos]) = 0; % making all bins corresponding to signal zero:==> what ever that remains is noise 
noise_pow       = sum(abs_fft_s); % sum of rest of componenents == noise power

SNR             = 10*log10(sig_pow/noise_pow);
  • $\begingroup$ thanks for your response, I was trying to understand the relation between sig_pow and noise_pow. So is the inputSignal the appliance noise on the graph? or is it carrier_signa_l in my code? because I couldn't find the relation between them. The noise for me is the appliance on the graph above, while the signal power is my carrier_signa_l. $\endgroup$ Commented Aug 12, 2018 at 23:20
  • $\begingroup$ also, if I create a random gaussian noise to my channel, can I calculate SNR to the signal as follows? for snr_deg=1:20 askn=awgn(ask,snr_deg); for i=1:bits fft_noise = fft(askn,N); % analysing noise freq spectrum abs_fft_noise= abs(fft_noise); [~,peak_noise] = max(abs_fft_noise(1:N/2)); noisepos = [peak_noise-leak:peak_noise+leak N-peak_noise-leak:N-peak_noise+leak]; abs_fft_noise([noisepos]) = 0; noise_power = sum(abs_fft_noise); SNR = 10*log10(sig_pow/noise_power ); end $\endgroup$ Commented Aug 12, 2018 at 23:58
  • $\begingroup$ I know I have too many questions, but bear with me please, How can I detect BER from the given SNR? $\endgroup$ Commented Aug 12, 2018 at 23:59
  • $\begingroup$ @srk_cb Hi, so I came across your answer to this post and had just one question, when taking the SNR, shouldn't the noise power be scaled with N/2 after taking the sum of noise bin amplitudes? $\endgroup$
    – malik12
    Commented Feb 8, 2023 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.