Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

CPE 416: DIGITAL SIGNAL PROCESSING

LABORATORY EXPERIMENT

NAME OF STUDENT: NAME HERE


YEAR & COURSE COURSE HERE
PROFESSOR: INSTRUCTOR’S NAME HERE

TITLE OF ACTIVITY: FREQUENCY ANALYSIS OF SIGNALS AND SYSTEMS


INTRODUCTION / BACKGROUND:
In the realm of Digital Signal Processing (DSP), the frequency analysis of signals and
systems is a fundamental and indispensable concept. This analysis allows us to investigate the
spectral characteristics of signals, revealing the various frequencies and their respective
amplitudes present within a signal. Understanding the frequency domain representation of
signals is crucial for tasks like filtering, modulation, and compression, enabling us to manipulate
signals effectively in the digital domain. This lab manual section delves into the essential
techniques and tools used in frequency analysis, empowering students to explore the intricate
interplay between time and frequency domains, ultimately advancing their proficiency in DSP
and signal processing applications.

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.

Mathematical Representation: Mathematically, a function f(x) is periodic with period T if it


satisfies the following condition for all x:

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

Representation of Periodic Functions

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

Significance of Fourier Series

INSTRUCTION: Copy and paste the given code. Try different functions and observe its
behavior.

MATLAB CODE:

% Define your function or create discrete data points


T = 2*pi; % Period
N = 1000; % Number of data points
t = linspace(0, T, N); % Time vector
f_t = sin(2*pi*1*t) + 0.5*sin(2*pi*2*t) + 0.25*sin(2*pi*3*t);% Your function here, or define it for
each t

% Compute the Fourier coefficients using FFT


F = fft(f_t);
L = length(F);
coeffs = 1/L * abs(F(1:L/2+1));

% Number of terms in the Fourier series


N_terms = 10;

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

% Plot the original function and the Fourier series


plot(t, f_t, 'b', t, series, 'r');
legend('Original Function', 'Fourier Series Approximation');
xlabel('t');
ylabel('f(t)');
title('Fourier Series Approximation');

EXPECTED OUTPUT

5
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
OBSERVATIONS

ACTIVITY 2: PROPERTIES OF FOURIER SERIES

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:

1. Linearity (Superposition): One of the most fundamental properties of Fourier series is


linearity. This property allows you to break down complex functions into simpler
components and then reassemble them. Specifically, if you have two periodic functions
f1(t) and f2(t) with Fourier series representations, you can compute the Fourier series of
their sum or scalar multiples as the sum or scalar multiple of their respective Fourier
series.

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;

% Define the time values for plotting


t = linspace(0, 3*T, 1000);

% Define the fundamental frequency


omega_0 = 2*pi/T;

% Create a square wave function


square_wave = zeros(size(t));
square_wave(t < T/2) = 1;
square_wave(t >= T/2) = -1;

8
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT

% Plot the original square wave


subplot(3,2,1);
plot(t, square_wave);
title('Original Square Wave');
xlabel('t');
ylabel('x(t)');

% Property 1: Linearity (Superposition)


N = 5; % Number of harmonics
fourier_series = 0;
for n = 1:N
fourier_series = fourier_series + (4/pi) * (1/n) * sin(n*omega_0*t);
end

subplot(3,2,2);
plot(t, fourier_series);
title('Superposition (Fourier Series)');
xlabel('t');
ylabel('Fourier Series');

% Property 2: Time Shifting


t_shifted = t - T/4; % Shift by T/4 to the right

subplot(3,2,3);
plot(t_shifted, square_wave);
title('Time Shifting');
xlabel('t');
ylabel('x(t - T/4)');

% Property 3: Frequency Shifting


omega_shifted = omega_0 * 2; % Shift frequency by 2*omega_0

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)');

% Property 4: Symmetry (Half-wave Symmetry)


t_symmetric = linspace(0, T, 500); % One-half of a period

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)');

% Property 5: Symmetry (Odd-Even)


t_odd = linspace(0, T, 500); % One complete period
t_even = linspace(0, T, 500); % One complete period

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.

1. Continuous Fourier Transform (CFT):


The Continuous Fourier Transform is used to analyze continuous-time functions. It is defined as
follows:

2. Discrete Fourier Transform (DFT):


The Discrete Fourier Transform is used to analyze discrete-time signals, often
encountered in digital signal processing. It is defined as follows:

3.Inverse Fourier Transform:


The Inverse Fourier Transform allows you to convert the frequency domain
representation back to the time domain. For the Continuous Fourier Transform:

12
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT
MATLAB CODE:

% Load an audio file


input_audio_file = 'HappyBirthday.wav'; % Replace with the path to your audio file
[x, fs] = audioread(input_audio_file);

% Display the original audio signal


figure;
subplot(2,1,1);
plot((0:length(x)-1)/fs, x);
title('Original Audio Signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Apply the Fourier Transform to the audio signal


X = fft(x);

% Calculate the frequencies corresponding to each FFT bin


frequencies = (0:length(X)-1)*(fs/length(X));

% Plot the magnitude spectrum of the audio signal


subplot(2,1,2);
plot(frequencies, abs(X));
title('Magnitude Spectrum of Original Signal');
xlabel('Frequency (Hz)');
ylabel('Magnitude');

% Design a low-pass Butterworth filter


cutoff_frequency = 5000; % Cutoff frequency (Hz)
filter_order = 10; % Filter order

[b, a] = butter(filter_order, cutoff_frequency/(fs/2), 'low');

% Apply the filter in the frequency domain


X_filtered = X .* fftshift(b);

% Compute the inverse FFT to obtain the filtered signal


x_filtered = ifft(X_filtered);
sound(x_filtered, fs);

% Display the filtered signal


figure;

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');

% Plot the magnitude spectrum of the filtered signal


subplot(2,1,2);
plot(frequencies, abs(X_filtered));
title('Magnitude Spectrum of Filtered Signal');
xlabel('Frequency (Hz)');
ylabel('Magnitude');

% Save the filtered audio signal to a new audio file


output_audio_file = 'filtered_audio.wav'; % Replace with your desired output file path
audiowrite(output_audio_file, x_filtered, fs);

disp(['Filtered audio saved as ' output_audio_file]);

EXPECTED OUTPUT:

OBSERVATIONS

14
CPE 416: DIGITAL SIGNAL PROCESSING
LABORATORY EXPERIMENT

PRACTICE PROBLEM:

1. Calculate and display the output of:

x(t) = cos(2t)

Insert your code and output here….


Observations

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.

Insert your code and output here….


Observations

15

You might also like