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

MATLAB Signal Analysis and Quantization

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)
11 views10 pages

MATLAB Signal Analysis and Quantization

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

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

Common questions

Powered by AI

MATLAB offers several benefits for digital signal processing experiments, particularly its robust visualization tools that facilitate understanding of complex concepts such as spectrum, frequency, and time-domain transformations. It allows for easy manipulation of data, quick plotting of results, and comprehensive calculations like FFT and obw for bandwidth analysis, providing immediate visual feedback. However, a drawback can be its potential complexity for beginners due to its syntax and extensive feature set. Users need a solid understanding of both signal processing theory and MATLAB functionality to fully leverage its capabilities for analysis .

The process of converting a time domain signal into its frequency domain representation using FFT involves applying the FFT algorithm to the signal data, which decomposes it into its frequency components. The FFT outputs a complex-valued sequence where each element corresponds to a specific frequency in the signal. The magnitude of each element shows the amplitude of the associated frequency component in the original signal. The resulting plot, after applying FFT and fftshift, shows distinct peaks at the frequencies present in the original sine waves, such as 12 Hz and 6 Hz if those were part of the signals, reflecting their presence and amplitude in the frequency spectrum .

Choosing an appropriate bandwidth for signal transmission is crucial as it directly affects the data rate and signal quality. A bandwidth that is too narrow may not be able to carry all the frequencies of the signal, leading to distortion or loss of information. Conversely, bandwidth that accommodates the signal's occupied bandwidth allows for efficient transmission without loss. Bandwidth limitations can restrict data rate, as a limited range of frequencies can carry less information per unit time, potentially necessitating higher levels of compression or affecting the clarity of the recovered signal. In the MATLAB experiments, bandwidth was calculated to ensure that significant power was transmitted, highlighting its importance in maintaining signal integrity and efficiency .

In experiments with multiple frequency components, the Fourier Transform plays the role of decomposing a time-domain signal into its constituent frequencies, revealing the frequency spectrum. In MATLAB, its application is demonstrated by executing fft on a generated signal composed of various sinusoidal waves. The fftshift function is used to center the zero-frequency component, producing a symmetrical frequency plot for clearer interpretation. The magnitude of each frequency component indicates its presence in the original signal, enabling analysis and verification of theoretical predictions about signal behavior in the frequency domain .

Quantization affects a continuous signal by converting it into discrete levels, which reduces its resolution. This process approximates the continuous waveform by mapping it to the nearest quantization level defined by the codebook. The implications include the introduction of quantization noise, which is the error between the original continuous values and the quantized levels. This can affect signal quality, as seen in the MATLAB plot where the continuous sine wave is transformed into a step-like approximation. Thus, the trade-off between bit rate, bandwidth, and quantization accuracy is crucial for an efficient and accurate signal representation .

Quantization can be explained using MATLAB simulations by mapping a continuous signal into discrete levels, demonstrating how digital communication systems convert analog signals into digital format. MATLAB allows the creation of a sine wave followed by partitioning it into intervals and mapping it using a codebook of quantization levels. The resulting plot shows the difference between the original and quantized signals, illustrating the concept visually. In digital communication systems, quantization is vital for converting signals for processing, transmission, and storage, although it introduces quantization noise that needs management for high fidelity .

Adding noise to a signal in a digital processing experiment serves the purpose of simulating real-world conditions where signals often encounter interference. This helps in analyzing the robustness of signal processing techniques and the effectiveness of filters or error correction methods. The effects of noise can be controlled or mitigated through filtering, which reduces noise components, or through digital techniques like error correction coding, which allows for accurate signal reconstruction despite interference. In MATLAB, noise generation and analysis allow for visualization and testing of these techniques under controlled conditions .

The sampling frequency directly influences the representation of a signal by determining how often the signal amplitude is measured per second. According to the Nyquist theorem, the sampling frequency must be at least twice the highest frequency present in the signal to avoid aliasing, which is when different signals become indistinguishable from each other after sampling. In the experiment, sampling at a high rate of 10,000 Hz accurately represents a 10 Hz signal without aliasing, demonstrating the Nyquist theorem's principle that ensures a reliable representation of the signal .

MATLAB facilitates the exploration of communication principles like bit rate, spectrum, and frequency by providing a versatile platform for simulating and visualizing these concepts through practical experimentation. It enables students to model signals, apply transformations like FFT, and analyze results in multiple domains. This offers educational advantages by bridging theoretical knowledge with hands-on experience, enhancing understanding through visual learning, and allowing real-time manipulation and observation of communication phenomena, which are critical for grasping complex principles in signal processing and telecommunications .

Noise impacts the frequency content of a signal by adding random variations that broaden the signal's spectrum, making the identification of original frequency components more difficult. In the time domain, noise appears as random fluctuations superimposed on the original signal, leading to a less smooth waveform. In the frequency domain, noise manifests as a flattened spectrum due to its energy spreading across the frequency range. Using MATLAB, as noise is added to a sine wave, the frequency-domain plot shows the original sine wave's peak combined with the noise's broad spectrum, demonstrating the challenge in isolating specific frequencies in a noisy environment .

You might also like