0% found this document useful (0 votes)
7 views6 pages

MATLAB Codes for Digital Modulation Techniques

The document contains an assignment for a Computer Communications and Networking course, focusing on Digital-To-Analog Conversion using MATLAB. It includes MATLAB code examples for generating signals using Amplitude Shift Keying (ASK), Frequency Shift Keying (FSK), and Phase Shift Keying (PSK), along with instructions for plotting the resulting waveforms. Each section provides code snippets that input a digital data stream and visualize the corresponding modulated signals.

Uploaded by

zeeshan291712
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

MATLAB Codes for Digital Modulation Techniques

The document contains an assignment for a Computer Communications and Networking course, focusing on Digital-To-Analog Conversion using MATLAB. It includes MATLAB code examples for generating signals using Amplitude Shift Keying (ASK), Frequency Shift Keying (FSK), and Phase Shift Keying (PSK), along with instructions for plotting the resulting waveforms. Each section provides code snippets that input a digital data stream and visualize the corresponding modulated signals.

Uploaded by

zeeshan291712
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

University of

Engineering &
Technology, Taxila

Computer Communications
And Networking (CCN)

Assignment # 02
Digital-To-Analog Conversion

Name : Zeeshan Haider


Roll No : 21-CP-24
Section : Omega
Semester : 5th
Submitted To : Sir Aasim Raheel
1. Write a MATLAB code that inputs a digital data and generate a signal using
ASK.
MATLAB Code:

% Input binary bit stream (e.g., [0 1 0 1 1 1 0])


bitStream = input('Enter the Bit stream: ');
n = length(bitStream);
timeIncrement = 0.01;
t = 0:timeIncrement:n;
% Initialize an index vector for bit waveforms
x = 1:1:(n+1)*100;
% Initialize an empty array for the bit waveform
bitWaveform = zeros(1, length(t));
% Generate the bit waveform based on the input bit stream
for i = 1:n
for j = i:timeIncrement:i+1
bitWaveform(x(i*100:(i+1)*100)) = bitStream(i);
end
end
% Remove the initial portion to match the length of t
bitWaveform = bitWaveform(100:end);

% Generate a sinusoidal carrier waveform


sineWave = sin(2*pi*t);

% Modulate the carrier with the bit waveform to create the output signal
modulatedSignal = bitWaveform .* sineWave;

% Plot the bit waveform


subplot(3, 1, 1)
plot(t, bitWaveform)
xlabel('Time')
ylabel('Amplitude')
title('Bit Waveform')
grid on
axis([0 n -2 +2])

% Plot the carrier (sine wave)


subplot(3, 1, 2)
plot(t, sineWave)
xlabel('Time')
ylabel('Amplitude')
title('Carrier (Sine Wave)')
grid on
axis([0 n -2 +2])

% Plot the modulated signal


subplot(3, 1, 3)
plot(t, modulatedSignal)
xlabel('Time')
ylabel('Amplitude')
title('Modulated Signal')
grid on
axis([0 n -2 +2])
MATLAB Output:

2. Write a MATLAB code that inputs a digital data and generate a signal using
FSK.

MATLAB Code:
% Input binary bit stream
bitStream = input('Enter the Bit stream : ');

% Get the length of the bit stream


n = length(bitStream);

% Define time vector


t = 0:0.01:n;

% Initialize an index variable for creating the bandwidth signal


x = 1:1:(n+1)*100;

% Initialize an array for the bipolar signal


bipolarSignal = zeros(1, n);

% Convert binary bits to bipolar (0 to -1, 1 to 1)


for i = 1:n
if (bitStream(i) == 0)
bipolarSignal(i) = -1;
else
bipolarSignal(i) = 1;
end

% Create the bandwidth signal over each bit duration


for j = i:.1:i+1
bandwidthSignal(x(i*100:(i+1)*100)) = bipolarSignal(i);
end
end

% Remove the initial 100 samples to match the time vector


bandwidthSignal = bandwidthSignal(100:end);

% Define angular frequencies


wo = 2 * (2 * pi * t);
W = 1 * (2 * pi * t);

% Generate signals
sinHt = sin(wo + W); % High-frequency component
sinLt = sin(wo - W); % Low-frequency component
modulatedSignal = sin(wo + (bandwidthSignal) .* W); % Modulated signal

% Plot the signals for better understanding


subplot(4, 1, 1)
plot(t, bandwidthSignal)
xlabel('Time')
ylabel('Amplitude')
title('Bandwidth Signal')
grid on
axis([0 n -2 +2])

subplot(4, 1, 2)
plot(t, sinHt)
xlabel('Time')
ylabel('Amplitude')
title('High-Frequency Component')
grid on
axis([0 n -1 +1])

subplot(4, 1, 3)
plot(t, sinLt)
xlabel('Time')
ylabel('Amplitude')
title('Low-Frequency Component')
grid on
axis([0 n -2 +2])

subplot(4, 1, 4)
plot(t, modulatedSignal)
xlabel('Time')
ylabel('Amplitude')
title('FSK Modulated Signal')
grid on
axis([0 n -2 +2])
MATLAB Output:

3. Write a MATLAB code that inputs a digital data and generate a signal using
PSK.

MATLAB Code:
b = input('Enter the Bit stream \n '); %b = [0 1 0 1 1 1 0];
n = length(b);
t = 0:.01:n;
x = 1:1:(n+1)*100;
for i = 1:n
if (b(i) == 0)
b_p(i) = -1;
else
b_p(i) = 1;
end
for j = i:.1:i+1
bw(x(i*100:(i+1)*100)) = b_p(i);
end
end
bw = bw(100:end);
sint = sin(2*pi*t);
st = bw.*sint;
subplot(3,1,1)
plot(t,sint)
xlabel('Time')
ylabel('Amplitude')
title('Carrier')
grid on ; axis([0 n -2 +2])

subplot(3,1,2)
plot(t,bw)
%xlabel('Time')
%ylabel('Amplitude')
title('Message Sinal')
grid on ; axis([0 n -2 +2])

subplot(3,1,3)
plot(t,st)
xlabel('Time')
ylabel('Amplitude')
title('PSK')
grid on ; axis([0 n -2 +2])

MATLAB Output:

You might also like