Fourier Transforms - MATLAB & Simulink (2024)

Open Live Script

The Fourier transform is a mathematical formula that transforms a signal sampled in time or space to the same signal sampled in temporal or spatial frequency. In signal processing, the Fourier transform can reveal important characteristics of a signal, namely, its frequency components.

The Fourier transform is defined for a vector x with n uniformly sampled points by

yk+1=j=0n-1ωjkxj+1.

ω=e-2πi/n is one of the n complex roots of unity where i is the imaginary unit. For x and y, the indices j and k range from 0 to n-1.

The fft function in MATLAB® uses a fast Fourier transform algorithm to compute the Fourier transform of data. Consider a sinusoidal signal x that is a function of time t with frequency components of 15 Hz and 20 Hz. Use a time vector sampled in increments of 1/50 seconds over a period of 10 seconds.

Ts = 1/50;t = 0:Ts:10-Ts;x = sin(2*pi*15*t) + sin(2*pi*20*t);plot(t,x)xlabel('Time (seconds)')ylabel('Amplitude')

Fourier Transforms- MATLAB & Simulink (1)

Compute the Fourier transform of the signal, and create the vector f that corresponds to the signal's sampling in frequency space.

y = fft(x);fs = 1/Ts;f = (0:length(y)-1)*fs/length(y);

Plot the magnitude of the transformed signal as a function of frequency.

plot(f,abs(y))xlabel('Frequency (Hz)')ylabel('Magnitude')title('Magnitude')

The plot shows four frequency peaks, although the signal is expected to have two frequency peaks at 15 Hz and 20 Hz. Here, the second half of the plot is the mirror reflection of the first half. The discrete Fourier transform of a time-domain signal has a periodic nature, where the first half of its spectrum is in the positive frequencies and the second half is in the negative frequencies. The 30 Hz and 35 Hz frequency components in the plot correspond to the –20 Hz and –15 frequency components. To better visualize this periodicity, you can use the fftshift function, which performs a zero-centered, circular shift on the transform.

n = length(x);fshift = (-n/2:n/2-1)*(fs/n);yshift = fftshift(y);plot(fshift,abs(yshift))xlabel('Frequency (Hz)')ylabel('Magnitude')

Fourier Transforms- MATLAB & Simulink (3)

Noisy Signals

In scientific applications, signals are often corrupted with random noise, disguising their frequency components. The Fourier transform can process out random noise and reveal the frequencies. For example, create a new signal, xnoise, by injecting Gaussian noise into the original signal, x.

rng('default')xnoise = x + 2.5*randn(size(t));

Signal power as a function of frequency is a common metric used in signal processing. Power is the squared magnitude of a signal's Fourier transform, normalized by the number of frequency samples. Compute and plot the power spectrum of the noisy signal centered at the zero frequency. Despite noise, you can still make out the signal's frequencies due to the spikes in power.

ynoise = fft(xnoise);ynoiseshift = fftshift(ynoise);power = abs(ynoiseshift).^2/n; plot(fshift,power)title('Power')xlabel('Frequency (Hz)')ylabel('Power')

Fourier Transforms- MATLAB & Simulink (4)

Computational Efficiency

Using the Fourier transform formula directly to compute each of the n elements of y requires on the order of n2 floating-point operations. The fast Fourier transform algorithm requires only on the order of nlogn operations to compute. This computational efficiency is a big advantage when processing data that has millions of data points. Many specialized implementations of the fast Fourier transform algorithm are even more efficient when n has small prime factors, such as n is a power of 2.

Consider audio data collected from underwater microphones off the coast of California. This data can be found in a library maintained by the Cornell University Bioacoustics Research Program. Load and format a subset of the data in bluewhale.au, which contains a Pacific blue whale vocalization. Because blue whale calls are low-frequency sounds, they are barely audible to humans. The time scale in the data is compressed by a factor of 10 to raise the pitch and make the call more clearly audible. You can use the command sound(x,fs) to listen to the entire audio file.

whaleFile = 'bluewhale.au';[x,fs] = audioread(whaleFile);whaleMoan = x(2.45e4:3.10e4);t = 10*(0:1/fs:(length(whaleMoan)-1)/fs);plot(t,whaleMoan)xlabel('Time (seconds)')ylabel('Amplitude')xlim([0 t(end)])

Fourier Transforms- MATLAB & Simulink (5)

Specify a new signal length that is the next power of 2 greater than the original length. Then, use fft to compute the Fourier transform using the new signal length. fft automatically pads the data with zeros to increase the sample size. This padding can make the transform computation significantly faster, particularly for sample sizes with large prime factors.

m = length(whaleMoan);n = pow2(nextpow2(m));y = fft(whaleMoan,n);

Plot the power spectrum of the signal. The plot indicates that the moan consists of a fundamental frequency around 17 Hz and a sequence of harmonics, where the second harmonic is emphasized.

f = (0:n-1)*(fs/n)/10; % frequency vectorpower = abs(y).^2/n; % power spectrumplot(f(1:floor(n/2)),power(1:floor(n/2)))xlabel('Frequency (Hz)')ylabel('Power')

Fourier Transforms- MATLAB & Simulink (6)

Phase of Sinusoids

Using the Fourier transform, you can also extract the phase spectrum of the original signal. For example, create a signal that consists of two sinusoids of frequencies 15 Hz and 40 Hz. The first sinusoid is a cosine wave with phase -π/4, and the second is a cosine wave with phase π/2. Sample the signal at 100 Hz for 1 second.

fs = 100;t = 0:1/fs:1-1/fs;x = cos(2*pi*15*t - pi/4) - sin(2*pi*40*t);

Compute the Fourier transform of the signal. Plot the magnitude of the transform as a function of frequency.

y = fft(x);z = fftshift(y);ly = length(y);f = (-ly/2:ly/2-1)/ly*fs;stem(f,abs(z))xlabel("Frequency (Hz)")ylabel("|y|")grid

Fourier Transforms- MATLAB & Simulink (7)

Compute the phase of the transform, removing small-magnitude transform values. Plot the phase as a function of frequency.

tol = 1e-6;z(abs(z) < tol) = 0;theta = angle(z);stem(f,theta/pi)xlabel("Frequency (Hz)")ylabel("Phase / \pi")grid

Fourier Transforms- MATLAB & Simulink (8)

See Also

fft | fftshift | nextpow2 | ifft | fft2 | fftn | fftw

Related Topics

  • 2-D Fourier Transforms

External Websites

  • Fourier Analysis (MathWorks Teaching Resources)

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Fourier Transforms- MATLAB & Simulink (9)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Fourier Transforms
- MATLAB & Simulink (2024)

FAQs

How hard are Fourier transforms? ›

Fourier series and Fourier transform can be easily understood with analogy to vectors. Both rely on a mathematical operation called correlation. Once you understand correlation and the concept of a basis, you can easily understand Fourier analysis.

How do you solve a Fourier transform in Matlab? ›

Compute the Fourier transform of the signal, and create the vector f that corresponds to the signal's sampling in frequency space. y = fft(x); fs = 1/Ts; f = (0:length(y)-1)*fs/length(y); Plot the magnitude of the transformed signal as a function of frequency.

What is the Fourier transform application in Matlab? ›

The Fourier transform is a powerful tool for analyzing data across many applications, including Fourier analysis for signal processing. Use the Fourier transform for frequency and power spectrum analysis of time-domain signals. Transform 2-D optical data into frequency space. Smooth noisy, 2-D data using convolution.

Do engineers use Fourier transform? ›

In electrical power systems, the Fourier Transform plays a crucial role in analyzing voltage and current waveforms. Engineers use it to study the harmonics in power systems, which are unwanted frequency components that can cause issues such as equipment overheating and power quality problems.

What are the disadvantages of Fourier transform? ›

The major disadvantage of the Fourier transformation is the inherent compromise that exists between frequency and time resolution. The length of Fourier transformation used can be critical in ensuring that subtle changes in frequency over time, which are very important in bat echolocation calls, are seen.

What does a Fourier transform tell you? ›

Fourier Transform is a mathematical model which helps to transform the signals between two different domains, such as transforming signal from frequency domain to time domain or vice versa. Fourier transform has many applications in Engineering and Physics, such as signal processing, RADAR, and so on.

What is an example of a Fourier transform? ›

An example application of the Fourier transform is determining the constituent pitches in a musical waveform. This image is the result of applying a constant-Q transform (a Fourier-related transform) to the waveform of a C major piano chord.

What is the difference between DFT and FFT? ›

The algorithms for this special case are called fast Fourier transform (FFT). The advantages of the FFT include speed and memory efficiency. The DFT can process sequences of any size efficiently but is slower than the FFT and requires more memory, because it saves intermediate results while processing.

What is FFT in Simulink MATLAB? ›

A fast Fourier transform (FFT) is a highly optimized implementation of the discrete Fourier transform (DFT), which convert discrete signals from the time domain to the frequency domain. FFT computations provide information about the frequency content, phase, and other properties of the signal.

What is the formula of Fourier transform? ›

1.1 Fourier's integral formula. f(x)=12a0+∞∑n=1{ancos(nπxL)+bnsin(nπxL)}. f ( x ) = 1 2 a 0 + ∑ n = 1 ∞ { a n cos ⁡ ( n π x L ) + b n sin ⁡

What are the types of Fourier transform? ›

  • (i) The Fourier integral:
  • (ii) The classical Fourier series:
  • (iii) The discrete-time Fourier transform:
  • (iv) The discrete Fourier transform:

What is Fourier transform good for? ›

The Fourier Transform is a powerful mathematical tool used to analyze the frequency components present in a signal. It's perfect in the sense that it does exactly what it's mathematically designed to do: transform a function of time into a function of frequency.

What is the Fourier law in MATLAB? ›

For a flat surface, the Fourier law describes the transfer, Q = k ⋅ A D ( T A − T B ) , where: Q is the heat flow.

How difficult is the Fourier series? ›

Is fourier series easy? - Quora. Yes it is. Fourier series is used to represent any function in terms of a periodic function that is in terms of sines and cosines. The main advantage of using Fourier series is that decomposing a function(which is difficult to treat) into sine and cosine is easily solvable.

Which is easier Laplace or Fourier? ›

Answer. We use Laplace transforms instead of Fourier transforms because their integral is simpler. Fourier analysis is always the best option when looking at “frequency components,” “spectrum,” and so on. The Fourier transform is simply a signal's frequency spectrum.

Does the brain do Fourier transform? ›

The signal coming out of the inner ear is already broken down by frequency, with each nerve indicating that sounds in one particular narrow frequency band have been detected. The brain doesn't need to do a Fourier transform, because it's getting information that is already broken down by frequency.

Is the Fourier transform complex? ›

Each of these four transforms has a complex version and a real version. The complex versions have a complex time domain signal and a complex frequency domain signal. The real versions have a real time domain signal and two real frequency domain signals.

References

Top Articles
Latest Posts
Article information

Author: Patricia Veum II

Last Updated:

Views: 5950

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Patricia Veum II

Birthday: 1994-12-16

Address: 2064 Little Summit, Goldieton, MS 97651-0862

Phone: +6873952696715

Job: Principal Officer

Hobby: Rafting, Cabaret, Candle making, Jigsaw puzzles, Inline skating, Magic, Graffiti

Introduction: My name is Patricia Veum II, I am a vast, combative, smiling, famous, inexpensive, zealous, sparkling person who loves writing and wants to share my knowledge and understanding with you.