I am unable to understand the command awgn in matlab.I considered the signal vector x=[1 2 3 4 5 6 7 8 9 10].The power of x is
pow_x=norm(x,2)^2/length(x)=38.5000
and it's value in dB is pow_xdb=10*log10(pow_x)=15.8546 dB
Now I want AWGN noise denoted by n with SNR of 30 dB wrt to signal x.So I use the command
n=awgn(x,snr,sigpower)=awgn(x,30,15.8546) and I get
n=[1.1055 2.3598 2.5568 4.1692 5.0625 5.7434 6.9149 8.0672 9.7021 10.5434]
The power of n is pow_n=norm(n,2)^2/length(n)=40.7517 and in dB is pow_ndb=10*log10(pow_n)=16.1015
When I can calculate SNR I get
SNR=10*log10(pow_x/pow_n)=-0.2469 dB and not 30 dB.
So,someone please help me though I use the command n=awgn(x,snr,sigpower)=awgn(x,30,15.8546) to get a AWGN signal vector whose SNR wrt to x is 30 dB why am I unable to generate it
Based upon Adam Sir's suggestion I tried running the program below and the answers I got are
t=0:0.01:1; disp('Number of Samples');disp(length(t));
y=sin(2*pi*1*t);% Signal
y_pow=norm(y)^2/length(t); disp('Power of y');disp(y_pow); y_powdb=10*log10(y_pow); disp('Power of y in db');disp(y_powdb);
y_noise=awgn(y,30,'measured');% Noisy Signal
n=y_noise-y;% Noise
n_pow=norm(n)^2/length(t);disp('Noise Power');disp(n_pow); n_powdb=10*log10(n_pow);disp('Noise Power in db');disp(n_powdb);
SNR=20*log10(norm(y_noise)/norm(n));disp('The Signal to Noise Ratio is');disp((SNR));
Answers I got
Number of Samples 101
Power of y 0.4950
Power of y in db -3.0535
Noise Power 4.9047e-004
Noise Power in db -33.0939
The Signal to Noise Ratio is 30.0608
I tried this program several times and the SNR I got is not exactly 30 but a value in the neighbourhood of 30,is there any mistake in my approach,I am not getting the exact value
It could be because of this reason:
x ... signal
n = awgn(x,snr) ... that's the resulting signal; signal x with added noise
Check it easily by subtracting clear signal from noisy signal: only_noise = n - x;
It works for me, hope that it helps you...
Adam