0% found this document useful (0 votes)
1 views24 pages

Matlab Manual Draft1

The document outlines a series of MATLAB programs designed for a Principles of Communication Systems Lab at GEC Hassan. It covers the generation and analysis of various basic signals, modulation techniques, sampling, and multiplexing, alongside their respective outputs and visualizations. Each section includes specific aims, code snippets, and expected results for practical understanding of communication systems.

Uploaded by

chinnudeepub
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)
1 views24 pages

Matlab Manual Draft1

The document outlines a series of MATLAB programs designed for a Principles of Communication Systems Lab at GEC Hassan. It covers the generation and analysis of various basic signals, modulation techniques, sampling, and multiplexing, alongside their respective outputs and visualizations. Each section includes specific aims, code snippets, and expected results for practical understanding of communication systems.

Uploaded by

chinnudeepub
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
You are on page 1/ 24

Pinciples Of Communication Systems Lab

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

1. Basic Signals and Signal Graphing: a) Unit Step, b) Rectangular, c) standard


triangle d) sinusoidal and e) Exponential signal.

AIM: To write a MATLAB program to generate basics signals as Unit Step,


Rectangular, Triangular, Sinusoidal, Exponential signal

%unit step function%


clc;
clear all;
close all;
N=100;
t=1:100;
x=ones(1,N);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('unit step function');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('unit step discreat function');

# OUTPUT :

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

% b) unit rectangle function%


clc;
clear all;
close all;
% Define the time range
t = -5:0.01:5;

% Define the unit rectangle function


unit_rectangle = @(t) (abs(t) <= 0.5);

% Evaluate the unit rectangle function


y = unit_rectangle(t);

% Plot the unit rectangle function


plot(t, y, 'LineWidth', 2);
xlabel('Time');
ylabel('Amplitude');
title('Unit Rectangle Function');
grid on;

# OUTPUT :

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

% c) triangular function%
clc;
clear all;
close all;
t=0:0.01:2;
x=sawtooth(2*pi*5*t,0.5);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
ylabel('amplitude');
title('trianguler signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('triangular sequence');

# OUTPUT :

% d) sinusoidal function%
clc;
clear all;
close all;
t=0:0.01:2;
x=sin(2*pi*t);
subplot(2,1,1);
plot(t,x,'g');
xlabel('time');
Department of ECE , GEC Hassan
Pinciples Of Communication Systems Lab

ylabel('amplitude');
title('sinusoidal signal');
subplot(2,1,2);
stem(t,x,'r');
xlabel('time');
ylabel('amplitude');
title('sinusoidal sequence');

# OUTPUT :

% e) Exponential Function%
clc;
clear all;
close all;
n=50;
s=0:1:n;
figure(1)
C1=0.95*(exp(j*(pi/10)).*s);
C2=0.95*(exp(j*(pi/10)).*s);
C=real(C1)+real(C2);
subplot(2,1,1);
plot(s,C,'b');
subplot(2,1,2);
stem(s, C)
xlabel('Sample Number n');
ylabel('Amplitude');
title('Exponential Signal');

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

#OUTPUT :

2. Illustration of signal representation in time and frequency domains for a


rectangular pulse

AIM : To write a MATLAB program to generate signal representation in time and


frequency domains for a rectangular pulse

% Illustration of Signal Representation in Time and Frequency Domains for a Rectangular


Pulse %
clc;
clear all;
close all;
% Parameters
Fs = 1000; % Sampling frequency (Hz)
T = 10/Fs; % Sampling period
duration = 1; % Duration of signal (seconds)
pulse_width = 0.1; % Width of rectangular pulse (seconds)
A = 1; % Amplitude

% Time vector
t = 0:T:duration-T;

% Generate rectangular pulse


x_rect = zeros(size(t));

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

x_rect(t < pulse_width) = A;

% Compute Fourier Transform


X_rect = fft(x_rect);
frequencies = linspace(0, Fs, length(X_rect));

% Plot the rectangular pulse in time domain


subplot(2, 1, 1);
plot(t, x_rect, 'b', 'LineWidth', 2);
title('Rectangular Pulse in Time Domain');
xlabel('Time (s)');
ylabel('Amplitude');

% Plot the magnitude of the Fourier Transform in frequency domain


subplot(2, 1, 2);
stem(frequencies, abs(X_rect), 'r', 'LineWidth', 2);
title('Magnitude of Fourier Transform in Frequency Domain');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0, Fs/2]);
% Adjust plot
grid on;

# OUTPUT :

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

3. Amplitude Modulation and demodulation: Generation and display the


relevant signals and its spectrums

AIM : To write a MATLAB program to generate Amplitude Modulation and


demodulation and display the relevant signals and its spectrums

% $$ %% AM Modulation and Demodulation using Functions in MATLAB


clc;
clear all;
close all;
%% Modulation index
h= 60;
%% Time Period of Simulation :
t = linspace(0, 0.2, 100000);

%% Message Signal :
Am = 14;
fm = 200;
ym = Am*cos(2*pi*fm*t);
figure;
subplot(4, 1, 1);
plot(t(1:10000), ym(1:10000));
title('Message Signal');
xlabel('time(t)');
ylabel('Amplitude');

%% Carrier Signal :
Ac = Am/h;
fc = 2000;
yc = Ac*cos(2*pi*fc*t);
subplot(4, 1, 2);
plot(t(1:10000), yc(1:10000));
title('Carrier Signal');
xlabel('time(t)');
ylabel('Amplitude');

%% Modulated Signal :
y = ammod(ym, fc, 100000, 0, Ac);
subplot(4, 1, 3);
plot(t(1:10000), y(1:10000));
title('Modulated Signal');
xlabel('time(t)');
ylabel('Amplitude');

%% Demodulated Signal :
z = amdemod(y, fc, 100000, 0, Ac);
subplot(4, 1, 4);
plot(t(1:10000), z(1:10000));
title('Demodulated Signal');
xlabel('time(t)');

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

ylabel('Amplitude');
ylim([-10, 10]);

# OUTPUT :

4. Frequency Modulation and demodulation: Generation and display the


relevant signals and its spectrums

AIM : To write a MATLAB program to generate Frequency Modulation and


demodulation and display the relevant signals and its spectrums

clc;
clear all;
close all;
t = 0:0.001:1; %upto 1000 samples
vm = input('Enter Amplitude (Message) = ');
vc = input('Enter Amplitude (Carrier) = ');
fM = input('Enter Message frequency = ');
fc = input('Enter Carrier frequency = ');
m = input('Enter Modulation Index = ');
msg = vm*sin(2*pi*fM*t);
subplot(3,1,1); %plotting message signal
Department of ECE , GEC Hassan
Pinciples Of Communication Systems Lab

plot(t,msg);
xlabel('Time');
ylabel('Amplitude');
title('Message ');

carrier = vc*sin(2*pi*fc*t);
subplot(3,1,2); %plotting carrier signal
plot(t,carrier);
xlabel('Time');
ylabel('Amplitude');
title('Carrier Signal');

y = vc*sin(2*pi*fc*t+m.*cos(2*pi*fM*t));
subplot(3,1,3); %plotting FM (Frequency Modulated) signal
plot(t,y);
xlabel('Time');
ylabel('Amplitude');
title('FM Signal');

# OUTPUT :
Sample MATLAB Input:
Enter Amplitude (Message) = 5
Enter Amplitude (Carrier) = 5
Enter Message frequency = 8
Enter Carrier frequency = 100
Enter Modulation Index = 10

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

5. Sampling and reconstruction of low pass signals. Display the signals and its
spectrum

AIM : To write a MATLAB program to generate Sampling and reconstruction of


low pass signals. Display the signals and its spectrum

% Sampling and Reconstruction of Low Pass Signals


clc;
clear all;
close all;
% Parameters
Fs = 1000; % Sampling frequency (Hz)
T = 1/Fs; % Sampling period
duration = 1; % Duration of signal (seconds)
f_signal = 50; % Signal frequency (Hz)
A_signal = 1; % Signal amplitude

% Time vector
t = 0:T:duration-T;

% Generate low-pass signal


x = A_signal * sin(2*pi*f_signal*t);

% Plot original signal and its spectrum


figure;

subplot(2, 2, 1);
plot(t, x, 'b', 'LineWidth', 2);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Compute and plot spectrum of original signal


X = fft(x);
frequencies = linspace(0, Fs, length(X));
subplot(2, 2, 2);
plot(frequencies, abs(X), 'b', 'LineWidth', 2);
title('Spectrum of Original Signal');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0, Fs/2]);

% Sampling
Fs_new = 200; % New sampling frequency (Hz)
T_new = 1/Fs_new; % New sampling period
t_new = 0:T_new:duration-T_new;
x_sampled = A_signal * sin(2*pi*f_signal*t_new);

% Plot sampled signal and its spectrum


subplot(2, 2, 3);

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

stem(t_new, x_sampled, 'r', 'LineWidth', 2);


title('Sampled Signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Compute and plot spectrum of sampled signal


X_sampled = fft(x_sampled);
frequencies_sampled = linspace(0, Fs_new, length(X_sampled));
subplot(2, 2, 4);
stem(frequencies_sampled, abs(X_sampled), 'r', 'LineWidth', 2);
title('Spectrum of Sampled Signal');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0, Fs_new/2]);
% Adjust plot
grid on;

# OUTPUT :

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

6. Time Division Multiplexing and demultiplexing

AIM : To write a MATLAB program to generate Time Division Multiplexing and


demultiplexing

% Number of signals to multiplex


numSignals = 3;

% Number of time slots


numSlots = 10;

% Generate random data for each signal


data = cell(1, numSignals);
for i = 1:numSignals
data{i} = randi([0, 100], 1, numSlots); % Generate random data for each signal
end

% Multiplexing (combining signals into one)


TDM_signal = zeros(1, numSlots*numSignals);
for i = 1:numSignals
TDM_signal((i-1)*numSlots+1:i*numSlots) = data{i};
end

% Display multiplexed signal


disp('Multiplexed Signal (TDM):');
disp(TDM_signal);

% Demultiplexing (separating signals)


demux_data = cell(1, numSignals);
for i = 1:numSignals
demux_data{i} = TDM_signal(i:numSignals:end); % Extract every nth element
end

% Display demultiplexed signals


for i = 1:numSignals
fprintf('Demultiplexed Signal %d:\n', i);
disp(demux_data{i});
end

# OUTPUT :

Multiplexed Signal (TDM):

Columns 1 through 25

82 91 12 92 63 9 28 55 96 97 15 98 96 49 80 14 42 92
80 96 66 3 85 94 68

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

Columns 26 through 30

76 75 39 66 17

Demultiplexed Signal 1:
82 92 28 97 96 14 80 3 68 39

Demultiplexed Signal 2:
91 63 55 15 49 42 96 85 76 66

Demultiplexed Signal 3:
12 9 96 98 80 92 66 94 75 17

7. PCM Illustration: Sampling, Quantization and Encoding

AIM: To write a MATLAB program to generate PCM Illustration: Sampling,


Quantization and Encoding

% PCM Illustration: Sampling, Quantization, and Encoding


% Parameters
Fs = 1000; % Sampling frequency (Hz)
T = 1/Fs; % Sampling period
t = 0:T:1-T; % Time vector for one second

% Analog signal (example: sine wave)


Analog_signal = sin(2*pi*5*t); % 5 Hz sine wave

% Plot analog signal


subplot(3,1,1);
plot(t, Analog_signal);
title('Analog Signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Sampling
nSamples = 10; % Number of samples
sampled_signal = Analog_signal(1:nSamples); % Downsample

% Plot sampled signal


stem((0:(nSamples-1))*T, sampled_signal);
title('Sampled Signal');
xlabel('Time (s)');
ylabel('Amplitude');

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

% Quantization
nBits = 4; % Number of bits for quantization
quantized_signal = round(sampled_signal * (2^(nBits-1) - 1));

% Plot quantized signal


subplot(3,1,3);
stem((0:nSamples-1)*T, quantized_signal);
title('Quantized Signal');
xlabel('Time (s)');
ylabel('Quantization Levels');

% Encoding (converting to binary)


binary_signal = de2bi(quantized_signal, nBits, 'left-msb');

% Display encoded signal


disp('Encoded Signal (Binary):');
disp(binary_signal);

# OUTPUT :

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

Encoded Signal (Binary):


0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 1
0 0 0 1
0 0 0 1
0 0 0 1
0 0 1 0
0 0 1 0
0 0 1 0

8. Generate a) NRZ, RZ and Raised cosine pulse, b) Generate and plot eye
diagram

% MATLAB Program to Generate and Plot an NRZ Signal


% Define the binary data sequence
data = [1 0 1 1 0 0 1 0 1]; % Example binary sequence

% Parameters for the signal


bit_rate = 1; % bits per second
bit_duration = 1 / bit_rate; % duration of one bit in seconds
samples_per_bit = 100; % number of samples per bit

% Time vector for one bit


t_bit = linspace(0, bit_duration, samples_per_bit);

% Initialize the NRZ signal vector


nrz_signal = [];

% Generate the NRZ signal


for bit = data
if bit == 1
nrz_signal = [nrz_signal ones(1, samples_per_bit)];
else
nrz_signal = [nrz_signal zeros(1, samples_per_bit)];
end
end

% Time vector for the entire signal


t = linspace(0, bit_duration * length(data), length(nrz_signal));

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

% Plot the NRZ signal


figure;
plot(t, nrz_signal, 'LineWidth', 2);
ylim([-0.5 1.5]);
xlabel('Time (s)');
ylabel('Amplitude');
title('NRZ Signal');
grid on;

# OUTPUT :

% MATLAB Program to Generate and Plot an RZ Signal


% Define the binary data sequence
data = [1 0 1 1 0 0 1 0 1]; % Example binary sequence

% Parameters for the signal


bit_rate = 1; % bits per second
bit_duration = 1 / bit_rate; % duration of one bit in seconds
samples_per_bit = 100; % number of samples per bit
half_bit_samples = samples_per_bit / 2; % samples for half bit duration

% Time vector for one bit


t_bit = linspace(0, bit_duration, samples_per_bit);

% Initialize the RZ signal vector

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

rz_signal = [];

% Generate the RZ signal


for bit = data
if bit == 1
rz_signal = [rz_signal ones(1, half_bit_samples) zeros(1, half_bit_samples)];
else
rz_signal = [rz_signal zeros(1, samples_per_bit)];
end

end

% Time vector for the entire signal


t = linspace(0, bit_duration * length(data), length(rz_signal));

% Plot the RZ signal


figure;
plot(t, rz_signal, 'LineWidth', 2);
ylim([-0.5 1.5]);
xlabel('Time (s)');
ylabel('Amplitude');
title('RZ Signal');
grid on;

#OUTPUT :

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

% MATLAB Program to Generate and Plot a Raised Cosine Pulse


% Parameters
rolloff = 0.5; % Roll-off factor (0 <= rolloff <= 1)
symbol_rate = 1; % Symbol rate (symbols per second)
span = 6; % Number of symbol periods the pulse spans
samples_per_symbol = 100; % Number of samples per symbol

% Derived parameters
Fs = samples_per_symbol * symbol_rate; % Sampling frequency
Ts = 1 / symbol_rate; % Symbol duration

% Time vector
t = linspace(-span/2, span/2, span * samples_per_symbol);

% Raised Cosine Pulse Generation


raised_cosine_pulse = zeros(size(t));
for i = 1:length(t)
if abs(t(i)) == Ts / (2 * rolloff)
raised_cosine_pulse(i) = (pi/4) * sinc(1/(2*rolloff));
elseif abs(t(i)) < Ts / (2 * rolloff)
raised_cosine_pulse(i) = sinc(t(i) / Ts) * cos(pi * rolloff * t(i) / Ts) / (1 - (2 * rolloff * t(i) / Ts)^2);
else
raised_cosine_pulse(i) = 0;
end
end

% Plot the Raised Cosine Pulse


figure;
plot(t, raised_cosine_pulse, 'LineWidth', 2);
xlabel('Time (s)');
ylabel('Amplitude');
title(['Raised Cosine Pulse (Roll-off Factor = ', num2str(rolloff), ')']);
grid on;

% Display the pulse properties


disp('Raised Cosine Pulse Parameters:');
disp(['Roll-off Factor: ', num2str(rolloff)]);
disp(['Symbol Rate: ', num2str(symbol_rate), ' symbols/second']);
disp(['Span: ', num2str(span), ' symbol periods']);
disp(['Samples per Symbol: ', num2str(samples_per_symbol)]);

# OUTPUT :

Raised Cosine Pulse Parameters:


Roll-off Factor: 0.5
Symbol Rate:
1 symbols/second
Span: 6 symbol periods
Samples per Symbol: 100

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

b) Generate and plot eye diagrams

% Generate a random binary signal


data_length = 1000;
data = randi([0, 1], 1, data_length);

% Reshape the data into a matrix with desired number of samples per symbol
samples_per_symbol = 10;
num_symbols = data_length / samples_per_symbol;
eye_data = reshape(data, samples_per_symbol, num_symbols);

% Plot the eye diagram


figure;
plot(eye_data);
title('Eye Diagram');
xlabel('Sample');
ylabel('Amplitude');
grid on;

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

# OUTPUT :

9. Generate the Probability density function of Gaussian distribution function

AIM : To write a MATLAB program to generate the Probability density function


of Gaussian distribution function

% Parameters
mu = 0; % Mean of the Gaussian distribution
sigma = 1; % Standard deviation of the Gaussian distribution

% Define range for x-axis


x = -5:0.1:5;
% Compute PDF
pdf = (1 / (sigma * sqrt(2 * pi))) * exp(-(x - mu).^2 / (2 * sigma^2));

% Plot PDF
figure;
plot(x, pdf, 'b', 'LineWidth', 2);
title('Probability Density Function of Gaussian Distribution');
xlabel('x');
ylabel('PDF');
grid on;

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

# OUTPUT :

10. Display the signal and its spectrum of an audio signal

AIM: To write a MATLAB program to generate the signal and its spectrum of an
audio signal

% Load audio file


audioFile = 'your_audio_file.wav'; % Change this to your audio file path
[y, Fs] = audioread(audioFile);

% Plot the time-domain signal


t = (0:length(y)-1) / Fs;
figure;
subplot(2, 1, 1);
plot(t, y);
title('Time-Domain Signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Compute the spectrum


N = length(y);
Y = fft(y);
f = (0:N-1) * Fs / N;

Department of ECE , GEC Hassan


Pinciples Of Communication Systems Lab

% Plot the spectrum


subplot(2, 1, 2);
plot(f, abs(Y));
title('Frequency Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([0, Fs/2]); % Display only positive frequencies

% You can also use the following line to display the spectrum in dB scale
% plot(f, 20*log10(abs(Y)));
% ylabel('Magnitude (dB)');

% Adjust plot
grid on;

Department of ECE , GEC Hassan

You might also like