
- MATLAB - Home
- MATLAB - Overview
- MATLAB - Features
- MATLAB - Environment Setup
- MATLAB - Editors
- MATLAB - Online
- MATLAB - Workspace
- MATLAB - Syntax
- MATLAB - Variables
- MATLAB - Commands
- MATLAB - Data Types
- MATLAB - Operators
- MATLAB - Dates and Time
- MATLAB - Numbers
- MATLAB - Random Numbers
- MATLAB - Strings and Characters
- MATLAB - Text Formatting
- MATLAB - Timetables
- MATLAB - M-Files
- MATLAB - Colon Notation
- MATLAB - Data Import
- MATLAB - Data Output
- MATLAB - Normalize Data
- MATLAB - Predefined Variables
- MATLAB - Decision Making
- MATLAB - Decisions
- MATLAB - If End Statement
- MATLAB - If Else Statement
- MATLAB - If…Elseif Else Statement
- MATLAB - Nest If Statememt
- MATLAB - Switch Statement
- MATLAB - Nested Switch
- MATLAB - Loops
- MATLAB - Loops
- MATLAB - For Loop
- MATLAB - While Loop
- MATLAB - Nested Loops
- MATLAB - Break Statement
- MATLAB - Continue Statement
- MATLAB - End Statement
- MATLAB - Arrays
- MATLAB - Arrays
- MATLAB - Vectors
- MATLAB - Transpose Operator
- MATLAB - Array Indexing
- MATLAB - Multi-Dimensional Array
- MATLAB - Compatible Arrays
- MATLAB - Categorical Arrays
- MATLAB - Cell Arrays
- MATLAB - Matrix
- MATLAB - Sparse Matrix
- MATLAB - Tables
- MATLAB - Structures
- MATLAB - Array Multiplication
- MATLAB - Array Division
- MATLAB - Array Functions
- MATLAB - Functions
- MATLAB - Functions
- MATLAB - Function Arguments
- MATLAB - Anonymous Functions
- MATLAB - Nested Functions
- MATLAB - Return Statement
- MATLAB - Void Function
- MATLAB - Local Functions
- MATLAB - Global Variables
- MATLAB - Function Handles
- MATLAB - Filter Function
- MATLAB - Factorial
- MATLAB - Private Functions
- MATLAB - Sub-functions
- MATLAB - Recursive Functions
- MATLAB - Function Precedence Order
- MATLAB - Map Function
- MATLAB - Mean Function
- MATLAB - End Function
- MATLAB - Error Handling
- MATLAB - Error Handling
- MATLAB - Try...Catch statement
- MATLAB - Debugging
- MATLAB - Plotting
- MATLAB - Plotting
- MATLAB - Plot Arrays
- MATLAB - Plot Vectors
- MATLAB - Bar Graph
- MATLAB - Histograms
- MATLAB - Graphics
- MATLAB - 2D Line Plot
- MATLAB - 3D Plots
- MATLAB - Formatting a Plot
- MATLAB - Logarithmic Axes Plots
- MATLAB - Plotting Error Bars
- MATLAB - Plot a 3D Contour
- MATLAB - Polar Plots
- MATLAB - Scatter Plots
- MATLAB - Plot Expression or Function
- MATLAB - Draw Rectangle
- MATLAB - Plot Spectrogram
- MATLAB - Plot Mesh Surface
- MATLAB - Plot Sine Wave
- MATLAB - Interpolation
- MATLAB - Interpolation
- MATLAB - Linear Interpolation
- MATLAB - 2D Array Interpolation
- MATLAB - 3D Array Interpolation
- MATLAB - Polynomials
- MATLAB - Polynomials
- MATLAB - Polynomial Addition
- MATLAB - Polynomial Multiplication
- MATLAB - Polynomial Division
- MATLAB - Derivatives of Polynomials
- MATLAB - Transformation
- MATLAB - Transforms
- MATLAB - Laplace Transform
- MATLAB - Laplacian Filter
- MATLAB - Laplacian of Gaussian Filter
- MATLAB - Inverse Fourier transform
- MATLAB - Fourier Transform
- MATLAB - Fast Fourier Transform
- MATLAB - 2-D Inverse Cosine Transform
- MATLAB - Add Legend to Axes
- MATLAB - Object Oriented
- MATLAB - Object Oriented Programming
- MATLAB - Classes and Object
- MATLAB - Functions Overloading
- MATLAB - Operator Overloading
- MATLAB - User-Defined Classes
- MATLAB - Copy Objects
- MATLAB - Algebra
- MATLAB - Linear Algebra
- MATLAB - Gauss Elimination
- MATLAB - Gauss-Jordan Elimination
- MATLAB - Reduced Row Echelon Form
- MATLAB - Eigenvalues and Eigenvectors
- MATLAB - Integration
- MATLAB - Integration
- MATLAB - Double Integral
- MATLAB - Trapezoidal Rule
- MATLAB - Simpson's Rule
- MATLAB - Miscellenous
- MATLAB - Calculus
- MATLAB - Differential
- MATLAB - Inverse of Matrix
- MATLAB - GNU Octave
- MATLAB - Simulink
MATLAB - Fourier Transform
The Fourier Transform is a powerful mathematical tool used in signal processing, image processing, and many other fields. It decomposes a function of time (or a signal) into its constituent frequencies. In MATLAB, the Fourier Transform can be computed using the fft function for 1D signals or the fft2 function for 2D signals like images.
The Fourier Transform has many applications, such as filtering, compression, and analysis of signals and images. Understanding the Fourier Transform can help in analyzing and manipulating various types of data in MATLAB.
Fourier Transform using fourier()
The fourier function in MATLAB is used to compute the Fourier series coefficients of a periodic signal or the Fourier transform of a non-periodic signal. It can be used to analyze the frequency components of a signal in both the time and frequency domains. The function returns complex coefficients that represent the amplitude and phase of the sinusoidal components of the signal at different frequencies.
Syntax
fourier(f) fourier(f,transVar) fourier(f,var,transVar)
Syntax Explanation
fourier(f) − Calculates the Fourier Transform of the function f. It uses symvar to find the independent variable, and w is the variable used for the transformation.
fourier(f,transVar) − calculates the Fourier Transform of the function f, using the variable transVar instead of w for the transformation.
fourier(f,var,transVar) − computes the Fourier Transform of the function f. It uses var as the independent variable and transVar as the transformation variable, instead of the default symvar and w, respectively.
Let us see a few examples based on the syntax we explained above.
Example 1: Calculating the Fourier Transform of a Function
The code we have is −
syms t w f = exp(-t^2); % Define the function F = fourier(f); % Calculate the Fourier Transform disp(F); % Display the result
- In this example, we have a function f defined as exp(-t^2).
- We use the fourier function to calculate the Fourier Transform of f.
- The function fourier uses symvar to determine t as the independent variable and w as the transformation variable.
- The result F is the Fourier Transform of the function f, which is displayed using disp(F).
On execution the output is −
pi^(1/2)*exp(-w^2/4)
Example 2: Calculating the Fourier Transform with a Custom Transformation Variable
The code we have is −
syms t u f = sin(2*pi*t); % Define the function F = fourier(f, u); % Calculate the Fourier Transform with u as the transformation variable disp(F); % Display the result
- In this example, we have a function f defined as sin(2*pi*t).
- We use the fourier function with the variable u specified as the transformation variable, instead of the default w.
- The result F is the Fourier Transform of the function f with respect to the variable u.
- The result is displayed using disp(F).
On execution the output is −
-pi*(dirac(u - 2*pi) - dirac(u + 2*pi))*1i
Example 3: Fourier Transform with Custom Variables
The code we have is −
syms t omega f = sin(omega*t); % Define the function F = fourier(f, t, omega); % Calculate the Fourier Transform with t as the independent variable and omega as the transformation variable disp(F); % Display the result
The output we have is −
>> syms t omega f = sin(omega*t); % Define the function F = fourier(f, t, omega); % Calculate the Fourier Transform with t as the independent variable and omega as the transformation variable disp(F); % Display the result -1i*Inf >>
Fourier Transform using fft()
The Fourier Transform is a mathematical technique that decomposes a signal into its constituent frequencies. In MATLAB, the Fourier Transform of a 1D signal can be computed using the fft function.
Syntax
Y = fft(X) Y = fft(X,n) Y = fft(X,n,dim)
Syntax Explanation
Y = fft(X) − Calculates the Discrete Fourier Transform (DFT) of X using a fast algorithm called the Fast Fourier Transform (FFT). The output Y is the same size as X.
- If X is a vector, fft(X) returns the Fourier transform of the vector.
- If X is a matrix, fft(X) treats the columns of X as vectors and returns the Fourier transform of each column.
- If X is a multidimensional array, fft(X) treats the values along the first array dimension that is not size 1 as vectors and returns the Fourier transform of each vector.
Y = fft(X,n) − Calculates the n-point Discrete Fourier Transform (DFT) of X.
- If X is a vector and shorter than n, zeros are added to the end of X to make its length n.
- If X is a vector and longer than n, X is shortened to length n.
- If X is a matrix, each column is treated like a vector.
- If X is a multidimensional array, the first dimension that is not size 1 is treated like a vector.
Y = fft(X,n,dim) − computes the Fourier transform along the specified dimension dim of X.
- If X is a matrix, fft(X,n,2) computes the n-point Fourier transform of each row.
- If X is a multidimensional array, the Fourier transform is computed along the specified dimension dim.
Let us see a few examples based on the syntax we explained above.
Example 1: Calculating the Discrete Fourier Transform (DFT)
The code we have is -
% Create a simple signal x = [1, 2, 3, 4]; % Calculate the Discrete Fourier Transform (DFT) of the signal y = fft(x); % Display the original signal and its DFT disp('Original Signal:'); disp(x); disp('Discrete Fourier Transform:'); disp(y);
- In this example, we have a simple 1D signal x consisting of four values [1, 2, 3, 4].
- We use the fft function to calculate the Discrete Fourier Transform (DFT) of the signal, storing the result in y.
- The fft function computes the DFT using a fast algorithm called the Fast Fourier Transform (FFT).
- The output y is the same size as the input signal x, containing the Fourier transform of the signal.
On execution the output we get is as follows −
Original Signal: 1 2 3 4 Discrete Fourier Transform: 10.0000 + 0.0000i -2.0000 + 2.0000i -2.0000 + 0.0000i -2.0000 - 2.0000i
Example 2: Calculating the n-point Discrete Fourier Transform (DFT)
The code we have is -
% Create a simple signal x = [1, 2, 3, 4]; % Calculate the 8-point Discrete Fourier Transform (DFT) of the signal y = fft(x, 8); % Display the original signal and its DFT disp('Original Signal:'); disp(x); disp('8-point Discrete Fourier Transform:'); disp(y);
- In this example, we have a simple 1D signal x consisting of four values [1, 2, 3, 4].
- We use the fft function with the parameter 8 to calculate the 8-point Discrete Fourier Transform (DFT) of the signal, storing the result in y.
- Since the length of x is less than 8, zeros are added to the end of x to make its length 8.
- The output y is the 8-point DFT of the signal.
On execution the output i get is −
Original Signal: 1 2 3 4 8-point Discrete Fourier Transform: Columns 1 through 3: 10.0000 + 0i -0.4142 - 7.2426i -2.0000 + 2.0000i Columns 4 through 6: 2.4142 - 1.2426i -2.0000 + 0i 2.4142 + 1.2426i Columns 7 and 8: -2.0000 - 2.0000i -0.4142 + 7.2426i
Example 3: Computing the Fourier Transform Along a Specified Dimension
The code we have is as follows -
% Create a 2x4 matrix X = [1, 2, 3, 4; 5, 6, 7, 8]; % Compute the Fourier transform along the second dimension (columns) Y = fft(X, [], 2); % Display the original matrix and its Fourier transform disp('Original Matrix:'); disp(X); disp('Fourier Transform Along Columns:'); disp(Y);
- In this example, we have a 2x4 matrix X with two rows and four columns.
- We use the fft function with the parameter 2 to compute the Fourier transform along the second dimension (columns) of X, storing the result in Y.
- Each column of X is treated as a vector, and the Fourier transform of each column is computed independently.
- The output Y is a 2x4 matrix containing the Fourier transforms of the columns of X.
On execution the output we get is as follows −
Original Matrix: 1 2 3 4 5 6 7 8 Fourier Transform Along Columns: 10 + 0i -2 + 2i -2 + 0i -2 - 2i 26 + 0i -2 + 2i -2 + 0i -2 - 2i