Dsap Lab Report 077bei045
Dsap Lab Report 077bei045
Theory
Octave, also known as GNU Octave, is a programming language designed for
numerical computations. It offers a command-line interface for solving linear
and nonlinear problems, with compatibility similar to MATLAB. Key features
include efficient matrix operations, function plotting, and data visualization.
Octave serves as a free alternative for numerical computation tasks
Characteristics:
• Symbolic Math: Octave supports symbolic computations, allowing you
to manipulate algebraic expressions, perform differentiation,
integration, and solve equations symbolically.
• Built-in Functions: Octave provides a wide range of built-in functions for
mathematical operations, signal processing, statistics, and more. These
functions simplify complex tasks and enhance productivity.
• Extensibility: Octave allows you to create custom functions and
packages, extending its functionality beyond the built-in capabilities.
You can share your custom functions with others or reuse existing
packages.
• Parallel Computing: Octave supports parallel execution, enabling faster
computations by distributing tasks across multiple cores or processors.
• File I/O: Octave can read and write data from various file formats (e.g.,
CSV, HDF5, MAT) seamlessly, making it convenient for data analysis and
manipulation.
1
Programs
Sinusoid Signals
t = -pi : 0.01 : pi; y =
sin(t); x = cos(t); plot(t, y,
’r’); hold on; plot(t, x, ’g’);
xlabel(’t’); ylabel(’x(t)’);
title(’Sinusoid’);
Output
2
Output
Ramp Signal
n = -10 : 10;
c = input("Enter the intercept: "); m =
input("Enter the slope: "); y = m*n + c;
3
Output
Sinc Signal
clear all;
t = -5 : 0.01 : 5; x =
sinc(t);
4
Output
Exponential Signal
n = -5 : 5;
a = input("Enter three values for a: "); c = input("Enter the
amplitude scaling factor: ");
y = c*exp(a(1)*n); subplot(311);
stem(n, y); xlabel("n");
ylabel("y[n]"); title("Exponential
signal");
y = c*exp(a(2)*n); subplot(312);
stem(n, y); xlabel("n");
ylabel("y[n]"); title("Exponential
signal");
y = c*exp(a(3)*n);
subplot(313); stem(n, y);
xlabel("n");
ylabel("y[n]");
5
title("Exponential signal");
Output
Discussion
In the lab exercise, we utilized Octave to create plots of fundamental signals
such as step functions, ramps, sinusoids, and exponentials. We employed the
plot function for continuous signals and the stem function for discrete
signals. This introduction lays the groundwork for more advanced labs,
familiarizing students with Octave’s essential features.
Conclusion
Hence, this lab session was successfully completed by generating and plotting
basic signals in Octave.
6
Lab 2 - Convolution
Objectives
• To understand convolution of finite signals and calculate it in Octave
Theory
Convolution is a mathematical operation used in signal processing, image
processing, and various other fields of engineering and applied mathematics.
It combines two functions to produce a third function that expresses how the
shape of one is modified by the other. Convolution is fundamental in the
analysis of linear time-invariant systems and is widely used in the context of
filtering, system analysis, and solving differential equations.
Mathematical Definition
The convolution of two continuous functions f(t) and g(t) is defined as:
dτ
For discrete functions f[n] and g[n], the convolution is defined as:
∞
X
(f ∗ g)[n] = f[k]g[n − k]
k=−∞
Key Properties
• Commutativity:
f∗g=g∗f
• Associativity:
(f ∗ g) ∗ h = f ∗ (g ∗ h)
• Distributivity:
f ∗ (g + h) = (f ∗ g) + (f ∗ h)
• Identity Element: The delta function δ(t) acts as an identity element for
convolution:
7
f∗δ=f
Programs
subplot(311); stem(x);
title("x[n]");
subplot(312); stem(h);
title("h[n]");
8
Output
x = a.ˆn .* u;h = u
y = conv(x, h);
9
Output
Discussion
During the lab exercise, we employed Octave’s conv function to compute the
convolution of two functions. When dealing with functions of finite lengths,
the process was straightforward, as the conv function directly provided the
finite-length output. However, for functions with infinite length, we set a
limit (in this case, 20) and calculated the convolution within that range.
Conclusion
Hence, this lab session, was completed by calculating and plotting the
convolution between two finite and two infinite signals in Octave.
10
Lab 3 - Signal Transformation
Objectives
• To understand the use of fft and ifft to calculate Fourier transorm and its
inverse
• To calculate the Z-transform of a real signal and plot its zeroes and poles
FFT
The Fast Fourier Transform (FFT) is an efficient algorithm to compute the
Discrete Fourier Transform (DFT) and its inverse. The DFT is a mathematical
technique used to convert a discrete-time signal into its frequency
components. The FFT significantly reduces the computational complexity of
evaluating the DFT, making it practical for a wide range of applications in signal
processing, image processing, and more.
Mathematical Definition
• Linearity:
F{af[n] + bg[n]} = aF{f[n]} + bF{g[n]}
• Time Shifting:
• Frequency Shifting:
11
F{ej2Nπk0nf[n]} = F[k − k0]
Theory of Z-Transform
The Z-transform is a mathematical tool used in the analysis and
characterization of discrete-time signals and systems. It provides a means to
represent discrete-time signals in the frequency domain and is particularly
useful in the study of linear, time-invariant (LTI) systems.
Mathematical Definition
X n
n=−∞
Key Properties
• Linearity:
• Time Shifting:
12
• Convolution: The convolution of two sequences in the time domain
corresponds to multiplication in the Z-domain:
x[0] = zlim→∞X(z)
Programs
Calculation of FFT
x = [0 1 2 3]; y =
fft(x, 4);
subplot(311); stem(x);
xlabel("n"); ylabel("x[n]");
title("Original signal");
subplot(312); stem(real(y));
xlabel("n"); ylabel("Real part of
FFT"); title("FFT of the signal");
subplot(313); stem(imag(y));
xlabel("n"); ylabel("Img part of
FFT"); title("FFT of the signal");
13
Output
subplot(511); stem(x);
xlabel("n"); ylabel("x[n]");
title("Original signal");
subplot(512); stem(real(y));
xlabel("n"); ylabel("Real part of
FFT"); title("FFT of the signal");
subplot(513); stem(imag(y));
xlabel("n"); ylabel("Img part of
FFT"); title("FFT of the signal");
subplot(514); stem(abs(y));
xlabel("n"); ylabel("Magnitude of
FFT"); title("FFT of the signal");
subplot(515); stem(angle(y));
xlabel("n"); ylabel("Phase of FFT");
title("FFT of the signal");
14
Output
Inverse FFT
x = [1.2 3.7 0.8 1 2.1]; y = fft(x,
8); x_recovered = ifft(y, 8);
subplot(311); stem(real(y));
xlabel("n"); ylabel("Real part of
FFT"); title("FFT Input");
subplot(312); stem(imag(y));
xlabel("n"); ylabel("Img part of
FFT"); title("FFT Input");
subplot(313); stem(x_recovered);
xlabel("n"); ylabel("x[n]");
title("Recovered Time Domain Signal");
15
Output
Z-Transform
num = [1 0.8 0 2 0 3]; den = [0.76 0
2 1.7 2.3 1]; [z, p, k] = tf2zp(num,
den); zplane(z, p); title("Z-plane
Plot of Zeroes and Poles");
16
Discussion
In the lab exercise, we explored various signal and system transformations.
Specifically:
• We computed the Fourier transform of given signals using the Fast
Fourier Transform (FFT) algorithm.
• To recover the original signal, we applied the inverse FFT.
• Additionally, for a given digital system, we visualized its poles and
zeros in the z-domain.
Conclusion
Hence, this lab session was successfully completed by calculating and plotting
the Fourier transform of a signal using FFT (and the inverse) and plotting a
digital system in z domain.
17
Lab 4 - System Response
Objectives
• To plot the frequency response of a given system.
• To plot the frequency response of a given difference equation.
Theory
Digital systems are used to process discrete-time signals and are fundamental
in modern electronic applications such as computing, communications, and
control systems. These systems can be analyzed and designed using
mathematical tools such as transfer functions, which describe the input-
output relationship of a system in the frequency domain.
Transfer Function
The transfer function of a digital system characterizes the system’s response
to an input signal. It is defined in the Z-domain as the ratio of the Z-transform
of the output signal to the Z-transform of the input signal, assuming all initial
conditions are zero.
H(z) = XY ((zz))
• Zeros: The values of z that make the numerator of H(z) zero. These
represent frequencies where the output is minimized.
• Poles: The values of z that make the denominator of H(z) zero. These
represent frequencies where the system’s response is theoretically
infinite.
The locations of poles and zeros in the Z-plane provide insights into the
stability and frequency response of the system.
Stability
A digital system is stable if all the poles of its transfer function lie inside the
unit circle in the Z-plane. This means that for all poles zi:
|zi| < 1
Frequency Response
The frequency response of a digital system describes how the system
responds to different frequency components of an input signal. It is obtained
by evaluating the transfer function on the unit circle z = ejω:
H(ejω) = H(z)
z=ejω
19
Applications of Transfer Functions in Digital Systems
• Filter Design: Transfer functions are used to design digital filters that can
pass, attenuate, or stop specific frequency components of a signal.
• Control Systems: Transfer functions are used in the design and analysis of
digital control systems, ensuring desired performance and stability
characteristics.
Programs
System Response
kg load signal;
w = 20;
## num = [0.008, 1.2, 3.5, 0, 4];
## den = [1, 2.5, 0, 1, 0.65]; ## x =
freqz(num, den, w);
subplot(211); plot(abs(x));
title("Magnitude Response")
xlabel("w"); ylabel("Mag");
subplot(212); plot(angle(x));
title("Phase Response")
xlabel("w"); ylabel("Phase");
20
Output
Difference Equation
## For the system described by the following difference equation, plot the
magnitude and phase response: ## y(n) - 0.67y(n-1) + 0.2y(n-2) = 0.32x(n) + x(n-1)
subplot(211); plot(abs(x));
title("Magnitude Response")
xlabel("w"); ylabel("Mag");
subplot(212); plot(angle(x));
title("Phase Response")
xlabel("w"); ylabel("Phase");
21
Output
Discussion
During the lab exercise, we analyzed the frequency response of a given
system using the freqz function. The system could be specified in various
forms:
• Transfer Function: We directly used the transfer function
representation.
• Poles and Zeros: We worked with the poles and zeros representation.
• Difference Equation: For systems described by a difference equation,
we manually converted it into an appropriate transfer function form
before plotting the frequency response. This allowed us to visualize
both the magnitude and phase response.
Conclusion
Hence, this lab session was successfully completed by plotting the frequency
response of the given system.
22
Lab 5 - Digital Filters
Objectives
• To learn about the design of Butterworth filter with given specifications.
• To learn about the design of Chebyshev I filter with given specifications.
Butterworth Filter
The Butterworth filter is a type of signal processing filter designed to have a
frequency response that is as flat as possible in the passband. It is also known
as a maximally flat magnitude filter.
Characteristics
• Flat Response in Passband: The Butterworth filter is designed to have no
ripples in the passband. The response is maximally flat, meaning the
magnitude response is smooth and monotonically decreasing without
any ripples.
• Smooth Transition: The transition from the passband to the stopband is
gradual compared to other types of filters like Chebyshev filters.
• Order of the Filter: The order of the Butterworth filter determines the
sharpness of the transition between the passband and the stopband.
Higher-order filters have a steeper roll-off but require more
computational resources.
Transfer Function
H(s) = r 1
1 + ωsc2n
23
in the passband to achieve a faster transition between the passband and the
stopband.
Characteristics
• Passband Ripples: The Chebyshev Type I filter has ripples in the passband,
which allows it to achieve a steeper roll-off compared to the Butterworth
filter.
• Order of the Filter: Similar to the Butterworth filter, the order of the
Chebyshev filter determines the steepness of the roll-off. Higherorder
filters have a steeper transition.
Transfer Function
The transfer function of an n-th order Chebyshev Type I filter is given by:
H(s) = r 1
1 + ϵ2Tn2 ωsc
Programs
Butterworth Filter Design
fp = 1000; fs =
2000; Ap = 1;
As = 40;
Fs = 10000;
Wp = fp / (Fs / 2);
Ws = fs / (Fs / 2);
24
utput
Wp = fp / (Fs / 2);
Ws = fs / (Fs / 2);
25
Output
Discussion
In this lab exercise, we looked at the design of digital low pass filters (LPF) in
Octave. The filters were designed using Butterworth and Chebyshev I
approximations for the given specifications (passband, stopband). The
frequency response of the designed filter was plotted and verified. The order
required for the filter was also determined using Octave.
Conclusion
Hence, this lab session was successfully completed by designing Butterworth
and Chebyshev I filter for given specifications and observing their frequency
response.
26