lab1comm
-
Upload
shravan-kumar-luitel -
Category
Documents
-
view
16 -
download
0
Transcript of lab1comm
Kathmandu University
Communication Laboratory
D_COMM_LAB1:Digital Modulation-1
Shravan Kumar Luitel (32015)5/13/2011
Introduction:
Modulation is defined as the process by which some characteristics of a carrier is varied in accordance with modulating signal . In digital communications the modulating signal consists of binary data or an M-ary encoder version in it . This data is used to modulate a carrier wave with fixed frequency . The input data may represent the digital computer outputs of PCM waves generated by digitizing voice or video signals . The channel may be telephone channel , microwave radio link , satellite channel or optical fibre . In digital communications , the modulation process involves switching or keying the amplitude , frequency or phase of the carrier in accordance with the input data .
For this lab we will take into consideration ASK and PSK .
Example#1[Generation of ASK Signal and its plot]
a=rand(1,10)>0.5;n=1; fc=30;while n<=length(a) if a(n)==0 t=(n-1)*0.1:0.1/100:n*0.1; p=(1)*sin(2*pi*fc*t); %for binary 0 sine wave of amplitude 1 is taken %we can also consider no signal in this case subplot(2,1,1); plot(t,a(n)); title('Binary Signal'); axis([0 1 -1.5 1.5]); hold on ; subplot(2,1,2); plot(t,p); grid on ; title('Modulated signal'); hold on ; else t=(n-1)*0.1:0.1/100:n*0.1; p=(2)*sin(2*pi*fc*t); %for binary 1 sine wave of amplitude 2 is taken %we can also consider sine wave of amplitude 1 in this case subplot(2,1,1); plot(t,a(n)); hold on ; subplot(2,1,2); plot(t,p); hold on ; end n=n+1;end
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1.5
-1
-0.5
0
0.5
1
1.5Binary Signal
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-2
-1.5
-1
-0.5
0
0.5
1
1.5
2Modulated signal
Figure 1: Binary Signal and ASK Signal
Analysis/Inference:
The above code is an example of a binary modulation technique. With a binary modulation technique , the modulation process corresponds to switching or keying the amplitude , frequency or phase of the carrier between either of the two possible values corresponding to binary symbols 0 and 1 . The above code was the case of amplitude shift keying (ASK).
In the ASK system above , binary symbol 1 is represented by transmitting a sinusoidal carrier wave of fixed amplitude 2, and fixed frequency 30Hz for the bit duration 0.1 seconds whereas binary symbol 0 is represented by transmitting a sinusoidal carrier wave of fixed amplitude 1, and fixed frequency 30Hz for the bit duration 0.1 seconds as shown in Figure 1 . In mathematical terms , we may express the binary ASK wave s(t) as :
2sin (2π 30 t ) , symbol 1
S(t)= 1sin (2π 30 t ) , symbol 0
Example#2[Generation of BPSK Signal and its plot]
a=rand(1,10)>0.5;
n=1; fc=10;while n<=length(a) if a(n)==1 t=(n-1)*0.1:0.1/100:n*0.1; p=(1)*sin(2*pi*fc*t); %for binary 1 sine wave of amplitude 1 is taken subplot(2,1,1); plot(t,a(n)); title('Binary Signal'); axis([0 1 -1.5 1.5]); hold on ; subplot(2,1,2); plot(t,p,'k-'); grid on ; title('Modulated signal'); hold on ; else t=(n-1)*0.1:0.1/100:n*0.1; p=(-1)*sin(2*pi*fc*t); %for binary 0 sine wave of amplitude -1 is taken subplot(2,1,1); plot(t,a(n)); hold on ; subplot(2,1,2); plot(t,p,'k-'); hold on ; end n=n+1;end
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1.5
-1
-0.5
0
0.5
1
1.5Binary Signal
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1
-0.5
0
0.5
1Modulated signal
Figure 2: Binary Signal and BPSK Signal
Analysis/Inference:
In the above code we saw another example of binary modulation technique.The code generated a PSK system . In phase shift keying , the phase of the carrier is changed according to the modulating waveform which is a digital signal . In Binary Phase Shift Keying (BPSK) the carrier gets 0 or 180⁰ phase shift corresponding to two different voltage levels of binary modulating signal .In above BPSK system a sinusoidal carrier wave of fixed amplitude 1 and fixed frequency 10Hz is used to represent both symbols 1 and 0 , except that the carrier phase for each symbol differs by 180⁰ as illustrated in figure 2. In this case we may express the binary PSK as :
1sin (2 π 10t ), symbol1
s(t)=−1sin (2π 10 t+π ) , symbol 0
Example#3[BER vs. SNR plot of a signal]
db=0:0.1:10;SNR=10.^(db./10);pb=0.5*erfc(sqrt(SNR));semilogy(db,pb); %same as : plot(db,log10(pb));grid on;xlabel('SNR(db)');ylabel('Bit error rate');title('Performance of a signal over AWGN channel');
0 1 2 3 4 5 6 7 8 9 1010
-6
10-5
10-4
10-3
10-2
10-1
SNR(db)
Bit
erro
r ra
te
Performance of a signal over AWGN channel
Figure 3: BER vs SNR plot
Example#4[Simulation of BPSK in Simulink]
Sine Wave
Scope
Product 1
Product
Complex toReal -Imag
Re
Im
Coine Wave 1
Bernoulli BinaryGenerator
BernoulliBinary
BPSKModulatorBaseband
BPSK
BPSKDemodulator
Baseband
BPSK
Figure 4: Simulink model for BPSK
Figure 5: Simulated Plot of BPSK
Assignment :
1. Generate OOK Signal .
Code:a=rand(1,10)>0.5;n=1; fc=30;while n<=length(a) if a(n)==0 t=(n-1)*0.1:0.1/100:n*0.1; p=0; %for binary 0 no signal is taken in this case subplot(2,1,1); plot(t,a(n)); title('Binary Signal'); axis([0 1 -1.5 1.5]); hold on ; subplot(2,1,2); plot(t,p); grid on ; title('Modulated signal'); hold on ; else t=(n-1)*0.1:0.1/100:n*0.1; p=(1)*sin(2*pi*fc*t); %for binary 1 sine wave of amplitude 1 is taken subplot(2,1,1); plot(t,a(n)); hold on ; subplot(2,1,2);
plot(t,p); hold on ; end n=n+1;end
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1.5
-1
-0.5
0
0.5
1
1.5Binary Signal
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1
-0.5
0
0.5
1Modulated signal
Assignment 1: Binary Signal and OOK Signal
Analysis/Inference:
On-off keying (OOK) is a special case of binary ASK . In the OOK system above , binary symbol 1 is represented by transmitting a sinusoidal carrier wave of fixed amplitude 1, and fixed frequency 30Hz for the bit duration 0.1 seconds whereas binary symbol 0 is represented by switching off the carrier for 0.1 seconds as shown in figure above . In mathematical terms , we may express the OOK wave s(t) as :
2sin (2π 30 t ) , symbol 1
S(t)= 0 , symbol 0
2. Generate QPSK Signal .3. Simulate QPSK signal from SIMULINK , also display the error rate .
Bit Error Rate
Number of Errors
Total number of bits that are transmitted
scope
Sine
DSP
Random IntegerGenerator
RandomInteger
QPSKModulatorBaseband
QPSK
QPSKDemodulator
Baseband
QPSK
Product 1
Product
Error RateCalculation
Error Rate Calculation
Tx
Rx
Display
0
0
21
Cosine
DSP
Complex toReal -Imag
Re
Im
Assignment 2:Simulink model for QPSK
4. For different values of Eb/η, find the BER plot for BPSK and QPSK and match the simulated value with the theoretical value. Also give inferences if you find any differences .
BPSK:
clearN = 10^6 % number of bits or symbolsrand('state',100); % initializing the rand() functionrandn('state',200); % initializing the randn() function
% Transmitterip = rand(1,N)>0.5; % generating 0,1 with equal probabilitys = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 1 n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white gaussian noise, 0dB variance Eb_N0_dB = [-3:10]; % multiple Eb/N0 values for ii = 1:length(Eb_N0_dB) % Noise addition y = s + 10^(-Eb_N0_dB(ii)/20)*n; % additive white gaussian noise % receiver - hard decision decoding ipHat = real(y)>0; % counting the errors nErr(ii) = size(find([ip- ipHat]),2); end simBer = nErr/N; % simulated bertheoryBer = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber % plotclose allfiguresemilogy(Eb_N0_dB,theoryBer,'b.-');hold onsemilogy(Eb_N0_dB,simBer,'mx-');axis([-3 10 10^-5 0.5])grid onlegend('theory', 'simulation');xlabel('Eb/No, dB');ylabel('Bit Error Rate');title('Bit error probability curve for BPSK modulation');
-2 0 2 4 6 8 1010
-5
10-4
10-3
10-2
10-1
Eb/No, dB
Bit
Err
or R
ate
Bit error probability curve for BPSK modulation
theory
simulation
Assignment 4b: BER vs Eb/η plot for BPSK
QPSK:
clear;clc;%---------Input Fields------------------------N=1000000; %Number of input bitsEbN0dB = -4:2:10; % Eb/N0 range in dB for simulation%--------------------------------------------- data=randn(1,N)>=0; %Generating a uniformly distributed random 1s and 0soddData = data(1:2:end);evenData = data(2:2:end);qpskModulated = sqrt(1/2)*(1i*(2*oddData-1)+(2*evenData-1)); %QPSK Mapping M=4; %Number of Constellation points M=2^k for QPSK k=2Rm=log2(M); %Rm=log2(M) for QPSK M=4Rc=1; %Rc = code rate for a coded system. Since no coding is used Rc=1 BER = zeros(1,length(EbN0dB)); %Place holder for BER values for each Eb/N0index=1; for i=EbN0dB, %------------------------------------------- %Channel Noise for various Eb/N0 %------------------------------------------- %Adding noise with variance according to the required Eb/N0 EbN0 = 10.^(i/10); %Converting Eb/N0 dB value to linear scale noiseSigma = sqrt(1./(2*Rm*Rc*EbN0)); %Standard deviation for AWGN Noise %Creating a complex noise for adding with QPSK modulated signal %Noise is complex since QPSK is in complex representation
noise = noiseSigma*(randn(1,length(qpskModulated))+1i*randn(1,length(qpskModulated))); received = qpskModulated + noise; %------------------------------------------- %Threshold Detector detected_real = real(received)>=0; detected_img = imag(received)>=0; estimatedBits=reshape([detected_img;detected_real],1,[]); %------------------------------------------ %Bit Error rate Calculation BER(index) = sum(xor(data,estimatedBits))/length(data); index=index+1;end%Plot commands followsplotHandle=plot(EbN0dB,log10(BER),'r--');set(plotHandle,'LineWidth',1.5);title('SNR per bit (Eb/N0) Vs BER Curve for QPSK Modulation Scheme');xlabel('SNR per bit (Eb/N0) in dB');ylabel('Bit Error Rate (BER) in dB');grid on; hold on; theoreticalBER =0.5*erfc(sqrt(10.^(EbN0dB/10)));plotHandle=plot(EbN0dB,log10(theoreticalBER),'b*');set(plotHandle,'LineWidth',1.5);legend('Simulated','Theoretical-QPSK','Theoretical-QPSK');grid on;
-4 -2 0 2 4 6 8 10-5.5
-5
-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5SNR per bit (Eb/N0) Vs BER Curve for QPSK Modulation Scheme
SNR per bit (Eb/N0) in dB
Bit
Err
or R
ate
(BE
R)
in d
B
Simulated
Theoretical-QPSK
Assignment 4b: BER vs SNR plot for QPSK
Observations1. We can see good agreement between the simulated and theoretical plots for BPSK and QPSK modulation.