Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views3 pages

Lab 8

DIGITAL Signal Processing Lab 08

Uploaded by

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

Lab 8

DIGITAL Signal Processing Lab 08

Uploaded by

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

Lab 8

Objective
In this lab we will be able:
 To break down a signal into a sum of sine and cosine function

Introduction
Spectral analysis is a technique used to analyze signals in the frequency domain. It is a
powerful tool used in signal processing, image processing, and other fields. The
Discrete Fourier Transform (DFT) is one of the most used techniques for spectral
analysis. This report will discuss the implementation of DFT in MATLAB and its
applications.

Procedure
In MATLAB, the DFT can be computed using the built-in function "fft". The function
takes a signal as input and returns the complex valued DFT coefficients. The magnitude
and phase of the coefficients can be obtained using the "abs" and "angle" functions,
respectively. The frequency axis can be computed using the "fftshift" function and the
"fs" variable, which represents the sampling frequency.

Applications

DFT is used in a wide range of applications such as signal processing, image


processing, and control systems. Some examples include:
 Frequency domain filtering of signals
 Detection of periodic patterns in signals
 Analysis of power spectrum of signals
 Reconstruction of signals from their DFT coefficients

Lab Task
% Create the signal
f1 = 30;
f2 = 120;
f3 = 200;
t = linspace(0, 1, 1000);
Sig1 = 0.3 * sin(2 * pi * f1 * t) + 0.7 * sin(2 * pi * f2 * t) + sin(2
* pi * f3 * t);

% Sample the signal


sample_rate = 1000;
samples = Sig1;

% Calculate the FFT


Sig1_fft = fft(Sig1);

% Calculate the magnitude of each point


Sig1_magnitude = abs(Sig1_fft);
% Create a frequency axis to plot the FFT results
f_axis = linspace(0, sample_rate, length(Sig1_fft));

% Plot the FFT results


figure;
plot(f_axis, Sig1_magnitude);
xlabel('Frequency (Hz)');
ylabel('Magnitude');

% Calculate the next power of 2 for the length of the signal


NFFT = nextpow2(length(Sig1));

% Calculate the FFT with a specific NFFT value


Sig1_fft = fft(Sig1, NFFT);

% Only use half of the fft results


Sig1_fft = Sig1_fft(1:NFFT/2);

% Divide the results by the length of the signal


Sig1_magnitude = abs(Sig1_fft/length(Sig1));

% Multiply the magnitude by 2


Sig1_magnitude(2:end-1) = 2*Sig1_magnitude(2:end-1);

% Create frequency axis


f_axis = linspace(0, sample_rate/2, NFFT/2);

% Finally you need to load ECG signal data first


sample_rate = 128;
ECG_signal = load('your_ecg_signal_data');

% Evaluate the FFT of the ECG signal


ECG_fft = fft(ECG_signal);

% Get the magnitude of the FFT


ECG_magnitude = abs(ECG_fft);

% Create a frequency axis


f_axis = linspace(0, sample_rate, length(ECG_fft));

% Get the major frequency components of the ECG signal


[~,index] = maxk(ECG_magnitude,5); %5 is number of major frequency
components
major_freq = f_axis(index);
amplitude = ECG_magnitude(index);

% Make a table of major frequency components of the ECG signal, giving


amplitude of each frequency.
T = table(major_freq',
amplitude','VariableNames',{'Frequency','Amplitude'});
disp(T);
Conclusion
The DFT is a powerful tool for spectral analysis in MATLAB. It allows for the
computation of the frequency content of a signal in a computationally efficient manner.
The DFT is widely used in various applications and its implementation in MATLAB
makes it easy to use for researchers and engineers.

You might also like