Experiment No:1: Aim:Write A Program For Sampling. Software Used:matlab Theory

Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

EXPERIMENT NO:1

Aim:Write a program for sampling.

Software used:Matlab

Theory:
Sampling is defined as, “The process of measuring the instantaneous values of
continuous-time signal in a discrete form.”Sample is a piece of data taken from the
whole data which is continuous in the time domain.When a source generates an
analog signal and if that has to be digitized, having 1s and 0s i.e., High or Low, the
signal has to be discretized in time. This discretization of analog signal is called as
Sampling.The following figure indicates a continuous-time signal x(t) and a sampled
signal xs (t). When x (t) is multiplied by a periodic impulse train, the sampled
signal x(t) is obtained.
Sampling Rate

To discretize the signals, the gap between the samples should be fixed. That gap can
be termed as a sampling period Ts.

SamplingFrequency=1/Ts=fs

Where
Ts is the sampling time
fs is the sampling frequency or the sampling rate
Sampling frequency is the reciprocal of the sampling period. This sampling
frequency, can be simply called as Sampling rate. The sampling rate denotes the
number of samples taken per second, or for a finite set of values.
For an analog signal to be reconstructed from the digitized signal, the sampling rate
should be highly considered. The rate of sampling should be such that the data in the
message signal should neither be lost nor it should get over-lapped. Hence, a rate
was fixed for this, called as Nyquist rate.

Nyquist Rate

Suppose that a signal is band-limited with no frequency components higher


than W Hertz. That means, W is the highest frequency. For such a signal, for
effective reproduction of the original signal, the sampling rate should be twice the
highest frequency.
Which means,

fS=2W

Where,
fS is the sampling rate
W is the highest frequency
This rate of sampling is called as Nyquist rate.
A theorem called, Sampling Theorem, was stated on the theory of this Nyquist rate.

Sampling Theorem

The sampling theorem, which is also called as Nyquist theorem, delivers the theory
of sufficient sample rate in terms of bandwidth for the class of functions that are
bandlimited.
The sampling theorem states that, “a signal can be exactly reproduced if it is
sampled at the rate fs which is greater than twice the maximum frequency W.”
To understand this sampling theorem, let us consider a band-limited signal, i.e., a
signal whose value is non-zero between some –W and W Hertz.
Such a signal is represented as x(f)=0for|f|>Wx(f)=0for|f|>W
For the continuous-time signal x tt, the band-limited signal in frequency domain, can
be represented as shown in the following figure.

We need a sampling frequency, a frequency at which there should be no loss of


information, even after sampling. For this, we have the Nyquist rate that the
sampling frequency should be two times the maximum frequency. It is the critical
rate of sampling.If the signal x(t) is sampled above the Nyquist rate, the original
signal can be recovered, and if it is sampled below the Nyquist rate, the signal
cannot be recovered.The following figure explains a signal, if sampled at a higher
rate than 2w in the frequency domain.

The above figure shows the Fourier transform of a signal xs(t). Here, the information
is reproduced without any loss. There is no mixing up and hence recovery is
possible.
The Fourier Transform of the signal xs(t) is

Xs(w)=1/Ts∑n=−∞∞X(w−nw0)

Where Ts = Sampling Period and w0=2πTs


Let us see what happens if the sampling rate is equal to twice the highest frequency
(2W)
That means,

fs=2W

Where,
Fs is the sampling frequency
W is the highest frequency

The result will be as shown in the above figure. The information is replaced without
any loss. Hence, this is also a good sampling rate.
Matlab Code:
% Sample the sinusoid x = sin(2 pi f t), where f =
2 kHz, and plot the sampled
% signals over the continuous-time signal.
% Let x1 be the signal sampled at 10 kHz.
% Let x2 be the signal sampled at 3 kHz.

f = 2000;
T = 1/f;
tmin = 0;
tmax = 5*T;
dt = T/100;
dt1 = 1/10000;
dt2 = 1/3000;
t = tmin:dt:tmax;
t1 = tmin:dt1:tmax;
t2 = tmin:dt2:tmax;
x = sin(2*pi*f*t);
x1 = sin(2*pi*f*t1);
x2 = sin(2*pi*f*t2);
subplot(211)
plot(t,x,'r');
hold on
stem(t1,x1);
subplot(212)
plot(t,x,'r');
hold on
stem(t2,x2);
Output:

Conclusion:

The sampling of sin(2*pi*f*t) is plotted.The conversion of a signal from continuous


time to discrete time,a process called sampling is used.
EXPERIMENT NO:2

Aim:Write a program for analog signal reconstruction.


Software used:Matlab
Theory:
Reconstruction is the process of creating an analog voltage (or current) from samples.
A digital-to-analog converter takes a series of binary numbers and recreates the
voltage (or current) levels that corresponds to that binary number. Then this signal is
filtered by a lowpass filter. This process is analogous to interpolating between points
on a graph, but it can be shown that under certain conditions the original analog
signal can be reconstructed exactly from its samples. Unfortunately, the conditions
for exact reconstruction cannot be achieved in practice, and so in practice the
reconstruction is an approximation to the original analog signal.

Matlab Code:
%% Sampling and reconstruction
clear,clc,close all;

%% Parameters
F = 30; % frequency of signal [Hz]
Fs = 2*F; % sampling rate [Hz]
Ts = 1/Fs; % sampling period [sec]

%% Generate "continuous time" signal and discrete time signal


tc = 0:1e-4:5/F; % CT axis
xc = cos(2*pi*F*tc); % CT signal
td = 0:Ts:5/F; % DT axis
xd = cos(2*pi*F*td); % DT signal
N = length(td); % number of samples

%% Reconstruction by using the formula:


% xr(t) = sum over n=0,...,N-1:
x(nT)*sin(pi*(t-nT)/T)/(pi*(t-nT)/T)
% Note that sin(pi*(t-nT)/T)/(pi*(t-nT)/T) = sinc((t-nT)/T)
% sinc(x) = sin(pi*x)/(pi*x) according to MATLAB
xr = zeros(size(tc));
sinc_train = zeros(N,length(tc));
for t = 1:length(tc)
for n = 0:N-1
sinc_train(n+1,:) =
sin(pi*(tc-n*Ts)/Ts)./(pi*(tc-n*Ts)/Ts);
xr(t) = xr(t) +
xd(n+1)*sin(pi*(tc(t)-n*Ts)/Ts)/(pi*(tc(t)-n*Ts)/Ts);
end
end

%% Plot the results


figure
hold on
grid on
plot(tc,xc)
stem(td,xd)
plot(tc,xr)
xlabel('Time [sec]')
ylabel('Amplitude')

%% Sinc train visualization


figure
hold on
grid on
plot(tc,xd.'.*sinc_train)
stem(td,xd)
xlabel('Time [sec]')
ylabel('Amplitude')
Output:
Conclusion:
The reconstruction of analog signal is plotted.In reconstructing a signal from its
samples, there is another practical difficulty. The sampling theorem was proved on
the assumption that the signal x(t) is bandlimited. All practical signals are time
limited, i.e., they are of finite duration. As a signal cannot be timelimited and
bandlimited simultaneously.
EXPERIMENT NO:3

Aim:Write a program for Pulse code modulation.


Software Used:Matlab
Theory:
A signal is pulse code modulated to convert its analog information into a binary
sequence, i.e., 1s and 0s. The output of a PCM will resemble a binary sequence. The
following figure shows an example of PCM output with respect to instantaneous
values of a given sine wave.

Instead of a pulse train, PCM produces a series of numbers or digits, and hence this
process is called as digital. Each one of these digits, though in binary code,
represent the approximate amplitude of the signal sample at that instant.
In Pulse Code Modulation, the message signal is represented by a sequence of coded
pulses. This message signal is achieved by representing the signal in discrete form in
both time and amplitude.

Basic Elements of PCM

The transmitter section of a Pulse Code Modulator circuit consists of Sampling,


Quantizing and Encoding, which are performed in the analog-to-digital converter
section. The low pass filter prior to sampling prevents aliasing of the message signal.
The basic operations in the receiver section are regeneration of impaired signals,
decoding, and reconstruction of the quantized pulse train. Following is the block
diagram of PCM which represents the basic elements of both the transmitter and the
receiver sections.
Matlab Code:
clc;
close all;
clear all;
n=input('Enter n value for n-bit PCM system : ');
n1=input('Enter number of samples in a period : ');
L=2^n;
% % Signal Generation
% x=0:1/100:4*pi;
% y=8*sin(x);
% Amplitude Of signal is 8v
% subplot(2,2,1);
% plot(x,y);grid on;
% Sampling Operation
x=0:2*pi/n1:4*pi;
% n1 number of samples have to be selected
s=8*sin(x);
subplot(3,1,1);
plot(s);
title('Analog Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(3,1,2);
stem(s);grid on; title('Sampled Sinal');
ylabel('Amplitude--->'); xlabel('Time--->');
% Quantization Process
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L
part=vmin:del:vmax; % level
are between vmin and vmax with difference of del
code=vmin-(del/2):del:vmax+(del/2);
% Contaion Quantized values
[ind,q]=quantiz(s,part,code); %
Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);

for i=1:l1
if(ind(i)~=0) % To
make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==vmin-(del/2))
% To make quantize value inbetween the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);grid on; % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

% Encoding Process
figure
code=de2bi(ind,'left-msb');
% Convert the decimal to binary
k=1;
for i=1:l1
for j=1:n
coded(k)=code(i,j);
% convert code matrix to a coded row vector
j=j+1;
k=k+1;
end
i=i+1;
end
subplot(2,1,1); grid on;
stairs(coded); % Display the encoded signal
axis([0 100 -2 3]); title('Encoded Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
% Demodulation Of PCM signal

qunt=reshape(coded,n,length(coded)/n);
index=bi2de(qunt','left-msb');
% Getback the index in decimal form
q=del*index+vmin+(del/2);
% getback Quantized values
subplot(2,1,2); grid on;
plot(q); % Plot Demodulated signal
title('Demodulated Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

Output:
Conclusion:
The demodulation and modulation of pulse code modulation is plotted.
Advantages:
o The PCM convenient for long distance communication.
o It has a higher transmitter efficiency.
o It has a higher noise immunity.

Disadvantages:
o The PCM (pulse code modulation) requires large bandwidth as compared to
analog system.
o Encoding, decoding and quantizing circuit of PCM is very complex.

Applications:
o The PCM is used in the satellite transmission system.
o It is used in space communication.
o It is used in telephony.
o The compact disc (CD) is a recent application of PCM.
EXPERIMENT NO:4

Aim:Write a program for Adaptive Delta Modulation

Software used:Matlab

Theory:

A larger step-size is needed in the steep slope of modulating signal and a smaller
stepsize is needed where the message has a small slope. The minute details get
missed in the process. So, it would be better if we can control the adjustment of
step-size, according to our requirement in order to obtain the sampling in a desired
fashion. This is the concept of Adaptive Delta Modulation.

Following is the block diagram of Adaptive delta modulator.

The gain of the voltage controlled amplifier is adjusted by the output signal from the
sampler. The amplifier gain determines the step-size and both are proportional.
ADM quantizes the difference between the value of the current sample and the
predicted value of the next sample. It uses a variable step height to predict the next
values, for the faithful reproduction of the fast varying values.
Matlab Code:
% define the input signal
t=0:2*pi/100:2*pi;
A=10;
x=A*sin(t);

%plot the original signal


plot(x)
hold on

% calling the adaptive delta modulation function


ADMout = adeltamod(x, 1, 0.1,0.3);
plot(ADMout);
% The working of the Advanced Delta Modulator is similar
to the regular
% Delta Modulator. The only difference is that the amplitude
step
% size is variable and it keeps getting doubled if the
previous output/s
% don't seem to 'catch up' with the input signal. This
problem is
% referred to as 'Slope overload' in textbooks.

function [ADMout] = adeltamod(sig_in, Delta, td, ts)


% Usage
% ADMout = adeltamod(sig_in, Delta, fs);
% Delta -- min. step size. This will be multiplied 2nX if
required
% sig_in -- the signal input, should be a vector
% td -- the original sampling period of the input signal,
sig_in
% ts -- the required sampling period for ADM output. Note
that it
% should be an integral multiple of the input
signal's period.
% If not, it will be rounded up to the nearest
integer.
% Function output: ADMout

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)

% do nothing

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:

Conclusion:
The Adaptive Delta Modulation signal is plotted.
Advantages:
o Adaptive delta modulation decreases slope error present in delta modulation.
o During demodulation, it uses a low pass filter which removes the quantized
noise.
o The slope overload error and granular error present in delta modulation are
solved using this modulation. Because of this, the signal to noise ratio of this
modulation is better than delta modulation.
o In the presence of bit errors, this modulation provides robust performance.
This reduces the need for error detection and correction circuits in radio
design.
o The dynamic range of Adaptive delta modulation is large as the variable step
size covers large range of values.
Disadvantages:

o For a relatively constant magnitude of input signal x(t), the system will
produce high granular noise.
o Lower bit rate than PCM.

Applications:

This modulation is used for a system which requires improved wireless


voice quality as well as speed transfer of bits. In television signal
transmission this modulation process is used. This modulation method is
used in voice coding.
EXPERIMENT NO:5

Aim:Write a program for delta modulation.

Software Used:Matlab

Theory:

The type of modulation, where the sampling rate is much higher and in which the
stepsize after quantization is of a smaller value Δ, such a modulation is termed
as delta modulation.

Features of Delta Modulation

Following are some of the features of delta modulation.


o An over-sampled input is taken to make full use of the signal correlation.
o The quantization design is simple.
o The input sequence is much higher than the Nyquist rate.
o The quality is moderate.
o The design of the modulator and the demodulator is simple.
o The stair-case approximation of output waveform.
o The step-size is very small, i.e., Δ delta
o The bit rate can be decided by the user.
o This involves simpler implementation.
Delta Modulation is a simplified form of DPCM technique, also viewed as 1-bit
DPCM scheme. As the sampling interval is reduced, the signal correlation will be
higher.

Delta Modulator

The Delta Modulator comprises of a 1-bit quantizer and a delay circuit along with
two summer circuits. Following is the block diagram of a delta modulator.
From the above diagram, we have the notations as −
o x(nTs) = over sampled input
o ep(nTs)= summer output and quantizer input
o eq(nTs)= quantizer output = v(nTs)
o xˆ(nTs) = output of delay circuit
o u(nTs) = input of delay circuit

ep(nTs)=x(nTs)−xˆ(nTs)---------equation 1
=x(nTs)−u([n−1]Ts)
=x(nTs)−[xˆ[[n−1]Ts]+v[[n−1]Ts]]---------equation 2
Further,
v(nTs)=eq(nTs)=S.sig.[ep(nTs)]---------equation 3
u(nTs)=xˆ(nTs)+eq(nTs)
Where,
xˆ(nTs) = the previous value of the delay circuit
eq(nTs)= quantizer output = v(nTs)

Hence,
u(nTs)=u([n−1]Ts)+v(nTs)---------equation 4
Which means,
The present input of the delay unit
= The previous output of the delay unit + the present quantizer output
Assuming zero condition of Accumulation,
Accumulated version of DM output is

- -------equation 5
Now, note that
xˆ(nTs)=u([n−1]Ts)

---------equation 6
Delay unit output is an Accumulator output lagging by one sample.
From equations 5 & 6, we get a possible structure for the demodulator.
A Stair-case approximated waveform will be the output of the delta modulator with
the step-size as delta (Δ). The output quality of the waveform is moderate.

Delta Demodulator

The delta demodulator comprises of a low pass filter, a summer, and a delay circuit.
The predictor circuit is eliminated here and hence no assumed input is given to the
demodulator.
Following is the diagram for delta demodulator.
From the above diagram, we have the notations as −
o vˆ(nTs) is the input sample
o uˆ(nTs) is the summer output
o x¯(nTs) is the delayed output
A binary sequence will be given as an input to the demodulator. The stair-case
approximated output is given to the LPF.
Low pass filter is used for many reasons, but the prominent reason is noise
elimination for out-of-band signals. The step-size error that may occur at the
transmitter is called granular noise, which is eliminated here. If there is no noise
present, then the modulator output equals the demodulator input.

Matlab Code:

%delta modulation = 1-bit differential pulse code modulation


(DPCM)
predictor = [0 1]; % y(k)=x(k-1)
%partition = [-1:.1:.9];codebook = [-1:.1:1];
step=0.2; %SFs>=2pifA
partition = [0];codebook = [-1*step step]; %DM quantizer

t = [0:pi/20:2*pi];
x = 1.1*sin(2*pi*0.1*t); % Original signal, a sine wave
%t = [0:0.1:2*pi];x = 4*sin(t);
%x=exp(-1/3*t);
%x = sawtooth(3*t); % Original signal

% Quantize x(t) using DPCM.


encodedx = dpcmenco(x,codebook,partition,predictor);

% Try to recover x from the modulated signal.


decodedx = dpcmdeco(encodedx,codebook,predictor);
distor = sum((x-decodedx).^2)/length(x) % Mean square error

% plots
figure,subplot(2,2,1);plot(t,x);xlabel('time');title('ori
ginal signal');
subplot(2,2,2);stairs(t,10*codebook(encodedx+1),'--');xla
bel('time');title('DM output');
subplot(2,2,3);plot(t,x);hold;stairs(t,decodedx);grid;xla
bel('time');title('received signal');
Output:

Conclusion:

Delta Modulation is performed.

Advantages
o Since, the delta modulation transmits only one bit for one sample, therefore
the signaling rate and transmission channel bandwidth is quite small for delta
modulation compared to PCM .
o The transmitter and receiver implementation is very much simple for delta
modulation. There is no analog to digital converter required in delta
modulation.

Disadvantages:

o Slope overload distortion


o Granular or idle noise
EXPERIMENT NO:6

Aim:Write a program for Root Raised Cosine Pulse Generation

Software used:Matlab

Theory:

A root-raised-cosine filter (RRC), sometimes known as square-root-raised-cosine


filter (SRRC), is frequently used as the transmit and receive filter in a digital
communication system to perform matched filtering. This helps in
minimizing intersymbol interference (ISI). The combined response of two such filters
is that of the raised-cosine filter. It obtains its name from the fact that its frequency
response, is the square root of the frequency response of the raised-cosine filter.

Why is it required?

To have minimum ISI (Intersymbol interference), the overall response of transmit


filter, channel response and receive filter has to satisfy Nyquist ISI criterion.
The raised-cosine filter is the most popular filter response satisfying this criterion.
Half of this filtering is done on the transmit side and half is done on the receive side.
On the receive side, the channel response, if it can be accurately estimated, can also
be taken into account so that the overall response is that of a raised-cosine filter.
The RRC filter is characterised by two values: the roll-off factor and the reciprocal of
the symbol-rate.
The impulse response of such a filter can be given as:

where

- The roll off factor


Ts - The reciprocal of the symbol rate
Matlab Code:

sig = randi([0 1],1024,1); % This would generate random data


of {0, 1}

sig = round(2*(sig - 0.5)); % This is to convert the data {0,1}


into {-1,1}

upsample=8;

num = rcosine(1,upsample,'sqrt'); % Transfer function of


filter

% This function performs two procedures in a single step. First


it upsample the input data(sig) and filter it with rrc filter
(num)

sig_rrc = rcosflt(sig,1,upsample,'filter',num);

% This is to perform fft. nextpow2() returns the number which


is power of 2 and nearest to the number of input data.

% fftshift rotate the fft data so that the peak is located


at the center of the spectrum.

Lsig = length(sig);

Lsig_rrc = length(sig_rrc);

NFFTsig = 2^nextpow2(Lsig);

NFFTsig_rrc = 2^nextpow2(Lsig_rrc);

sigfft=fftshift(fft(sig,NFFTsig)/Lsig);

sig_rrcfft=fftshift(fft(sig_rrc,NFFTsig_rrc)/Lsig_rrc);

% This is to convert the fft result into dB scale.

sigfft_dB = 20*log10(abs(sigfft));

sig_rrcfft_dB = 20*log10(abs(sig_rrcfft));

% this is for plotting the original data and filtered data


and frequency spectrum

plotRange_tsig = 1:50;

plotRange_tsig_rrc = 1:(50*upsample);
subplot(2,2,1);plot(sig(plotRange_tsig));
axis([1 length(plotRange_tsig) -1.2 1.2]);
title('original data');
subplot(2,2,2);plot(sigfft_dB);
axis([0 length(sigfft_dB) -100 0]);
title('FFT for original data');
subplot(2,2,3);
plot(sig_rrc(plotRange_tsig_rrc));
axis([1 length(plotRange_tsig_rrc) -1.2 1.2]);
title('upsampled and filtered data');
subplot(2,2,4);
plot(sig_rrcfft_dB);
axis([0 length(sig_rrcfft_dB) -100 0]);
title('FFT for upsampled and filtered data');

Output:

Conclusion:

RRC filter is performed using Matlab.


EXPERIMENT NO:7

Aim:Write a program for Binary Phase Shift Key modulation and demodulation.

Software used:Matlab

Theory:

Phase Shift Keying PSK is the digital modulation technique in which the phase of
the carrier signal is changed by varying the sine and cosine inputs at a particular time.
PSK technique is widely used for wireless LANs, bio-metric, contactless operations,
along with RFID and Bluetooth communications.

Binary Phase Shift Keying BPSK

This is also called as 2-phase PSK or Phase Reversal Keying. In this technique, the
sine wave carrier takes two phase reversals such as 0° and 180°.
BPSK is basically a Double Side Band Suppressed Carrier DSBSC modulation
scheme, for message being the digital information.

BPSK Modulator

The block diagram of Binary Phase Shift Keying consists of the balance modulator
which has the carrier sine wave as one input and the binary sequence as the other
input. Following is the diagrammatic representation.
The modulation of BPSK is done using a balance modulator, which multiplies the
two signals applied at the input. For a zero binary input, the phase will be 0° and for
a high input, the phase reversal is of 180°.
Following is the diagrammatic representation of BPSK Modulated output wave
along with its given input.

The output sine wave of the modulator will be the direct input carrier or the
inverted 180°phase shifted input carrier, which is a function of the data signal.

BPSK Demodulator

The block diagram of BPSK demodulator consists of a mixer with local oscillator
circuit, a bandpass filter, a two-input detector circuit. The diagram is as follows.
By recovering the band-limited message signal, with the help of the mixer circuit
and the band pass filter, the first stage of demodulation gets completed. The base
band signal which is band limited is obtained and this signal is used to regenerate the
binary message bit stream.
In the next stage of demodulation, the bit clock rate is needed at the detector circuit
to produce the original binary message signal. If the bit rate is a sub-multiple of the
carrier frequency, then the bit clock regeneration is simplified. To make the circuit
easily understandable, a decision-making circuit may also be inserted at the
2nd stage of detection.

Matlab Code:
% ********************* BPSK modulation and de-modulation
****************%
clc;
clear all;
close all;
% ********************* Define transmitted signal
*************************
N=10; % Number of bits , size of transmitted signal x_inp=[x_1
x_2...x_N]
x_inp =randi([0,1],1,N); % binary signal 0 or 1 % message
Tb=0.0001; % bit period (second)
% ********************* Represent input signal as digital
signal ****
x_bit=[];
nb=100; % bbit/bit
for n=1:1:N %
if x_inp(n)==1; %
x_bitt=ones(1,nb);
else x_inp(n)==0;
x_bitt=zeros(1,nb);
end
x_bit=[x_bit x_bitt];
end
t1=Tb/nb:Tb/nb:nb*N*(Tb/nb); % time of the signal
f1 = figure(1);
set(f1,'color',[1 1 1]);
subplot(3,1,1);
plot(t1,x_bit,'lineWidth',2);grid on;
axis([ 0 Tb*N -0.5 1.5]);
ylabel('Tmplitude(volt)');
xlabel(' Time(sec)');
title('Input signal as digital signal');
% ********************* Define BFSK Modulation
****************************
Ac=5; % Amplitude of carrier signal
mc=4; % fc>>fs fc=mc*fs fs=1/Tb
fc=mc*(1/Tb); % carrier frequency for bit 1
fi1=0; % carrier phase for bit 1
fi2=pi; % carrier phase for bit 0
t2=Tb/nb:Tb/nb:Tb;
t2L=length(t2);
x_mod=[];
for (i=1:1:N)
if (x_inp(i)==1)
x_mod0=Ac*cos(2*pi*fc*t2+fi1);%modulation signal with
carrier signal 1
else
x_mod0=Ac*cos(2*pi*fc*t2+fi2);%modulation signal with
carrier signal 2
end
x_mod=[x_mod x_mod0];
end
t3=Tb/nb:Tb/nb:Tb*N;
subplot(3,1,2);
plot(t3,x_mod);
xlabel('Time(sec)');
ylabel('Amplitude(volt)');
title('Signal of modulation ');
% ********************* Transmitted signal x
******************************
x=x_mod;
% ********************* Channel model h and w
*****************************
h=1; % Fading
w=0; % Noise
% ********************* Received signal y
*********************************
y=h.*x+w;
% ********************* Define BPSK Demodulation
**************************
y_dem=[];
for n=t2L:t2L:length(y)
t=Tb/nb:Tb/nb:Tb;
c=cos(2*pi*fc*t); % carrier siignal
y_dem0=c.*y((n-(t2L-1)):n);
t4=Tb/nb:Tb/nb:Tb;
z=trapz(t4,y_dem0); % intregation
A_dem=round((2*z/Tb));
if(A_dem>Ac/2) % logic level = Ac/2
A=1;
else
A=0;
end
y_dem=[y_dem A];
end
x_out=y_dem; % output signal;
% *************** Represent output signal as digital signal
***************
xx_bit=[];
for n=1:length(x_out);
if x_out(n)==1;
xx_bitt=ones(1,nb);
else x_out(n)==0;
xx_bitt=zeros(1,nb);
end
xx_bit=[xx_bit xx_bitt];
end
t4=Tb/nb:Tb/nb:nb*length(x_out)*(Tb/nb);
subplot(3,1,3)
plot(t4,xx_bit,'LineWidth',2);grid on;
axis([ 0 Tb*length(x_out) -0.5 1.5]);
ylabel('Amplitude(volt)');
xlabel(' Time(sec)');
title('Output signal as digital signal');
% **************************** end of pro
Output:

Conclusion:

The BPSK modulation and Demodulation is observed.

Advantages:

1) It is most robust modulation technique due to the fact that binary 1 and 0 are
separated by 180 degree phase shift of the carrier. Due to this property, BPSK
modulated data can travel longer distances when transmitted from base station or
subscriber stations. Hence BPSK modulation is employed in pilot carrier as well as in
preamble sequences. These are used for time/frequency synchronization and channel
estimation/equalization purpose.

2) Due to above, BPSK modulation is used by most of the cellular towers for long
distance communication or transmission of the data.

3) BPSK demodulator requires to make only two decisions in order to recover


original binary information. Hence BPSK receiver is very simple compare to other
modulation types.

4) BPSK is power efficient modulation technique as less power is needed to


transmit the carrier with less number of bits.
Disadvantages:
1) In BPSK modulation, one bit is carried by one single analog carrier. Hence data
rate in bits per second is same as the symbol rate. This is half in comparison to the
QPSK modulation technique and many times less compare to other higher
modulation techniques such as 16QAM, 64QAM etc.

2) Due to above reason, BPSK is not bandwidth efficient modulation technique


compare to other modulation types
EXPERIMENT NO:8

Aim:Write a program for Binary Frequency Shift Key Modulation and demodulation.

Software used:Matlab

Theory:

Frequency Shift Keying FSK is the digital modulation technique in which the
frequency of the carrier signal varies according to the digital signal changes. FSK is
a scheme of frequency modulation.
The output of a FSK modulated wave is high in frequency for a binary High input
and is low in frequency for a binary Low input. The binary 1s and 0s are called
Mark and Space frequencies.
The following image is the diagrammatic representation of FSK modulated
waveform along with its input.

FSK Modulator

The FSK modulator block diagram comprises of two oscillators with a clock and the
input binary sequence. Following is its block diagram.
The two oscillators, producing a higher and a lower frequency signals, are connected
to a switch along with an internal clock. To avoid the abrupt phase discontinuities of
the output waveform during the transmission of the message, a clock is applied to
both the oscillators, internally. The binary input sequence is applied to the
transmitter so as to choose the frequencies according to the binary input.

FSK Demodulator

There are different methods for demodulating a FSK wave. The main methods of
FSK detection are asynchronous detector and synchronous detector. The
synchronous detector is a coherent one, while asynchronous detector is a
non-coherent one.

Asynchronous FSK Detector

The block diagram of Asynchronous FSK detector consists of two band pass filters,
two envelope detectors, and a decision circuit. Following is the diagrammatic
representation.
The FSK signal is passed through the two Band Pass Filters BPFsBPFs, tuned
to Space and Mark frequencies. The output from these two BPFs look like ASK
signal, which is given to the envelope detector. The signal in each envelope detector
is modulated asynchronously.
The decision circuit chooses which output is more likely and selects it from any one
of the envelope detectors. It also re-shapes the waveform to a rectangular one.

Synchronous FSK Detector

The block diagram of Synchronous FSK detector consists of two mixers with local
oscillator circuits, two band pass filters and a decision circuit. Following is the
diagrammatic representation.

The FSK signal input is given to the two mixers with local oscillator circuits. These
two are connected to two band pass filters. These combinations act as demodulators
and the decision circuit chooses which output is more likely and selects it from any
one of the detectors. The two signals have a minimum frequency separation.
For both of the demodulators, the bandwidth of each of them depends on their bit
rate. This synchronous demodulator is a bit complex than asynchronous type
demodulators.
Matlab Code:

%>>>>>>>>> MATLAB code for binary FSK modulation and


demodulation >>>>>>>%
clc;
clear all;
close all;
x=[ 1 0 0 1 1 0 1]; % Binary Information
bp=.000001;
% bit period
disp(' Binary information at Trans mitter :');
disp(x);
%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(3,1,1);
plot(t1,bit,'lineWidth',2.5);grid on;
axis([ 0 bp*length(x) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('transmitting information as digital signal');
%XXXXXXXXXXXXXXXXXXXXXXX Binary-FSK modulation
XXXXXXXXXXXXXXXXXXXXXXXXXXX%
A=5; % Amplitude of carrier signal
br=1/bp;
% bit rate
f1=br*8; % 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(3,1,2);
plot(t3,m);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('waveform for binary FSK modulation coresponding
binary information');
%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 siignal for information 1
y2=cos(2*pi*f2*t); % carrier siignal 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)
% intregation
z2=trapz(t4,mmm)
% intregation
zz1=round(2*z1/bp)
zz2= round(2*z2/bp)
if(zz1>A/2) % logic lavel= (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 Reciver :');
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(3,1,3)
plot(t4,bit,'LineWidth',2.5);grid on;
axis([ 0 bp*length(mn) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('recived information as digital signal after binary FSK
demodulation');
Output:

Conclusion:

The BFSK modulation and demodulation is performed.

Advantages
 Simple process to construct the circuit
 Zero amplitude variations
 Supports a high data rate.
 Low probability of error.
 High SNR (signal to noise ratio).
 More noise immunity than the ASK
 Error-free reception can be possible with FSK
 Useful in high-frequency radio transmissions
 Preferable in high-frequency communications
 Low-speed digital applications

Disadvantages
 It requires more bandwidth than the ASK and PSK(phase shift keying)
 Due to the requirement of large bandwidth, this FSK has limitations to use only
in low-speed modems which the bit rate is 1200bits/sec.
 The bit error rate is less in AEGN channel than phase shift keying.
EXPERIMENT NO:9
Aim:Write a program for minimum shift key modulation.

Software Used:Matlab

Theory:

MSK, Minimum Shift Keying is a form of continuous phase frequency shift keying,
providing spectrum efficiency & enabling efficient RF power amplifier
operation.MSK offers advantages in terms of spectral efficiency when compared to
other similar modes, and it also enables power amplifiers to operate in saturaton
enabling them to provide high levels of efficiency.
It is found that binary data consisting of sharp transitions between "one" and "zero"
states and vice versa potentially creates signals that have sidebands extending out a
long way from the carrier, and this creates problems for many radio communications
systems, as any sidebands outside the allowed bandwidth cause interference to
adjacent channels and any radio communications links that may be using them.
MSK, minimum shift keying has the feature that there are no phase discontinuities
and this significantly reduces the bandwidth needed over other forms of phase and
frequency shift keying.
Minimum Shift Keying, MSK basics
The problem can be overcome in part by filtering the signal, but is found that the
transitions in the data become progressively less sharp as the level of filtering is
increased and the bandwidth reduced. To overcome this problem GMSK is often used
and this is based on Minimum Shift Keying, MSK modulation. The advantage of
which is what is known as a continuous phase scheme. Here there are no phase
discontinuities because the frequency changes occur at the carrier zero crossing
points.
When looking at a plot of a signal using MSK modulation, it can be seen that the
modulating data signal changes the frequency of the signal and there are no phase
discontinuities. This arises as a result of the unique factor of MSK that the frequency
difference between the logical one and logical zero states is always equal to half the
data rate. This can be expressed in terms of the modulation index, and it is always
equal to 0.5.
MSK is a particularly effective form of modulation where data communications is
required. Although QAM and PSK are used for many other systems, MSK is able to
provide relatively efficient spectrum usage. As it is a form of frequency modulation,
this enables RF power amplifiers to operate in saturation, thereby enabling them to
operate as efficiently as possible. If amplitude variations are present these need to be
preserved and amplifiers cannot run in saturation and this significantly limits the
efficiency levels attainable.

Matlab Code:

clear
N = 5*10^5; % number of bits or symbols
fsHz = 1; % sampling period
T = 4; % symbol duration
Eb_N0_dB = [0:10]; % multiple Eb/N0 values
ct = cos(pi*[-T:N*T-1]/(2*T));
st = sin(pi*[-T:N*T-1]/(2*T));
for ii = 1:length(Eb_N0_dB)
% MSK Transmitter
ipBit = rand(1,N)>0.5;
% generating 0,1 with equal probability
ipMod = 2*ipBit - 1; % BPSK modulation 0 -> -1, 1 -> 0
ai = kron(ipMod(1:2:end),ones(1,2*T)); % even bits
aq = kron(ipMod(2:2:end),ones(1,2*T)); % odd bits
ai = [ai zeros(1,T) ];
% padding with zero to make the matrix dimension match
aq = [zeros(1,T) aq ]; % adding delay of T for Q-arm

% MSK transmit waveform


xt = 1/sqrt(T)*[ai.*ct + j*aq.*st];
% Additive White Gaussian Noise
nt = 1/sqrt(2)*[randn(1,N*T+T) + j*randn(1,N*T+T)];
% white gaussian noise, 0dB variance
% Noise addition
yt = xt + 10^(-Eb_N0_dB(ii)/20)*nt;
% additive white gaussian noise
%% MSK receiver
% multiplying with cosine and sine waveforms
xE = conv(real(yt).*ct,ones(1,2*T));
xO = conv(imag(yt).*st,ones(1,2*T));
bHat = zeros(1,N);
bHat(1:2:end) = xE(2*T+1:2*T:end-2*T) > 0 ; % even bits
bHat(2:2:end) = xO(3*T+1:2*T:end-T) > 0 ; % odd bits
% counting the errors
nErr(ii) = size(find([ipBit - bHat]),2);
end
simBer = nErr/N; % simulated ber
theoryBer = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); %
theoretical ber
% plot
close all
figure
semilogy(Eb_N0_dB,theoryBer,'bs-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,simBer,'mx-','LineWidth',2);
axis([0 10 10^-5 0.5])
grid on
legend('theory - bpsk', 'simulation - msk');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('Bit error probability curve for MSK modulation');

Output:
Conclusion:

The MSK modulation is performed.


Advantages
1) The sidebands of PSK modulated spectrum is minimized by this modulation
technique. Hence sideband power is reduced.
2) The MSK or GMSK spectrum is less affected by noise and hence leads to good
SNR. This helps in achieving very stable and long distance communication. Due to
this fact, the GMSK modulation technique is being employed in GSM technology.
3) Above fact, helps in achieving good receiver sensitivity.
4) PAPR is maintained low due to no phase continuities and occurrence of frequency
changes at zero cross over of RF carrier. Due to this, highly linear PA (Power
Amplifier) is not required.
5) Spectral efficiency is better and higher while demodulator is less complex.
6) GMSK provides constant envelope over the entire bandwidth. Hence it offers
excellent power efficiency.
7) It provides good BER performance.
8) GMSK offers self synchronizing capabilities.
9) GMSK is good choice for voice modulation.

Disadvantages
1) PSD of MSK does not fall fast and hence Interference between adjacent channels
is observed. GMSK uses BT of 0.3 and hence good rejection can be achieved
between adjacent channels. Here B is 3dB bandwidth of shaping filter and T is bit
duration.
2) Both MSK and GMSK requires more power to transmit data compare to other
modulation types such as QPSK.
3) It requires complex channel equalization algorithms e.g. adaptive equalizer at
receiver.
4) Inter symbol interference may occur.

You might also like