Poc Lab 2
Poc Lab 2
Title: Study of signal frequency, spectrum, bandwidth, bit rate, quantization using MATLAB.
Submitted to-
Submitted by-
Group Number: 03
Group Members-
SL NAME ID
13 AKTER,AIRIN 22-46334-1
Submission Date:04/11/2024
Explanation:
1. Parameter Initialization:
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).
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:
3. Magnitude 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.
Command:
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:
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;
fs = 8000;
f = 400; %Hz
%Define signal
t = 0:1/fs:1-1/fs;
signal = 1.2*sin(2*pi*f*t);
plot(t, signal);
title('Time-Domain signal');
xlabel('Time (s)');
ylabel('amplitude');
fftSignal = fft(signal);
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);
get it to
figure;
plot(f, abs(fftSignal));
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))
xlabel('Frequency (Hz)');
ylabel('magnitude');
%noisy signal
figure
plot(t,noisySignal)
xlabel('Time (s)');
ylabel('Amplitude');
fftNoisySignal = fft(noisySignal);
fftNoisySignal = fftshift(fftNoisySignal)/(fs/2);
figure
plot(f,abs(fftNoisySignal))
xlabel('Frequency (Hz)');
ylabel('magnitude');
OUTPUT
Explanation:
1. Signal Generation:
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.
• 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:
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.
Command:
fs = 10000;
t = [0:1/fs:0.1];
intervals
figure
plot(t,sig,'x',t,quants,'.')
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.
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