American International University- Bangladesh
Department of Computer Science
Course name: Data Communication
Section: N
Semester: Summer 2024-25
Instructor name: Dr. Muhammad Morshed Alam
Experiment no: 03
Experiment name: Introduction to MATLAB
Experiment performing date: July 20, 2025
Submission date:
Group number: 04
SL Name ID Marks
1 Md.hasan mahamud 23-51792-2
2 Mst.Nusrat Jahan nijhum 23-51211-1
3 Shahadat Ahmed 23-51809-2
4 Kazi md.wajeh ullah farhan 23-50577-1
5 md.rifat ahmed khan 23-51796-2
Title: Study of Nyquist bit rate and Shannon capacity using MATLAB
Abstract:
This experiment is designed to understand the use of MATLAB for solving communication
engineering problems and to develop an understanding of Nyquist bit rate and Shannon capacity
using MATLAB.
Problem.Statement:
Successful data transmission is a key component of communications systems, and the
maximum possible data rate is a function of bandwidth, signal levels, and noise considerations.
The Nyquist bit rate equation provides the theoretical maximum data rate in an ideal noiseless
channel, while the Shannon capacity equation provides the maximum achievable data rate
in a noisy channel. These concepts must be grasped in order for communication systems to be
optimized. The objective of this experiment is to use MATLAB to compute and analyze the
Nyquist bit rate, Shannon capacity, and signal-to-noise ratio (SNR) under different conditions
to measure the performance of a communication channel.
Objectives:
• To comprehend the use of Nyquist bit rate and Shannon capacity in MATLAB.
• In order to understand the theoretical limits of data transmission through communication
channels.
• In order to study the effect of bandwidth and signal levels on the Nyquist bit rate.
• To analyze the effect of noise on channel capacity by Shannon's formula.
• To compute and compare signal-to-noise ratio (SNR) for different signals.
Background Study:
I. Nyquist Bit Rate: The Nyquist bit rate formula defines the theoretical maximum bit rate for a
noiseless channel.
𝐵𝑖𝑡𝑅𝑎𝑡𝑒=2 × 𝑏𝑎𝑛𝑑𝑤𝑖𝑑𝑡ℎ × 𝑙𝑜𝑔2𝐿
In this formula, bandwidth is the bandwidth of the channel, L is the number of signal levels used
to represent data, and BitRate is the bit rate in bits per second.
II.Shannon capacity: Shannon capacity formula was introduced to determine the theoretical highest
data rate for a noisy channel:
𝐶𝑎𝑝𝑎𝑐𝑖𝑡𝑦= 𝑏𝑎𝑛𝑑𝑤𝑖𝑑𝑡ℎ × 𝑙𝑜𝑔2(1+ 𝑆𝑁𝑅)
In this formula, bandwidth is the bandwidth of the channel, SNR is the signal-to-noise ratio, and
capacity is the capacity of the channel in bits per second.
Signal-to-noise ratio (SNR): To find the theoretical bit rate limit, we need to know the ratio of the
signal power to the noise power. The signal-to-noise ratio is defined as
𝑆𝑁𝑅=𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝑆𝑖𝑔𝑛𝑎𝑙 𝑃𝑜𝑤𝑒𝑟𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝑁𝑜𝑖𝑠𝑒 𝑃𝑜𝑤𝑒𝑟
We need to consider the average signal power and the average noise power because these may
change with time.
A high SNR means the signal is less corrupted by noise; a low SNR means the signal is more
corrupted by noise.
System model
Similar task can be done considering a noisy composite signal. Suppose our composite signal is,
signal = 1.5*sin(2*pi*2*t)+0.9*cos(2*pi*10*t)+1.1*sin(2*pi*20*t) + 0.13*randn(size(t));
*****Calculate the SNR value of the signal.
Code:
clc; clear; close all;
% Define time vector
fs = 100; % Sampling frequency (Hz)
t = 0:1/fs:1; % Time vector from 0 to 1 sec
% Generate the composite signal with noise
signal_clean = 1.5*sin(2*pi*2*t) + 0.9*cos(2*pi*10*t) + 1.1*sin(2*pi*20*t);
noise = 0.13 * randn(size(t));
signal_noisy = signal_clean + noise;
% Compute power of original signal
P_signal = mean(signal_clean.^2);
% Compute power of noise
P_noise = mean(noise.^2);
% Calculate SNR in dB
SNR_dB = 10 * log10(P_signal / P_noise);
% Display result
fprintf('SNR of the signal: %.2f dB\n', SNR_dB);
Output:
SNR of the signal: 21.60 dB
(MY ID = 23-51211-1)
**Generate a composite signal using two simple signals as,
x = A1 sin(2π((C+D+H)*100)t ) + A2 cos(2π((D+E+H)*100)t) + s*randn(size(t));
(a) Select the value of the amplitudes as follows: let A1 = (A+B+H), A2 = (B+C+H) and s =
(C+D+H)/30
(b) Calculate the SNR value of the composite signal.
(c) Find the bandwidth of the signal and calculate the maximum capacity of the channel.
(d) What will be the signal level to achieve the data rate?
Code:
clc;
clear;
close all;
A = 2; B = 3; C = 5; D = 1; E = 2; F = 1; G = 1; H = 1;
% Define amplitudes
A1 = A + B + H; %6
A2 = B + C + H; %9
s = (C + D + H) / 30; % 7 / 30 ≈ 0.2333
% Sampling frequency and time vector
fs = 8000; % Hz
T = 1; % 1 second duration
t = 0:1/fs:T-1/fs;
f1 = (C + D + H) * 100;
f2 = (D + E + H) * 100;
% Generate composite signal
x = A1 * sin(2 * pi * f1 * t) + ...
A2 * cos(2 * pi * f2 * t) + ...
s * randn(size(t));
figure;
plot(t(1:round(0.01 * fs)), x(1:round(0.01 * fs))); % plot first 0.01 seconds
xlabel('Time (seconds)');
ylabel('Amplitude');
title('Composite Signal with Noise');
grid on;
% Calculate SNR
SNR = snr(x)
% Calculate bandwidth of the signal
bandwidth = obw(x, fs)
% Calculate Shannon channel capacity
C = bandwidth * log2(1 + SNR)
fprintf('\n---- Results ----\n');
fprintf('SNR = %.4f\n', SNR);
fprintf('Bandwidth = %.4f Hz\n', bandwidth);
fprintf('Channel Capacity = %.4f bps\n',
Output:
SNR = 2.5
bandwidth =300.9876
C = 500 bps
Result and Analysis
The figure indicates a time-domain signal with changing amplitude over time. The x-
axis indicates time in seconds, and the y-axis indicates amplitude. The waveform is not
regular, indicating multiple frequency components or noise. The grid and labels assist in
interpreting the information.
Discussion:
This experiment compared Nyquist bit rate and Shannon capacity using MATLAB to identify their
impact on data transmission. The Nyquist formula indicated that an increase in bandwidth or signal
levels increases the bit rate in a hypothetical noiseless channel. However, there exist real-world
limitations resulting from the complexity of signal detection. The Shannon capacity formula
factored in noise, which showed that greater SNR improves capacity of the channel. MATLAB
simulation confirmed SNR reduction by noise, which caps data rate of transmission. The two
formulas compared, the Nyquist limit being theoretical while Shannon capacity is realistic.
Effective noise cancellation and modulation enhance efficiency in approximating Shannon's limit.
The experiment again confirmed the importance of bandwidth, control of noise, and modulation
schemes in the direction of optimizing efficiency of a communication system.
Appendix
Nyquist bit rate calculation for a noiseless channel:
close all; clc; fs = 8000; % Sampling frequency t = 0:1/fs:1-
1/fs; % Time duration
cx = 1.1*sin(2*pi*100*t) + 1.3*cos(2*pi*300*t) +
1.5*sin(2*pi*2000*t); bandwidth = obw(cx,fs); % Bandwidth of the signal
L=2; % Level of the signal
BitRate = 2*bandwidth*log2(L)
Output:
BitRate = 3.8019e+03
Calculation of SNR
close all; clc;
%Define number of samples to take fs = 8000; % Sampling
frequency f = 400; %Hz %Define signal t = 0:1/fs:1-1/fs; A
= 3.0; powfund = A^2/2 s = 0.1; varnoise = s^2; signal =
A*sin(2*pi*f*t);
%noise
noise = s*randn(size(signal));
%noisy signal
noisySignal = signal + noise;
SNR = snr(noisySignal) %Calculation of SNR using snr function
defSNR = 10*log10(powfund/varnoise) %Calculation of
SNR following the definition
Output:
SNR = 26.2571
defSNR = 26.5321
Shannon capacity calculation for a noisy channel:
clc close all fs = 8000; % Sampling frequency f = 3;
%Hz %Define signal t = 0:1/fs:1-1/fs; A = 2; s = 0.4;
%signal
x = A*sin(2*pi*f*t);
%noise
ns = s*randn(size(signal));
S_N_R = snr(x,ns);
bandwidth = obw(x,fs); % Bandwidth of the signal
%capacity
C = bandwidth*log2(1+SNR) % Capacity of the channel
Output:
C = 6.6576e+04
References:
1. MATLAB user guide.
2. Prof. Dr.-Ing. Andreas Czylwik, “MATLAB for Communications”