DSP Lab Report
DSP Lab Report
DSP Lab Report
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:
Algorithm:
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;
% 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.
● DFT:
Where X[k] is the DFT, x[n] is the discrete-time signal, and n is the number of points.
● IDFT:
Algorithm:
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;
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.
Algorithm:
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;
1. Sequence x1: The first sequence, x1=[1,2,3], is plotted in the time domain.
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.
Where Rx[l]] is the auto-correlation function, and lll is the time shift.
Algorithm:
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;
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.
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:
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;
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:
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:
x = [1, 2, 3, 4];
N = 8;
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:
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;
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