0% found this document useful (0 votes)
8 views10 pages

Poc Lab 2

Uploaded by

mushfiquelabib
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)
8 views10 pages

Poc Lab 2

Uploaded by

mushfiquelabib
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/ 10

American International University - Bangladesh

Department of Electrical and Electronic Engineering


EEE 3215: PRINCIPLES OF COMMUNICATION

Semester: Fall 2024-2025 Section: C

Experiment Number: 02.

Title: Study of signal frequency, spectrum, bandwidth, bit rate, quantization using MATLAB.
Submitted to-

DR. SHUVRA MONDAL


ASSISTANT PROFESSOR, Dept. of EEE
Faculty of Engineering, AIUB

Submitted by-
Group Number: 03

Group Members-
SL NAME ID

11 DAIYAN, F.M. MAHIR 22-49716-3

12 MITU, RIFAT ARA 22-47744-2

13 AKTER,AIRIN 22-46334-1

14 LABIB, MUSHFIQUE REDWAN 22-47132-1

15 ZAMAN, MD. SHAHRIAR 22-47754-2

Submission Date:04/11/2024

Faculty of Engineering, AIUB Dept. of Electrical & Electronics Engineering (EEE)


Experimental Findings (MATLAB Commands):

Generating a sinusoidal signal with different frequencies.


Command:
fs = 1000; % Sampling frequency
t = 0:1/fs:1-1/fs; % Time duration
f1 = 12; % Frequency of first signal
f2 = 6; % Frequency of second signal
A1 = 1.5; % Amplitude of first signal
A2 = 1.1; % Amplitude of second signal
x1 = A1*sin(2*pi*f1*t); % First Signal
x2 = A2*sin(2*pi*f2*t); % Second Signal
%Plotting both signals in time domain
plot(t,x1,'k--o','LineWidth',1.5)
hold on
plot(t,x2,'b-*','LineWidth',2)
hold off
xlabel('time in seconds')
ylabel('Amplitude in volts')
title('Signals of different Frequencies')
OUTPUT

Explanation:
1. Parameter Initialization:

• fs: Sets the sampling frequency to 1000 Hz.


• t: Creates a time vector from 0 to 1 second with a step size of 1/fs.
• f1 and f2: Define the frequencies of the two signals (12 Hz and 6 Hz).
• A1 and A2: Set the amplitudes of the two signals (1.5 and 1.1).

2. Signal Generation:

• x1 and x2: Generate the two signals using the sin function with the specified frequencies,
amplitudes, and time vector.
3. Plotting:

• plot(t,x1, 'k--o', 'LineWidth',1.5): Plots the first signal x1 with a black dashed line and
circles, with a line width of 1.5.
• hold on: Holds the current plot so that the next plot will be added to the same figure.
• plot(t, x2, 'b-*', 'LineWidth', 2): Plots the second signal x2 with a blue solid line and stars,
with a line width of 2.
• hold off: Releases the hold on the current plot.
• xlabel, ylabel, title: Adds labels to the x-axis, y-axis, and the title of the plot.

4. Output:

• The plot shows two sinusoidal signals with different frequencies and amplitudes. The first
signal (12 Hz) has a higher frequency and larger amplitude than the second signal (6 Hz).

These signals can be represented in frequency domain as well:


Command:
%Take fourier transform
fx1 = fft(x1);
fx2 = fft(x2);
%apply fftshift to put it in the form we are used to (see documentation)
fx1 = fftshift(fx1)/(fs/2);
fx2 = fftshift(fx2)/(fs/2);
%Next, calculate the frequency axis, which is defined by the sampling rate
f = fs/2*linspace(-1,1,fs);
%Since the signal is complex, we need to plot the magnitude to get it to
%look right, so we use abs (absolute value)
figure;
plot(f, abs(fx1), f, abs(fx2),'LineWidth',1.5);
title('magnitude FFT of sine');
axis([-100 100 0 2])
xlabel('Frequency (Hz)');
ylabel('magnitude');
OUTPUT

Explanation:

1. Fourier Transform:

• fx1 = fft(x1): Applies the Fast Fourier Transform (FFT) to the first signal x1, converting it
from the time domain to the frequency domain.
• fx2 = fft(x2): Does the same for the second signal x2.
2. Frequency Axis Calculation:

• f = (-fs/2:fs/2-1)/fs: Creates a frequency vector f that corresponds to the frequency bins in


the FFT output. The fftshift function is used to center the zero-frequency component at the
middle of the spectrum.

3. Magnitude Plot:

• figure;: Creates a new figure window.


• plot(f, abs(fx1), f, abs(fx2), 'LineWidth', 1.5): Plots the magnitude of the Fourier Transform
of both signals x1 and x2 against the frequency axis f. The abs function calculates the
absolute value (magnitude) of the complex-valued FFT output.
• title, xlabel, ylabel, axis: Adds a title, labels to the axes, and sets the axis limits for the plot.

4. Output:

• The plot shows the magnitude spectrum of the two signals. The peaks in the spectrum
correspond to the frequencies present in the original signals. In this case, we should see peaks
at 12 Hz and 6 Hz, corresponding to the frequencies of the two sinusoidal signals.

Example of Bandwidth calculation:

Command:

fs = 8000; % Sampling frequence

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)

OUTPUT

Explanation:

1. Parameter Initialization:

• fs: Sets the sampling frequency to 8000 Hz.


• t: Creates a time vector from 0 to 1 second with a step size of 1/fs.
2. Signal Generation:

• cx: Generates a signal cx by summing three sinusoidal components:


o A sine wave with a frequency of 100 Hz and amplitude of 1.1
o A cosine wave with a frequency of 300 Hz and amplitude of 1.3
o A sine wave with a frequency of 2000 Hz and amplitude of 1.5

3. Bandwidth Calculation:

• bandwidth = obw(cx, fs): Calculates the Occupied Bandwidth (OBW) of the signal cx using
the obw function. The OBW is a measure of the bandwidth of a signal, defined as the
frequency range over which 99% of the signal's power is concentrated.

4. Output:

• The bandwidth variable will contain the calculated OBW of the signal cx. In this case, the
output is 1.901e+03, which means the bandwidth is approximately 1901 Hz.

Another example of generating signals in time domain, adding noise and representing these
signals in frequency domain.

Command:

close all;

clc;

%Define number of samples to take

fs = 8000;

f = 400; %Hz

%Define signal

t = 0:1/fs:1-1/fs;

signal = 1.2*sin(2*pi*f*t);

%Plot to illustrate that it is a sine wave

plot(t, signal);

title('Time-Domain signal');

xlabel('Time (s)');

ylabel('amplitude');

%Take fourier transform

fftSignal = fft(signal);

%apply fftshift to put it in the form we are used to (see

documentation)
fftSignal = fftshift(fftSignal)/(fs/2);%scaling done by dividing

with (fs/2)

%Next, calculate the frequency axis, which is defined by the sampling rate

f = fs/2*linspace(-1,1,fs);

%Since the signal is complex, we need to plot the magnitude to

get it to

%look right, so we use abs (absolute value)

figure;

plot(f, abs(fftSignal));

title('magnitude FFT of sine');

xlabel('Frequency (Hz)');

ylabel('magnitude');

%noise

noise = 2*randn(size(signal));

figure

plot(t,noise)

xlabel('Time (s)');

ylabel('Amplitude');

title('Time-Domain Noise');

fftNoise = fft(noise);

fftNoise = fftshift(fftNoise)/(fs/2);

figure

plot(f,abs(fftNoise))

title('Magnitude FFT of noise');

xlabel('Frequency (Hz)');

ylabel('magnitude');

%noisy signal

noisySignal = signal + noise;

figure
plot(t,noisySignal)

xlabel('Time (s)');

ylabel('Amplitude');

title('Time-Domain Noisy Signal');

fftNoisySignal = fft(noisySignal);

fftNoisySignal = fftshift(fftNoisySignal)/(fs/2);

figure

plot(f,abs(fftNoisySignal))

title('Magnitude FFT of noisy signal');

xlabel('Frequency (Hz)');

ylabel('magnitude');

OUTPUT
Explanation:

1. Signal Generation:

• fs: Sets the sampling frequency to 8000 Hz.


• f: Defines the frequency of the sine wave to 400 Hz.
• t: Creates a time vector from 0 to 1 second with a step size of 1/fs.
• signal: Generates a sine wave with the specified frequency and amplitude.

2. Time-Domain Plot:

• The first figure plots the generated sine wave in the time domain.

3. Frequency-Domain Analysis:

• fftSignal = fft(signal): Calculates the Fast Fourier Transform (FFT) of the signal.
• fftshift: Shifts the zero-frequency component to the center of the spectrum.
• f = (-fs/2:fs/2-1)/fs: Creates a frequency vector.
• The second figure plots the magnitude spectrum of the sine wave, showing its frequency
content.

4. Noise Generation and Analysis:

• noise: Generates white Gaussian noise with the same length as the signal.
• The third and fourth figures plot the time-domain and frequency-domain representations of
the noise.

5. Noisy Signal:

• noisySignal: Adds the noise to the original signal.


• The fifth and sixth figures plot the time-domain and frequency-domain representations of
the noisy signal.

Output:

• Original Sine Wave: The time-domain plot shows a clear sinusoidal waveform, while the
frequency-domain plot exhibits a single peak at the specific frequency of the sine wave.
• Noise Signal: The time-domain plot depicts a random, seemingly chaotic signal. Its
frequency-domain plot reveals a relatively flat spectrum, indicating energy spread across a
wide range of frequencies.
• Noisy Signal: The addition of noise to the sine wave results in a distorted time-domain
waveform. The frequency-domain plot shows a combination of the original sine wave's peak
and the noise's broad spectrum, highlighting the impact of noise on the signal's frequency
content.

Example of scalar quantization in MATLAB:

Command:

fs = 10000;

t = [0:1/fs:0.1];

f = 10; % Times at which to sample the sine function

sig = 2*sin(2*pi*f*t); % Original signal, a sine wave

partition = [-1.5, -0.5, 0.5, 1.5]; % Length 4, to represent 5

intervals

codebook = [-2:2]; % Length 5, one entry for each interval

[index,quants] = quantiz(sig,partition,codebook); % Quantize.

figure

plot(t,sig,'x',t,quants,'.')

legend('Original signal','Quantized signal');

OUTPUT

Explanation:

1. Setting Parameters
o fs is the sampling frequency, set to 10,000 Hz, which determines how often the sine
wave is sampled.
o f is the frequency of the sine wave, set to 10 Hz.
2. Creating the Time Vector
o t is a time vector, which represents the times at which the sine function will be
sampled. It ranges from 0 to 0.1 seconds in steps of 1/fs, giving a high-resolution time
base.
3. Generating the Sine Wave
o signal, a sine wave with a peak amplitude of 2.
4. Defining Quantization Levels
o partition defines the thresholds for quantization. These thresholds split the range of
the sine wave into intervals.
o codebook specifies the quantization levels. Each interval in partition is mapped to a
value in codebook.
5. Quantizing the Signal
o quantiz is a MATLAB function that quantizes sig based on partition and codebook.
quants contains the quantized values of the sine wave, while index holds the index of
each quantization level.
6. Plotting the Original and Quantized Signals
o This part creates a plot with the original sine wave (marked by x) and the quantized
signal (marked by dots .).
o A legend is added to distinguish between the original and quantized signals.

Plot Interpretation

• Original Signal: The blue crosses (x) represent the continuous sine wave sampled at a high
frequency, showing the smooth shape of the sine wave.
• Quantized Signal: The orange dots (.) represent the quantized values. Since the quantization
reduces the possible values the signal can take, the quantized signal appears as discrete
horizontal lines, approximating the sine wave by mapping it to the closest quantization level
from the codebook.

The plot demonstrates how quantization affects a signal by reducing its resolution, effectively
"stepping" the smooth sine wave into a staircase-like approximation based on the defined
quantization levels. This is a common process in digital signal processing, especially in analog-to-
digital conversion.

Discussion & Conclusion:

In this lab experiment, we used MATLAB to explore key concepts in digital signal processing,
including signal frequency, spectrum, bandwidth, bit rate, and quantization. By generating and
sampling a sine wave, we observed how sampling at a high rate (10,000 Hz) accurately represents
a 10 Hz signal without aliasing, following the Nyquist theorem. We examined the frequency
spectrum, noting that a pure sine wave has a single frequency component. We also studied
bandwidth, bit rate, and quantization, seeing how quantization approximates a continuous signal
with discrete levels, introducing quantization noise. Key insights include the importance of
balancing bit rate, bandwidth, and quantization accuracy to achieve efficient, accurate signal
representation. MATLAB provided valuable visualization tools to enhance our understanding of
these concepts, which are essential in digital communications and telecommunications design.

Software:

MATLAB2016a

You might also like