Discrete Fourier Transform (DFT) Analysis

Version 1.0.1 (1.34 MB) by Márcio
Function [F, FT, PHASE] = dft(t, signal, fi, ff, res, p, cursor) calculates the Discrete Fourier Transform (DFT)
14 Downloads
Updated 28 Mar 2025

View License

Function Overview: Discrete Fourier Transform (DFT) Analysis
The function [F, FT, PHASE] = dft(t, signal, fi, ff, res, p, cursor) is a versatile tool for signal analysis in the frequency domain. It computes the Discrete Fourier Transform (DFT) of a signal within a specified range of frequencies, offering customizable options for visualization.
Inputs
  1. t (sampled time vector in seconds): Represents the time points corresponding to the signal samples being analyzed.
  2. signal (signal to be analyzed): The dataset or signal that you wish to examine in the frequency domain.
  3. fi (initial frequency in Hz): The starting point for the frequency analysis.
  4. ff (final frequency in Hz): The upper limit of the frequency analysis range.
  5. res (resolution in Hz): Determines the precision of the Fourier Transform. Smaller values increase the resolution.
  6. p (plotting option):
  • 0: No plots are generated.
  • 1: Displays only the magnitude plot.
  • 2: Displays both magnitude and phase plots.
  1. cursor (enable cursor on the plot) (optional):
  • 1: Enables the cursor on the plot when p is not zero.
  • 0: Disables the cursor.
Outputs
  1. F (frequency vector): Contains the frequencies analyzed, defined as: F = fi:res:ff.
  2. FT (absolute values of the DFT): A vector storing the absolute values of the Fourier Transform for each analyzed frequency.
  3. PHASE (phase values in degrees): Contains the phase information associated with the Fourier Transform at each frequency.
Practical Summary
This function is ideal for detailed frequency and phase analysis of signals. The ability to customize visualization makes it especially useful in fields like engineering, data science, and signal processing.
MATLAB Code Example
clear all
close all
clc
t = 0:1/(20*60):5*1/(60);
signal = sin(2*pi*60*t);
[F, FT, PHASE] = dft(t, signal, 0, 600, 1, 1, 1);
Explanation
  1. Clearing the Workspace and Closing Figures:
  • The commands clear all, close all, and clc are used to reset the MATLAB workspace by removing all variables, closing any open figures, and clearing the command window, respectively. This ensures a clean slate for the analysis.
  1. Defining the Sampled Time Vector (t):
  • The time vector t is defined using 0:1/(20*60):5*1/(60). Here:
  • The sampling frequency is 20 Hz, which is equivalent to a time resolution of 1/(20*60) seconds (adjusted for 60 subdivisions).
  • The analysis spans a total duration of 5*1/(60) seconds, resulting in a short time series.
  1. Defining the Signal to be Analyzed (signal):
  • The signal is a simple sinusoidal wave defined as sin(2*pi*60*t). This represents a sine wave oscillating at 60 Hz.
  1. Calling the dft Function:
  • Inputs:
  • t: The sampled time vector defined earlier.
  • signal: The sinusoidal signal to be analyzed.
  • 0: The initial frequency (fi) for the analysis, starting at 0 Hz.
  • 600: The final frequency (ff) for the analysis, up to 600 Hz.
  • 1: The resolution (res) of the Fourier Transform, set to 1 Hz.
  • 1: The plotting option (p) to display the magnitude plot.
  • 1: The cursor is enabled on the plot for interactive exploration.
  • Outputs:
  • F: The frequency vector ranging from 0 to 600 Hz with a resolution of 1 Hz.
  • FT: The absolute values of the Fourier Transforms at each frequency.
  • PHASE: The phase values (in degrees) for the respective frequencies.
  1. Result:
  • The function will analyze the input signal in the specified frequency range (0–600 Hz) and produce a plot showing the magnitude of the Fourier Transform. With the cursor enabled, you can interactively inspect the frequency components.

Cite As

Márcio F. S. Barroso (2025). dft (https://www.mathworks.com/matlabcentral/fileexchange/180247), MATLAB Central File Exchange. Retrieved March 28, 2025

MATLAB Release Compatibility
Created with R2010a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Version Published Release Notes
1.0.1

New Help

1.0.0