DSP Lab Report

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Table of Contents

Experiment 1: Representation of Basic Signals................................................................. 1


Experiment 2: To Find DFT/IDFT of a Given Discrete-Time (DT) Signal............................5
Experiment 3: Linear Convolution of Two Sequences....................................................... 8
Experiment 4: Auto-correlation of a Sequence................................................................. 11
Experiment 5: To Find the FFT of a Given Sequence....................................................... 13
Experiment 6: Implementation of Interpolation Process..................................................15
Experiment 7: Computation of n-point DFT of a Given Sequence.................................. 17
Experiment 8: Verification of Sampling Theorem............................................................. 19
Experiment 1: Representation of Basic Signals

Objective:
To represent basic signals such as sine wave, cosine wave, unit impulse, unit step wave,
square wave, and exponential waveform using MATLAB.

Description:
In this experiment, we will generate and visualize the following basic signals using MATLAB:

● Sine Wave: A periodic oscillatory signal.


● Cosine Wave: Similar to the sine wave but with a phase shift.
● Unit Impulse: A discrete-time signal with a value of one at a single time point and
zero elsewhere.
● Unit Step Wave: A signal that steps from zero to one at a given point.
● Square Wave: A signal that alternates between high and low states.
● Exponential Waveform: A waveform that either grows or decays exponentially.

Algorithm:

1. Define the time vector.


2. Generate each signal using MATLAB functions.
3. Plot each signal in a separate figure or subplot.

Source Code (MATLAB):

t = -1:0.01:1;
n = -10:10;

% Sine Wave
f = 5;
sine_wave = sin(2 * pi * f * t);
figure;
plot(t, sine_wave);
title('Sine Wave');
xlabel('Time');
ylabel('Amplitude');
grid on;

% Cosine Wave
cosine_wave = cos(2 * pi * f * t);
figure;
plot(t, cosine_wave);
title('Cosine Wave');

Page | 1
xlabel('Time');
ylabel('Amplitude');
grid on;

% Unit Impulse
impulse_signal = (n == 0);
figure;
stem(n, impulse_signal, 'filled');
title('Unit Impulse');
xlabel('n');
ylabel('Amplitude');
grid on;

% Unit Step Wave


step_signal = (n >= 0);
figure;
stem(n, step_signal, 'filled');
title('Unit Step Wave');
xlabel('n');
ylabel('Amplitude');
grid on;

% Square Wave
square_wave = square(2 * pi * f * t);
figure;
plot(t, square_wave);
title('Square Wave');
xlabel('Time');
ylabel('Amplitude');
grid on;

% Exponential Waveform
a = 2; % Exponential growth/decay rate
exp_wave = exp(a * t);
figure;
plot(t, exp_wave);
title('Exponential Waveform');
xlabel('Time');
ylabel('Amplitude');
grid on;

Page | 2
Result and Discussion:

1. Sine Wave: The sine wave is generated with a frequency of 5 Hz. It oscillates
periodically between -1 and 1 with smooth transitions.

2. Cosine Wave: The cosine wave also oscillates between -1 and 1 but starts at its
peak due to the phase difference of π/2 with the sine wave.

3. Unit Impulse: The unit impulse is a discrete signal that has a value of 1 at n = 0
and 0 elsewhere.

Page | 3
4. Unit Step Wave: The unit step wave starts at zero for n < 0 and jumps to 1 for n
>= 0.

5. Square Wave: The square wave alternates between -1 and 1 with equal duration,
representing a non-smooth periodic signal.

6. Exponential Waveform: The exponential signal grows or decays based on the value
of a. In this case, it shows an exponential growth pattern.

Page | 4
Experiment 2: To Find DFT/IDFT of a Given Discrete-Time (DT) Signal

Objective:
To compute the Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform
(IDFT) of a given discrete-time signal using MATLAB.

Description:
The Discrete Fourier Transform (DFT) is a numerical method for converting a discrete-time
signal from the time domain to the frequency domain. It is widely used for analyzing the
frequency content of signals. The Inverse Discrete Fourier Transform (IDFT) is the reverse
process, converting the signal back to the time domain.

The mathematical formulas for DFT and IDFT are as follows:

● DFT:

Where X[k] is the DFT, x[n] is the discrete-time signal, and n is the number of points.

● IDFT:

Where x[n] is the inverse transform of the frequency components X[k]

Algorithm:

1. Define the discrete-time signal.


2. Compute the DFT of the signal using MATLAB's built-in fft() function.
3. Compute the IDFT of the signal using MATLAB's built-in ifft() function.
4. Plot the original signal, its magnitude spectrum, and the recovered signal.

Source Code (MATLAB):

x = [1, 2, 3, 4];
N = length(x);

X_k = fft(x);
x_reconstructed = ifft(X_k);

figure;

Page | 5
stem(0:N-1, x, 'filled');
title('Original Discrete-Time Signal');
xlabel('n');
ylabel('Amplitude');
grid on;

figure;
stem(0:N-1, abs(X_k), 'filled');
title('Magnitude Spectrum of DFT');
xlabel('Frequency Index (k)');
ylabel('Magnitude |X[k]|');
grid on;

figure;
stem(0:N-1, real(x_reconstructed), 'filled');
title('Reconstructed Signal from IDFT');
xlabel('n');
ylabel('Amplitude');
grid on;

Result and Discussion:

1. Original Signal: The discrete-time signal x=[1,2,3,4] was chosen as an example.


The plot shows the time-domain representation of this signal.

2. DFT Magnitude Spectrum: The DFT converts the time-domain signal into its
frequency components. The magnitude spectrum is plotted using the absolute values
of the DFT. The DFT clearly shows the frequency content of the original signal.

Page | 6
3. Reconstructed Signal from IDFT: The IDFT is applied to convert the signal back to
the time domain. The reconstructed signal is identical to the original signal,
confirming the correctness of the DFT/IDFT process.

Page | 7
Experiment 3: Linear Convolution of Two Sequences

Objective:
To perform the linear convolution of two discrete-time sequences using MATLAB.

Description:
Convolution is a mathematical operation that combines two sequences to produce a third
sequence, which represents how the shape of one sequence is modified by the other. In
signal processing, linear convolution is used to analyze systems' responses, where one
sequence is typically the input signal, and the other is the impulse response of the system.

The formula for linear convolution is:

Algorithm:

1. Define two sequences x1 and x2​.


2. Use MATLAB's conv() function to compute the linear convolution of the two
sequences.
3. Plot the two original sequences and their convolution result.

Source Code (MATLAB):

x1 = [1, 2, 3];
x2 = [4, 5, 6];

y = conv(x1, x2);

figure;
stem(0:length(x1)-1, x1, 'filled');
title('Sequence x1');
xlabel('n');
ylabel('Amplitude');
grid on;

figure;
stem(0:length(x2)-1, x2, 'filled');
title('Sequence x2');
xlabel('n');

Page | 8
ylabel('Amplitude');
grid on;

figure;
stem(0:length(y)-1, y, 'filled');
title('Linear Convolution Result');
xlabel('n');
ylabel('Amplitude');
grid on;

Result and Discussion:

1. Sequence x1: The first sequence, x1=[1,2,3], is plotted in the time domain.

2. Sequence x2: The second sequence, x2=[4,5,6], is also plotted.

Page | 9
3. Convolution Result: The result of the linear convolution between the two sequences
is y=[4,13,28,27,18]. The plot of the convolution result shows how the two sequences
are combined to produce a new output sequence.

Page | 10
Experiment 4: Auto-correlation of a Sequence

Objective:
To compute the auto-correlation of a given discrete-time sequence using MATLAB.

Description:
Auto-correlation is a mathematical tool used to measure the similarity between a signal and
a time-shifted version of itself. It provides insight into the periodicity or repeating patterns
within the signal. Auto-correlation is commonly used in signal processing, particularly for
analyzing signals with periodic components or identifying hidden patterns.

The auto-correlation of a sequence x[n] is given by:

Where Rx[l]] is the auto-correlation function, and lll is the time shift.

Algorithm:

1. Define the discrete-time sequence.


2. Use MATLAB's xcorr() function to compute the auto-correlation of the sequence.
3. Plot the original sequence and its auto-correlation result.

Source Code (MATLAB):

% Define the discrete-time sequence


x = [1, 2, 3, 4]; % Example sequence

% Compute the auto-correlation using xcorr()


R_x = xcorr(x, x);

% Plot the original sequence


figure;
stem(0:length(x)-1, x, 'filled');
title('Original Sequence');
xlabel('n');
ylabel('Amplitude');
grid on;

% Plot the auto-correlation result

Page | 11
figure;
stem(-(length(x)-1):(length(x)-1), R_x, 'filled');
title('Auto-correlation of the Sequence');
xlabel('Lag (l)');
ylabel('Auto-correlation R_x[l]');
grid on;

Result and Discussion:

1. Original Sequence: The discrete-time sequence x=[1,2,3,4] was chosen as an


example. The plot shows the time-domain representation of this sequence.

2. Auto-correlation Result: The auto-correlation result Rx[l] is computed and plotted.


The auto-correlation gives an insight into the similarity of the sequence with its
time-shifted versions. In this case, the auto-correlation function exhibits symmetry
and has a maximum value at l=0, indicating that the sequence is most similar to itself
without any time shift.

Page | 12
Experiment 5: To Find the FFT of a Given Sequence

Objective:
To compute the Fast Fourier Transform (FFT) of a given discrete-time sequence using
MATLAB.

Description:
The Fast Fourier Transform (FFT) is an efficient algorithm for computing the Discrete Fourier
Transform (DFT). It is widely used in signal processing for analyzing the frequency
components of signals.

The DFT of a discrete-time sequence x[n] is given by:

Where N is the number of points, x[n] is the sequence in the time domain, and X[k] is the
sequence in the frequency domain.

Algorithm:

1. Define the discrete-time sequence.


2. Use MATLAB's fft() function to compute the FFT of the sequence.
3. Plot the original sequence and its magnitude spectrum using the FFT result.

Source Code (MATLAB):

x = [1, 2, 3, 4];
N = length(x);

X_k = fft(x);
f = (0:N-1)*(1/N);

figure;
stem(0:N-1, x, 'filled');
title('Original Discrete-Time Sequence');
xlabel('n');
ylabel('Amplitude');
grid on;

figure;
stem(f, abs(X_k), 'filled');
title('Magnitude Spectrum of FFT');

Page | 13
xlabel('Frequency (Normalized)');
ylabel('Magnitude |X[k]|');
grid on;

Result and Discussion:

1. Original Sequence: The discrete-time sequence x=[1,2,3,4] is plotted in the time


domain. This is the input signal for which we compute the FFT.

2. FFT Magnitude Spectrum: The FFT transforms the time-domain sequence into its
frequency-domain representation. The magnitude spectrum of the FFT is plotted,
showing the frequency components of the original signal. The peaks in the
magnitude spectrum correspond to the dominant frequency components present in
the signal.

Page | 14
Experiment 6: Implementation of Interpolation Process

Objective:
To implement the interpolation process to increase the sampling rate of a discrete-time
signal using MATLAB.

Description:
Interpolation is the process of increasing the sample rate of a discrete-time signal by
inserting additional samples between the existing ones. This process is commonly used in
digital signal processing to convert a signal to a higher sampling rate without introducing
distortion. The zero-order hold or linear interpolation methods are typically used, and in this
experiment, we will use linear interpolation.

Algorithm:

1. Define the original discrete-time sequence.


2. Set the interpolation factor (the number of new points to be inserted between each
existing sample).
3. Use MATLAB's interp() function to perform linear interpolation.
4. Plot the original sequence and the interpolated sequence for comparison.

Source Code (MATLAB):

F=5
P=2
N=10
t=0:1:N-1;
X = sin(2*pi*F*t);
subplot(2,1,1);
stem(X);
title("Original signal");
i=interp(X,P);
subplot(2,1,2);
stem(i);
title("Interpolated signal");

Page | 15
Result and Discussion:

1. Original signal: The original discrete-time sequence x=[1,2,3,4] is plotted. The signal
is sampled at the initial rate.
2. Interpolated signal: The sequence is interpolated with a factor L=2, meaning one
new sample is inserted between each pair of original samples. The interpolated
sequence has a higher sample rate and shows a smoother transition between points.

Page | 16
Experiment 7: Computation of n-point DFT of a Given Sequence

Objective:
To compute the n-point Discrete Fourier Transform (DFT) of a given discrete-time sequence
using MATLAB.

Description:
The Discrete Fourier Transform (DFT) converts a discrete-time sequence into its
corresponding frequency-domain representation. The n-point DFT is calculated by
considering a finite number of samples (n) and using the following formula:

Where x[n] is the time-domain sequence, N is the number of points (n-point), and X[k] is the
frequency-domain representation of the sequence.

Algorithm:

1. Define the discrete-time sequence x[n].


2. Set the number of points N for the DFT.
3. Use MATLAB's fft() function to compute the n-point DFT.
4. Plot the magnitude of the DFT result.

Source Code (MATLAB):

x = [1, 2, 3, 4];
N = 8;

X_k = fft(x, N);

f = (0:N-1)*(1/N);

figure;
stem(f, abs(X_k), 'filled');
title(['Magnitude Spectrum of ', num2str(N), '-point DFT']);
xlabel('Frequency (Normalized)');
ylabel('Magnitude |X[k]|');
grid on;

Page | 17
Result and Discussion:

1. Original Sequence: The given sequence x=[1,2,3,4] is used to compute the n-point
DFT. The sequence has four samples, but an 8-point DFT is computed, which
includes zero-padding to increase the frequency resolution.
2. Magnitude Spectrum of n-point DFT: The magnitude spectrum of the 8-point DFT
is plotted. The result shows how the energy of the original sequence is distributed
across different frequency components. The resolution of the frequency-domain
representation improves with more points (in this case, 8 points).

Page | 18
Experiment 8: Verification of Sampling Theorem

Objective:
To verify the Sampling Theorem by observing the effects of under-sampling, Nyquist rate
sampling, and over-sampling on a continuous-time signal.

Description:
The Sampling Theorem states that a continuous-time signal can be completely represented
in its discrete form, provided it is sampled at a rate greater than or equal to twice its highest
frequency component. This rate is called the Nyquist rate. If the signal is sampled below
this rate (under-sampling), aliasing occurs, leading to distortion. When sampled at or above
the Nyquist rate, the signal can be reconstructed without loss of information.

Algorithm:

1. Define a continuous-time signal (sine or cosine wave).


2. Sample the signal at three different rates:
○ Below the Nyquist rate (under-sampling).
○ At the Nyquist rate.
○ Above the Nyquist rate (over-sampling).
3. Use MATLAB to plot and compare the original continuous-time signal with its
sampled versions.
4. Observe and discuss the effects of each sampling rate.

Source Code (MATLAB):

f = 5;
t_cont = 0:0.001:1;
x_cont = sin(2*pi*f*t_cont);
fs_under = 8;
t_under = 0:1/fs_under:1;
x_under = sin(2*pi*f*t_under);
fs_nyquist = 2*f;
t_nyquist = 0:1/fs_nyquist:1;
x_nyquist = sin(2*pi*f*t_nyquist);
fs_over = 20;
t_over = 0:1/fs_over:1;
x_over = sin(2*pi*f*t_over);

figure;
plot(t_cont, x_cont);
hold on;
stem(t_under, x_under, 'r');
title('Under-sampling (fs < Nyquist)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
hold off;

Page | 19
figure;
plot(t_cont, x_cont);
hold on;
stem(t_nyquist, x_nyquist, 'g');
title('Nyquist-rate Sampling (fs = 2*f)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
hold off;

figure;
plot(t_cont, x_cont);
hold on;
stem(t_over, x_over, 'b');
title('Over-sampling (fs > Nyquist)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
hold off;

Result and Discussion:

1. Under-sampling: When the signal is sampled below the Nyquist rate (8 Hz), aliasing
occurs. The reconstructed signal appears distorted due to the insufficient number of
samples to represent the high-frequency content of the signal.

2. Nyquist-rate Sampling: When sampled at the Nyquist rate (10 Hz), the signal is
represented without any loss of information. The sampled points are sufficient to
accurately reconstruct the original signal.

Page | 20
3. Over-sampling: At a higher sampling rate (20 Hz), more samples are taken than
required by the Nyquist criterion. The signal is represented with high accuracy, but
the additional samples do not provide further useful information beyond what was
achieved with Nyquist-rate sampling.

Page | 21

You might also like