Professional Documents
Culture Documents
OUTPUT:
:
COMMAND WINDOW
x=input('Enter input bit stream: '); % Binary Information bp=.000001;
% bit period
% representation of transmitting binary information as digital signal
bit=[]; for n=1:1:length(x) if x(n)==1; se=ones(1,100); else x(n)==0;
se=zeros(1,100); end bit=[bit se]; end
t1=bp/100:bp/100:100*length(x)*(bp/100);
FIGURE WINDOW:
subplot(4,1,1);
plot(t1,bit,'lineWidth',1.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)'); xlabel(' time(sec)');
title('transmission sequence');
%XXXXXXXXXXXXXXXXXXXXXXX Binary-PSK modulation XXXXXXXXXXXXXXXXXXXXXXXXXXX%
A=5; % Amplitude of carrier signal
br=1/bp; % bit rate f=br*2; %
carrier frequency
t2=bp/99:bp/99:bp; ss=length(t2); m=[];
for (i=1:1:length(x)) if
(x(i)==1) y=A*sin(2*pi*f*t2);
else
y=A*sin(2*pi*f*t2+pi); %A*sin(2*pi*f*t+pi) means -A*sin(2*pi*f*t)
end m=[m y]; end
t3=bp/99:bp/99:bp*length(x);
%plotting carrier signal
subplot(4,1,2);
plot(t3,A*sin(2*pi*f*t3));
xlabel('t(sec)');
ylabel('A(volt)');
title('Carrier Wave'); %plotting
modulated wave subplot(4,1,3);
plot(t3,m);
xlabel('t(sec)'); ylabel('A(volt)');
RESULT:
title('Modulated ASK Signal');
We observed the modulatedBinary
%XXXXXXXXXXXXXXXXXXXX and demodulated ASK(Amplitude
PSK demodulation Shift Keying) Wave on MATLAB.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y=sin(2*pi*f*t); % carrier signal
mm=y.*m((n-(ss-1)):n); t4=bp/99:bp/99:bp;
z=trapz(t4,mm); % integration
zz=round((2*z/bp)) ; if(zz>0)
% logic level = (A+A)/2=0
%because A*sin(2*pi*f*t+pi) means -A*sin(2*pi*f*t) a=1; else a=0;
end mn=[mn a]; end
disp(' Binary information at Receiver :'); disp(mn);
%XXXXX Representation of binary information as digital signal which achived
%after PSK demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX bit=[]; for
n=1:length(mn); if mn(n)==1; se=ones(1,100); else mn(n)==0;
se=zeros(1,100); end bit=[bit se]; end
EXPERIMENT 2
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(4,1,4)
AIM:To write a code in MATLAB to generate modulated and demodulated PSK wave.
CODE:
clc; clear
all;
plot(t4,bit,'LineWidth',1.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('A(volt)'); xlabel(' t(sec)');
title('Demodulated PSK Wave');
%>>>>>>>>>>>>>>>>>>>>>>>>>> end of program >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>%
OUTPUT:
COMMAND WINDOW:
FIGURE WINDOW:
RESULT:
We observed the modulated and demodulated PSK (Phase Shift Keying) Wave on MATLAB.
EXPERIMENT 3
AIM: To write a code in MATLAB to generate modulated and demodulated FSK wave.
CODE:
%>>>>>>>>> MATLAB code for binary FSK modulation and de-modulation >>>>>>>%
clc; clear all;
x=input('Enter input bit stream: '); % Binary Information bp=.000001;
% bit period
%XX representation of transmitting binary information as digital signal XXX
bit=[]; for n=1:1:length(x) if x(n)==1; se=ones(1,100); else x(n)==0;
se=zeros(1,100); end bit=[bit se]; end
t1=bp/100:bp/100:100*length(x)*(bp/100);
subplot(5,1,1);
plot(t1,bit,'lineWidth',1.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('A(volt)'); xlabel(' t(sec)');
title('transmission Sequence');
%XXXXXXXXXXXXXXXXXXXXXXX Binary-FSK modulation XXXXXXXXXXXXXXXXXXXXXXXXXXX%
A=5; % Amplitude of carrier signal br=1/bp;
% bit rate f1=br*6; % carrier frequency for
information as 1
f2=br*2; % carrier frequency for information as 0
t2=bp/99:bp/99:bp; ss=length(t2); m=[];
for (i=1:1:length(x)) if
(x(i)==1)
y=A*cos(2*pi*f1*t2);
else
y=A*cos(2*pi*f2*t2);
end m=[m y]; end
t3=bp/99:bp/99:bp*length(x);
subplot(5,1,2);
plot(t3,A*cos(2*pi*f1*t3));
xlabel('t(sec)');
ylabel('A(volt)'); title('Carrier
Signal 1'); subplot(5,1,3);
plot(t3,A*cos(2*pi*f2*t3));
xlabel('t(sec)');
ylabel('A(volt)'); title('Carrier
Signal 2'); subplot(5,1,4); plot(t3,m);
xlabel('t(sec)'); ylabel('A(volt)');
title('Modulated FSK Signal');
%XXXXXXXXXXXXXXXXXXXX Binary FSK demodulation XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
mn=[];
for n=ss:ss:length(m)
t=bp/99:bp/99:bp;
y1=cos(2*pi*f1*t); % carrier signal for information 1
y2=cos(2*pi*f2*t); % carrier signal for information 0
mm=y1.*m((n-(ss-1)):n); mmm=y2.*m((n-(ss-1)):n); t4=bp/99:bp/99:bp;
z1=trapz(t4,mm) ; % integration
z2=trapz(t4,mmm); % integration
zz1=round(2*z1/bp); zz2= round(2*z2/bp);
if(zz1>A/2) % logic level= (0+A)/2 or (A+0)/2 or 2.5 ( in this case)
a=1; else(zz2>A/2) a=0; end mn=[mn a]; end
disp(' Binary information at Receiver :'); disp(mn);
%XXXXX Representation of binary information as digital signal which achived
%after demodulation
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX bit=[]; for
n=1:length(mn); if mn(n)==1; se=ones(1,100); else mn(n)==0;
se=zeros(1,100); end bit=[bit se]; end
t4=bp/100:bp/100:100*length(mn)*(bp/100);
subplot(5,1,5)
plot(t4,bit,'LineWidth',1.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('A(volt)'); xlabel(' t(sec)');
title('Demodulated FSK Signal');
%>>>>>>>>>>>>>>>>>>>>>>>>>> end of program >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>%
OUTPUT:
COMMAND WINDOW:
FIGURE WINDOW:
RESULT:
We observed the modulated and demodulated FSK (Frequency Shift Keying) Wave on MATLAB.
EXPERIMENT 4
AIM: To write a code in MATLAB to generate modulated and demodulated PCM Wave.
CODE:
RESULT:
We observed the modulated and demodulated PCM(Pulse Code Modulation) Wave on MATLAB.
EXPERIMENT 5
AIM: To write a code in MATLAB to generate modulated and demodulated Adaptive
Delta Modulation Wave.
CODE:
FUNCTION DEFINITION
function [ADMout] = adeltamod(sig_in, Delta, td, ts)
if (round(ts/td) >= 2)
Nfac = round(ts/td); %Nearest integer
xsig = downsample(sig_in,Nfac);
Lxsig = length(xsig);
Lsig_in = length(sig_in);
ADMout = zeros(Lsig_in); %Initialising output cnt1 = 0;
%Counters for no. of previous consecutively increasing cnt2 = 0; %steps
sum = 0; for i=1:Lxsig if (xsig(i) ==
sum) elseif (xsig(i) > sum) if (cnt1 < 2)
sum = sum + Delta; %Step up by Delta, same as in DM
elseif (cnt1 == 2) sum = sum + 2*Delta; %Double the
step size after %first two
increase elseif (cnt1 == 3) sum = sum
+ 4*Delta; %Double step size else
sum = sum + 8*Delta; %Still double and then stop
%doubling thereon
end if (sum < xsig(i))
cnt1 = cnt1 + 1; else cnt1
= 0; end else if
(cnt2 < 2) sum = sum - Delta;
elseif (cnt2 == 2) sum = sum - 2*Delta;
elseif (cnt2 == 3) sum = sum - 4*Delta;
else sum = sum - 8*Delta;
end
if (sum > xsig(i)) cnt2
= cnt2 + 1;
else cnt2 = 0; end
end
ADMout(((i-1)*Nfac + 1):(i*Nfac)) = sum;
end end end
OUTPUT:
FIGURE WINDOW:
RESULT:
We observed the modulated and demodulated ADM(Amplitude Code MOdulation) Wave on MATLAB.
EXPERIMENT 6
AIM:
MATLAB Code to perform Number of bit errors and bit error rate (BER)
MATLAB CODE:
%Number of bit errors %Create
two binary matrices.
x = [0 0; 0 0; 0 0; 0 0] y = [0 0; 0 0; 0 0; 1 1] numerrs = biterr(x,y)%Determine
the number of bit errors. numerrs = biterr(x,y,[],'column-wise')%Compute the
number of column-wise errors . numerrs = biterr(x,y,[],'row-wise')%Compute the
number of row-wise errors. numerrs = biterr(x,y,[],'overall')%Compute the number
of overall errors.
COMMAND WINDOW
>> BitErrorRateComputationExample x
=
0 0
0 0
0 0
0 0y
=
0 0
0 0
0 0
1 1
numerrs =
numerrs =
1 1
numerrs =
0
0
0
2
numerrs =
FIGURE WINDOW
BitsPerSymbol: 4
SignalPower: 1
SamplesPerSymbol: 1
EXPERIMENT 8
AIM:
EXPERIMENT 7
MATLAB Code to perform MSK Signal Recovery
MATLAB
AIM: CODE:
MATLAB Code to Configure Eb/No for AWGN Channels with Coding
%% MSK Signal Recovery
% Model channel impairments such as timing phase offset, carrier frequency
MATLAB
% offset, and CODE :
carrier phase offset for a minimum shift keying (MSK) signal.
N% =Use
15;|comm.MSKTimingSynchronizer|
% R-S codeword length in symbols
and |comm.CarrierSynchronizer| System
K% =objects
9; to
% R-S
synchronize
message length
such signals
in symbols
at the
M = receiver.
16; % Modulation
The MSK timing
order
% synchronizer
rsEncoder recovers
= the timing offset, while a carrier synchronizer
comm.RSEncoder(
% recovers the 'CodewordLength'
carrier frequency,N,'MessageLength' ,K, ...
and phase offsets.
%% 'BitInput',true);
pskModulator
% Initialize =system
comm.PSKModulator(
variables by'ModulationOrder'
running the MATLAB
,M,'BitInput',true);
script rsDecoder
=% comm.RSDecoder ('CodewordLength',N,'MessageLength'
|configureMSKSignalRecoveryEx|. ,K, ...
Define the logical control variable
'BitInput',true); to enable timing phase recovery, and % |
% |recoverTimingPhase|
pskDemodulator
recoverCarrier|= to comm.PSKDemodulator( 'ModulationOrder'
enable carrier frequency ,M,'BitOutput'
and phase recovery. ,true);
codeRate = K/N; bitsPerSymbol recoverTimingPhase
configureMSKSignalRecoveryEx; = log2(M); = true; recoverCarrier
UncodedEbNo
= true; = 6;
CodedEbNo
%% Modeling = UncodedEbNo + 10*
log10(codeRate); channel =
Channel Impairments
comm.AWGNChannel(
% Specify the sample 'BitsPerSymbol' ,bitsPerSymbol);
delay, |timingOffset|, that the channel model applies.
channel.EbNo = CodedEbNo
% Create a variable fractional delay object to introduce the timing delay %
to the transmitted signal.
OUTPUT:
%%
timingOffset = 0.2; varDelay =
COMMAND WINDOW
dsp.VariableFractionalDelay;
%%
>> AWGN a |comm.PhaseFrequencyOffset| System object to introduce carrier
% Create
% phase and frequency offsets to a modulated signal. Because the MSK
channel = comm.AWGNChannel with
% modulator upsamples the transmitted symbols, set the |SampleRate|
% property to the ratio of the |samplesPerSymbol| and the sample time,
properties:
EbNo: 3.7815
% |Ts|. %% freqOffset = 50;
phaseOffset = 30; pfo =
comm.PhaseFrequencyOffset(...
'FrequencyOffset',freqOffset, ...
'PhaseOffset',phaseOffset, ...
'SampleRate',samplesPerSymbol/Ts);
%%
% Create a |comm.AWGNChannel| System object to add white Gaussian noise to
% the modulated signal. The noise power is determined by the |EbNo| %
property, that is the bit energy to noise power spectral density ratio. %
Because the MSK modulator generates symbols with 1 Watt of power, set the
% signal power property of the AWGN channel System object to 1.
%%
EbNo = 20 + 10*log10(samplesPerSymbol); chAWGN =
comm.AWGNChannel(...
'NoiseMethod','Signal to noise ratio (Eb/No)', ...
'EbNo',EbNo,...
'SignalPower',1, ...
'SamplesPerSymbol',samplesPerSymbol);
%% Timing Phase, Carrier Frequency, and Carrier Phase Synchronization %
Create an MSK timing synchronizer to recover symbol timing phase using a %
fourth-order nonlinearity method.
%% timeSync = comm.MSKTimingSynchronizer(...
'SamplesPerSymbol',samplesPerSymbol, ...
'ErrorUpdateGain',0.02);
%%
% Create a carrier synchronizer to recover both carrier frequency and
% phase. Because the MSK constellation is QPSK with a 0-degree phase %
offset, set the |comm.CarrierSynchronizer| accordingly.
%% phaseSync = comm.CarrierSynchronizer(...
'Modulation','QPSK', ...
'ModulationPhaseOffset','Custom', ...
'CustomPhaseOffset',0, ...
'SamplesPerSymbol',1);
%% Stream Processing Loop
% The simulation modulates data using MSK modulation. The modulated symbols
% pass through the channel model, which applies timing delay, carrier
% frequency and phase shift, and additive white Gaussian noise. The
% receiver performs timing phase and carrier frequency and phase recovery.
% Finally, the signal symbols are demodulated and the bit error rate is %
calculated. The |plotResultsMSKSignalRecoveryEx| script generates scatter %
plots in this order to show these effects:
%
% # Channel impairments
% # Timing synchronization
% # Carrier synchronization
%
% At the end of the simulation, the example displays the timing phase,
% frequency, and phase estimates as a function of simulation time.
%%
for p = 1:numFrames
%------------------------------------------------------------------------
% Generate and modulate data
%------------------------------------------------------------------------
txBits = randi([0 1],samplesPerFrame,1);
txSym = modem(txBits);
%------------------------------------------------------------------------
% Transmit through channel
%------------------------------------------------------------------------
%
% Add timing offset rxSigTimingOff =
varDelay(txSym,timingOffset*samplesPerSymbol);
%
% Add carrier frequency and phase offset
rxSigCFO = pfo(rxSigTimingOff);
%
% Pass the signal through an AWGN channel
rxSig = chAWGN(rxSigCFO);
%
% Save the transmitted signal for plotting
plot_rx = rxSig;
%
%------------------------------------------------------------------------
% Timing recovery
%------------------------------------------------------------------------
if recoverTimingPhase
% Recover symbol timing phase using fourth-order nonlinearity
% method
[rxSym,timEst] = timeSync(rxSig);
% Calculate the timing delay estimate for each sample
timEst = timEst(1)/samplesPerSymbol;
else
% Do not apply timing recovery and simply downsample the received
% signal rxSym =
downsample(rxSig,samplesPerSymbol);
timEst = 0;
end
%------------------------------------------------------------------------
% Carrier frequency and phase recovery
%------------------------------------------------------------------------ if
recoverCarrier
% The following script applies carrier frequency and phase recovery
% using a second order phase-locked loop (PLL), and removes phase ambiguity
[rxSym,phEst] = phaseSync(rxSym);
removePhaseAmbiguityMSKSignalRecoveryEx; freqShiftEst
= mean(diff(phEst)/(Ts*2*pi));
phEst = mod(mean(phEst),360); % in degrees
else
freqShiftEst = 0;
phEst = 0;
end
OUTPUT:
COMMAND WINDOW
>> MSKSignalRecoveryExample
BitErrorRate =
2.0001e-06
TotalNumberOfSymbols =
499982
FIGURE WINDOW
EXPERIMENT NO. 9
AIM:
MATLAB Code to perform DQPSK Signal in AWGN
MATLAB CODE:
dqpskmod = comm.DQPSKModulator('BitInput',true);
dqpskdemod = comm.DQPSKDemodulator('BitOutput',true);
channel = comm.AWGNChannel('EbNo',6,'BitsPerSymbol',2);
errorRate = comm.ErrorRate('ComputationDelay',1); for
counter = 1:100 txData = randi([0 1],100,1); modSig
= dqpskmod(txData); rxSig = channel(modSig); rxData
= dqpskdemod(rxSig); errorStats =
errorRate(txData,rxData); end ber = errorStats(1)
numErrors = errorStats(2) numBits = errorStats(3)
OUTPUT:
COMMAND WINDOW
>> DQPSK
ber =
0.0174
numErrors =
174
numBits =
9999
EXPERIMENT 10
AIM:
MATLAB Code to perform OQPSK Signal in AWGN
MATLAB CODE:
oqpskmod = comm.OQPSKModulator('BitInput',true);
oqpskdemod = comm.OQPSKDemodulator('BitOutput',true);
channel = comm.AWGNChannel('EbNo',4,'BitsPerSymbol',2);
errorRate = comm.ErrorRate('ReceiveDelay',2); for
counter = 1:300 txData = randi([0 1],100,1); modSig
= oqpskmod(txData); rxSig = channel(modSig); rxData
= oqpskdemod(rxSig); errorStats =
errorRate(txData,rxData); end ber = errorStats(1)
numErrors = errorStats(2) numBits = errorStats(3)
OUTPUT:
COMMAND WINDOW
>> OQPSK
ber =
0
numErrors =
0
numBits =
29998