You are on page 1of 2

% ---------------------------------------% +++++ Simulation of PSK Demodulator +++++++ % For simplicity only the detector (after sampling) is simulated.

% ---------------------------------------clear all ; close all; % normalized to unit energy E = 1 ; snr_dB = 20 ; N = 10000 ; % no of bits ... % no. of levels ... M = 8 ; % carrier phase off-set in radian .. phi = 0*pi/180 ; snr = exp(snr_dB*log(10)/10) ; % this is detector noise std deviation sig = E/sqrt(2*snr) ; % the detector signals and symbol error .... err = 0 ; for i=1:N % tt is uniformly distributed in 0->1 . tt = rand; src = floor(rand*M) ; % simulate symbols 0 -- M-1 .... r0(i) = cos(phi+2*pi*src/M) + sig*randn ; % WGN r1(i) = sin(phi+2*pi*src/M) + sig*randn ; ang = atan2(r1(i),r0(i)) ; if(ang < 0) % angle in 0 --> 2*pi ang = ang + 2*pi ; end ; det = round(M*ang/(2*pi)) ; if(det == M ) det = 0 ; end ; if(det ~= src) err = err + 1 ; end ; end; SER = err/N ; % calculte therotical BER ...in a SNR (db) range dbR = 0:1:20 ; for i = 1:length(dbR) snr = exp(dbR(i)*log(10)/10) ; SERT(i) = erfc(sqrt(snr)*sin(pi/M)) ; end ; figure(1); plot(r0,r1,'.'); hold on ; for k=1:M plot([0 2*cos((2*k-1)*pi/M)], [0 2*sin((2*k-1)*pi/M)],'r--') ; end ; hold off ; axis([-1.5 1.5 -1.5 1.5]); grid; title('Signal constellations (normalized by Energy)'); xlabel('real part');

ylabel('imaginary part'); figure(2); semilogy(dbR, SERT, snr_dB, SER,'r*') ; grid ; xlabel('SNR in dB'); ylabel('Symbol Error Probability, Pm'); title('Theoretical (blue) and simulated (red *) Pm');

You might also like