Professional Documents
Culture Documents
Cpe416 - DSP - Laboratory 4
Cpe416 - DSP - Laboratory 4
LABORATORY EXPERIMENT
OBJECTIVE:
This lab demonstrates the implementation of Fourier Series Using MATLAB
Computation of Fourier Series
Construct Fourier Series and visualize the original function and the Fourier series
approximation
Fourier Series of Periodic Signals
Properties of Fourier Series
Apply Fourier Transform to audio signal
PROGRAMMING TOOL USED: MATLAB
OVERVIEW:
The Fourier Series is a fundamental mathematical tool in various fields, including mathematics,
physics, engineering, and signal processing. It allows us to represent complex, periodic
functions as a sum of simpler trigonometric functions. This concept has applications in areas
such as signal analysis, image processing, and even understanding the behavior of physical
systems.
Periodic Functions:
1
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
Definition of Periodicity: A function is said to be periodic if it repeats its values in a regular,
predictable manner over a certain interval. This interval is known as the "period" of the function.
f(x) = f(x + T) In other words, if you shift the input x by the period T, the function's values
remain the same.
Examples of Periodic Functions: Some common examples of periodic functions include sine
and cosine functions, square waves, triangular waves, and sawtooth waves. These functions
have well-defined periods.
2
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
Fourier Series: One of the most powerful methods for representing periodic functions is the
Fourier Series. It allows you to express a periodic function as an infinite sum (or a finite
approximation) of sine and cosine functions with different frequencies and amplitudes.
The Fourier Series representation of a function f(x) with period T is given by:
Fourier Coefficients: To compute the Fourier Series representation, you need to determine the
Fourier coefficients an and bn. These coefficients are calculated using integration over one
period of the function:
3
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
These coefficients capture the contributions of each frequency component to the original
function.
Approximation: In practice, the Fourier Series is often represented as a finite sum, which
means you include a limited number of terms (N) in the series. The more terms you include, the
better the approximation becomes.
Understanding periodic functions and their representation through Fourier Series is crucial
because it allows us to decompose complex, real-world signals into simpler components,
making it easier to analyze and manipulate them.
ACTIVITY 1
INSTRUCTION: Copy and paste the given code. Try different functions and observe its
behavior.
MATLAB CODE:
4
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
% Construct the Fourier series
series = zeros(size(t));
for n = 1:N_terms
series = series + coeffs(n) * cos(2*pi*(n-1)/T*t);
end
EXPECTED OUTPUT
5
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
OBSERVATIONS
The Fourier series is a powerful mathematical tool used to represent and analyze periodic
functions as a sum of sinusoidal components. Several key properties of Fourier series are
essential for understanding how they work and their practical applications:
2. Time Shifting: Fourier series exhibit time-shifting properties. If you take a function f(t)
with a Fourier series representation and replace t with (t-τ ¿you get a new function that
has the same Fourier series but is shifted to the right by τ units in the time domain.
Similarly, if you replace t with (t+ τ ¿ , the function is shifted to the left.
6
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
3. Frequency Shifting: You can shift the frequency components of a Fourier series by
adding or subtracting a constant frequency ω 0 to each term. This property is particularly
useful in signal processing and modulation techniques.
4. Conjugate Symmetry: The coefficients in the complex exponential Fourier series are
conjugate symmetric. This means that an and bn coefficients for real-valued functions satisfy an-1
= an and bn-1 = bn, which leads to symmetry properties in the frequency domain.
5. Symmetry Properties: Fourier series often exhibit various types of symmetry depending on
the original function. These symmetries include:
Odd Symmetry: If f(t) is an odd function (f(-t)= - f(t) ,then the Fourier series coefficients
will have a special form, and only sine terms bn will be present.
Even Symmetry: If f(t) is an even function (f(-t)= - f(t) , then the Fourier series
coefficients will also have a special form, and only cosine terms an will be present.
Half-Wave Symmetry: Some functions exhibit symmetry over half of their period. In
such cases, you can simplify the Fourier series representation by considering only half of
the period.
7
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
6. Parseval's Theorem: Parseval's theorem states that the total energy (or power) of a function
in the time domain is equal to the sum of the squared magnitudes of its Fourier coefficients in
the frequency domain. This theorem is essential in signal processing for energy and power
calculations.
MATLAB CODE:
% Define the period of the square wave
T = 2*pi;
8
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
subplot(3,2,2);
plot(t, fourier_series);
title('Superposition (Fourier Series)');
xlabel('t');
ylabel('Fourier Series');
subplot(3,2,3);
plot(t_shifted, square_wave);
title('Time Shifting');
xlabel('t');
ylabel('x(t - T/4)');
fourier_series_shifted = 0;
for n = 1:N
fourier_series_shifted = fourier_series_shifted + (4/pi) * (1/n) * sin(n*(omega_0 +
omega_shifted)*t);
end
subplot(3,2,4);
plot(t, fourier_series_shifted);
title('Frequency Shifting');
9
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
xlabel('t');
ylabel('Fourier Series (Shifted)');
square_wave_symmetric = ones(size(t_symmetric));
square_wave_symmetric(t_symmetric >= T/2) = 0;
subplot(3,2,5);
plot(t_symmetric, square_wave_symmetric);
title('Symmetry (Half-wave)');
xlabel('t');
ylabel('x(t)');
square_wave_odd = ones(size(t_odd));
square_wave_odd(t_odd >= T/2) = -1; % Odd symmetry
square_wave_even = ones(size(t_even));
square_wave_even(t_even >= T/2) = 1; % Even symmetry
subplot(3,2,6);
plot(t_odd, square_wave_odd, t_even, square_wave_even);
title('Symmetry (Odd-Even)');
xlabel('t');
ylabel('x(t)');
legend('Odd Symmetry', 'Even Symmetry');
10
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
EXPECTED OUTPUT
OBSERVATIONS
11
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
ACTIVITY 3: FOURIER TRANSFORM
The Fourier Transform is a mathematical tool used to analyze and represent functions or signals
in the frequency domain. It allows you to decompose a function or signal into its constituent
frequencies, providing valuable insights into its frequency content and enabling various
applications in mathematics, physics, engineering, and signal processing.
12
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
MATLAB CODE:
13
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
subplot(2,1,1);
plot((0:length(x_filtered)-1)/fs, x_filtered);
title('Filtered Audio Signal');
xlabel('Time (s)');
ylabel('Amplitude');
EXPECTED OUTPUT:
OBSERVATIONS
14
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
PRACTICE PROBLEM:
x(t) = cos(2t)
2. You will load your recorded audio signal, apply a low-pass Butterworth filter to remove
high-frequency noise, and save the filtered audio as a new file.
15