0% found this document useful (0 votes)
12 views11 pages

LAB File Template

The document outlines a practical exercise in MATLAB focused on signal handling, including frequency domain representation using DFT and FFT. It details objectives such as visualizing discrete signals' magnitude and phase spectra, and analyzing various signal types. The practical concludes with insights on the effectiveness of FFT in signal processing applications like filtering and data compression.

Uploaded by

frefwg77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views11 pages

LAB File Template

The document outlines a practical exercise in MATLAB focused on signal handling, including frequency domain representation using DFT and FFT. It details objectives such as visualizing discrete signals' magnitude and phase spectra, and analyzing various signal types. The practical concludes with insights on the effectiveness of FFT in signal processing applications like filtering and data compression.

Uploaded by

frefwg77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Practical No: 02 Date: 28-07-2025

Student Name Atharvaraj Aditya Mali PRN: 2305096

Tittle Fundamentals of Signal Handling in MATLAB

Objectives:
Sr. No. Statements
1. Understand the concept of frequency domain representation using DFT.

2. Use FFT in MATLAB to compute and visualize the magnitude and phase spectrum of
discrete signals.
3. Compare time-domain and frequency-domain representations of signals.

4. Analyze the spectral components of different types of signals (sinusoidal, square, sum
of sinusoids).

Program/ Code/ Blocks:


1.Audio file %Step 1: Read audio file
signal [x, Fs] = audioread('EXP_2_voice_file.wav'); % x: audio signal, Fs:
sampling rate
x = x(:,1); % Use only one channel (mono)
N = length(x);
%Step 2: Create time vectors
t_ct = (0:N-1)/Fs; % Continuous time vector in seconds
n_dt = 0:N-1; % Discrete sample index
%Step 3: Plot CT and DT versions
figure;
subplot(2,1,1);
plot(t_ct, x); title('Sound Signal in Continuous Time'); xlabel('Time
(s)'); ylabel('Amplitude'); grid on;
subplot(2,1,2);
stem(n_dt, x, 'Marker', 'none'); title('Sound Signal in Discrete Time');
xlabel('Sample Index (n)'); ylabel('Amplitude'); grid on;
%Step 4: Apply FFT
X = fft(x);
magX = abs(X);
f = (0:N-1)*(Fs/N); % Linear frequency axis in Hz
%Step 5: Plot Magnitude Spectrum
figure;
plot(f, magX); title('Magnitude Spectrum of Sound Signal');
xlabel('Frequency (Hz)'); ylabel('|X(f)|'); grid on;
xlim([0 Fs/2]); % Show only positive frequencies (real signal)

Signal Processing LAB (EC3174)


output:

Signal Processing LAB (EC3174)


Complex Discrete % Complex Discrete Signal and 8-point FFT Analysis
Signal and 8-
point FFT % Define complex discrete-time signal
Analysis n = 0:7;
x = 1.2*exp(1j*2*pi*0.25*n) + 0.8*exp(-1j*2*pi*0.125*n); % New
complex sinusoid

% Plot complex signal (real and imaginary parts)


figure;
subplot(2,1,1); stem(n, real(x), 'filled'); title('Real Part of x[n]');
xlabel('n'); ylabel('Re\{x[n]\}');
subplot(2,1,2); stem(n, imag(x), 'filled'); title('Imaginary Part of x[n]');
xlabel('n'); ylabel('Im\{x[n]\}');

% Compute 8-point FFT


X_1 = fft(x, 8);
k_1 = 0:7;
f_1 = k_1 / 8;

% Compute 12-point FFT (optional: keep x zero-padded to length 12)


X_2 = fft(x, 12);
k_2 = 0:11;
f_2 = k_2 / 12;

% Magnitude and Phase for 8-point FFT


magnitude = abs(X_1);
phase = angle(X_1);

% Plot Magnitude Spectrum for 8-point FFT


figure;
subplot(4,1,1); stem(f_1, magnitude, 'filled'); title('Magnitude Spectrum
|X_1[k]|'); xlabel('Normalized Frequency'); ylabel('|X_1[k]|');

% Plot Phase Spectrum for 8-point FFT


subplot(4,1,2); stem(f_1, phase, 'filled'); title('Phase Spectrum X_1[k]');
xlabel('Normalized Frequency'); ylabel('Angle (radians)');

% Magnitude and Phase for 12-point FFT


magnitude = abs(X_2);
phase = angle(X_2);

% Plot Magnitude Spectrum for 12-point FFT


subplot(4,1,3); stem(f_2, magnitude, 'filled'); title('Magnitude Spectrum
|X_2[k]|'); xlabel('Normalized Frequency'); ylabel('|X_2[k]|');

% Plot Phase Spectrum for 12-point FFT


subplot(4,1,4); stem(f_2, phase, 'filled'); title('Phase Spectrum X_2[k]');
xlabel('Normalized Frequency'); ylabel('Angle (radians)');

Signal Processing LAB (EC3174)


Output:

Signal Processing LAB (EC3174)


Continuous % Define continuous signal
Signal Discrete t = 0:0.001:1; % Continuous time vector
Signal DFT x_cont = 1.5*cos(2*pi*8*t) + 0.8*sin(2*pi*12*t); % New composite signal
Analysis
% Sample the continuous signal to get discrete version
Fs = 60; % Sampling frequency
Ts = 1/Fs; % Sampling interval
n = 0:Ts:1; % Discrete time samples
x_disc = 1.5*cos(2*pi*8*n) + 0.8*sin(2*pi*12*n); % Discrete version

% Compute DFT using FFT


N = length(x_disc);
X = fft(x_disc, N);
f = (0:N-1) * (Fs/N); % Frequency vector for plotting

% Plot continuous signal


figure;
subplot(3,1,1);
plot(t, x_cont); grid on;
title('Continuous-Time Signal');
xlabel('Time (s)'); ylabel('Amplitude');

% Plot discrete signal


subplot(3,1,2);
stem(n, x_disc, 'filled'); grid on;
title('Discrete-Time Signal');
xlabel('n'); ylabel('Amplitude');

% Plot spectral magnitude


subplot(3,1,3);
stem(f, abs(X), 'filled'); grid on;
title('Magnitude Spectrum of Discrete Signal');
xlabel('Frequency (Hz)'); ylabel('|X[k]|');

Signal Processing LAB (EC3174)


Continuous % Time vector
Signal Discrete n = 0:31; % 32-point signal
Signal DFT
Analysis % Component 1: Cosine signal
x1 = 1.2 * cos(2*pi*0.15*n); % Changed from sine to cosine

% Component 2: Alternating exponential decay


x2 = 5*(-0.9).^n; % Changed to alternating exponential

% Component 3: Impulse train (every 4th sample)


x3 = mod(n, 4) == 0; % Changed from step signal

% Composite signal (addition)


x = x1 + x2 + x3;

% Plot individual components


figure;
subplot(4,1,1); stem(n, x1, 'filled'); title('Cosine Component x1[n] =
1.2·cos(2π·0.15·n)'); xlabel('n'); ylabel('x1[n]');
subplot(4,1,2); stem(n, x2, 'filled'); title('Alternating Exponential Component
x2[n] = (-0.9)^n'); xlabel('n'); ylabel('x2[n]');
subplot(4,1,3); stem(n, x3, 'filled'); title('Impulse Train Component x3[n] = δ[n
mod 4 = 0]'); xlabel('n'); ylabel('x3[n]');
subplot(4,1,4); stem(n, x, 'filled'); title('Composite Signal x[n] = x1[n] + x2[n]
+ x3[n]'); xlabel('n'); ylabel('x[n]');

% Compute FFT
N = length(x);
X = fft(x, N);
f = (0:N-1)/N; % Normalized frequency

Signal Processing LAB (EC3174)


% Plot FFT Magnitude and Phase
figure;
subplot(2,1,1); stem(f, abs(X), 'filled'); title('Magnitude Spectrum |X[k]|');

subplot(2,1,2); stem(f, angle(X), 'filled'); title('Phase Spectrum ∠X[k]');


xlabel('Normalized Frequency'); ylabel('|X[k]|');

xlabel('Normalized Frequency'); ylabel('∠X[k] (radians)');

Output:

Signal Processing LAB (EC3174)


Sine Signal clc; clear; close all;
Discrete Signal
DFT Analysis
% Step 1: Generate continuous-time sine wave
f_sine = 5; % Signal frequency = 5 Hz
t = 0:0.001:0.3; % Slightly increased continuous-time range
x_cont = sin(2*pi*f_sine*t); % Continuous-time signal

% Step 2: Sample the signal


Fs = 50; % Sampling frequency
Ts = 1/Fs; % Sampling interval
n = 0:Ts:0.5; % Discrete-time samples (~16 samples)
x_disc = sin(2*pi*f_sine*n); % Sampled signal

% Step 3: FFT (no zero-padding)


N = length(x_disc); % FFT size same as signal length
X = fft(x_disc, N);

Signal Processing LAB (EC3174)


X_shifted = fftshift(X);
magX = abs(X_shifted)/max(abs(X_shifted)); % Normalize magnitude

% Step 4: Frequency axes


f_normalized = (-N/2:N/2-1)/N; % Normalized frequency
f_radians = 2*pi*f_normalized; % Frequency in radians/sample

% Step 5: Plot time-domain signals


figure;
subplot(2,1,1);
plot(t, x_cont); title('Continuous-Time Sine Wave');
xlabel('Time (s)'); ylabel('Amplitude'); grid on;

subplot(2,1,2);
stem(n, x_disc, 'filled'); title('Sampled Discrete-Time Signal');
xlabel('Sample Index n'); ylabel('Amplitude'); grid on;

% Step 6: Frequency-domain plots


figure;
subplot(2,1,1);
stem(f_normalized, magX, 'filled');
title('FFT - Normalized Frequency');
xlabel('Normalized Frequency (cycles/sample)'); ylabel('|X[k]| (Normalized)');
grid on;

subplot(2,1,2);
stem(f_radians, magX, 'filled');
title('FFT - Frequency in Radians/Sample');
xlabel('Frequency (rad/sample)'); ylabel('|X[k]| (Normalized)'); grid on;

Signal Processing LAB (EC3174)


Output:

Signal Processing LAB (EC3174)


Inference:

1 I used the FFT (Fast Fourier Transform) function in MATLAB to convert a signal from the
time domain to the frequency domain.

2 I observed that sinusoidal components in the time-domain signal appeared as distinct peaks in
the magnitude spectrum.

3 The phase spectrum effectively retained the phase information of the original signal.

4 FFT allowed for efficient analysis of the signal’s frequency content, making it a powerful tool
in signal processing.

5 This practical enhanced my understanding of spectral analysis and its significance in real-world
applications.

I realized that FFT is widely used in various fields such as:

 Filtering
6  Data Compression

 Communication Systems

Signal Processing LAB (EC3174)

You might also like