Understanding the Discrete Fourier Transform and the FFT

MATLAB
29 Nov 202319:19

Summary

TLDRThis MATLAB Tech Talk video, hosted by Brian, delves into the Discrete Fourier Transform (DFT) and its efficient computation through the Fast Fourier Transform (FFT) algorithm. It explains why DFT is essential for analyzing signals in the frequency domain, which isn't always apparent in the time domain. The video clarifies concepts like the amplitude spectrum, power spectrum, and power spectral density, while demonstrating the DFT's process with a graphical MATLAB app. It also addresses practical questions about interpreting FFT results, the difference between one-sided and two-sided FFTs, and the significance of bin width and frequency resolution in signal processing.

Takeaways

  • 🔨 The script discusses the process of analyzing hardware vibrations using a shaker table and accelerometers, emphasizing the importance of understanding frequency components of the signal.
  • 📈 The Discrete Fourier Transform (DFT) is introduced as a method to transform signals from the time or spatial domain into the frequency domain, making it easier to identify signal features.
  • 🔍 The Fast Fourier Transform (FFT) algorithm is highlighted as an efficient way to compute the DFT, taking advantage of signal symmetries to reduce computational work.
  • 🌐 The script explains the concept of frequency spectrum, amplitude spectrum, and power spectrum, which provide insights into the signal that time-domain analysis alone cannot.
  • 🔄 The DFT equation is broken down to illustrate how the transformation works, involving multiplication of the time signal with sine and cosine signals of different frequencies.
  • 📊 A MATLAB app demonstration is used to visually explain the DFT process, showing how it correlates the time signal with different frequencies to produce a frequency domain signal.
  • 🔁 The script clarifies that the FFT returns both positive and negative frequencies, with the Nyquist frequency marking the boundary between them.
  • 📉 The difference between one-sided and two-sided FFT is explained, with one-sided FFT focusing only on the positive frequencies for analysis.
  • 📝 The importance of understanding the relationship between the variable k in the FFT and the actual frequency spectrum is discussed, including the concept of bin width.
  • 🔧 The script provides practical advice on how to perform a one-sided FFT in MATLAB, including scaling considerations and the impact on frequency resolution.
  • 🔬 The video concludes with a walkthrough of writing MATLAB code for a one-sided FFT, demonstrating the process from signal acquisition to frequency domain analysis.

Q & A

  • What is the purpose of using a shaker table in hardware testing?

    -A shaker table is used to apply random vibrations to hardware in order to simulate real-world conditions and measure its response, ensuring the hardware can withstand such vibrations.

  • How does an accelerometer help in vibration analysis?

    -Accelerometers are used to measure the response of the hardware to the vibrations applied by the shaker table, capturing the motion data which is then analyzed to understand the hardware's performance under vibration.

  • What is the main reason for transforming a signal from the time domain to the frequency domain?

    -The transformation helps in identifying the frequency components of a signal, which may not be evident in the time domain, and provides insights into the signal's characteristics that are not apparent in the time or spatial domains.

  • What is the Discrete Fourier Transform (DFT) and why is it used?

    -The DFT is a mathematical technique that transforms a signal from the time or spatial domain into the frequency domain, allowing for the analysis of the signal's frequency components.

  • How does the Fast Fourier Transform (FFT) algorithm improve upon the DFT?

    -The FFT algorithm is an efficient way to compute the DFT by taking advantage of the symmetries in the matrix multiplication involved in the DFT, reducing the number of calculations required.

  • Why is the absolute value of the FFT often considered in signal processing applications?

    -The absolute value of the FFT provides the magnitude of the frequency components, which indicates the presence and strength of specific frequencies in the signal without the need to consider their phase.

  • What is the difference between a one-sided and two-sided FFT?

    -A two-sided FFT shows both positive and negative frequencies, while a one-sided FFT focuses only on the positive frequencies, which is often sufficient when dealing with real signals due to the mirrored nature of the spectrum.

  • How does the Nyquist frequency relate to the FFT?

    -The Nyquist frequency is the highest frequency that can be accurately represented in the FFT and is based on the Nyquist sampling theorem, which states that the sampling rate must be at least twice the highest frequency of the signal.

  • What is meant by 'bin width' in the context of an FFT?

    -Bin width refers to the frequency resolution of the FFT, which is the distance in frequency between adjacent points in the spectrum.

  • How does padding a signal with zeros affect the FFT?

    -Padding a signal with zeros can improve the visualization of the FFT by reducing the bin width, but it does not increase the frequency resolution since no additional signal information is added.

  • Can you provide an example of how to calculate the one-sided FFT of a signal in MATLAB?

    -Yes, to calculate a one-sided FFT in MATLAB, you would first take the FFT of the signal, then take the absolute value to get the magnitude, and finally, select only the first half of the spectrum, including the Nyquist frequency if present, and plot it against the corresponding frequencies.

Outlines

00:00

🔍 Introduction to DFT and FFT

The script begins with an introduction to the Discrete Fourier Transform (DFT) and the Fast Fourier Transform (FFT), explaining their importance in analyzing hardware vibrations. It discusses how vibrations are measured and transformed from the time domain to the frequency domain using DFT, which is efficiently computed by the FFT algorithm. The video aims to answer common questions about DFT and FFT, providing insights into signal analysis that are not evident in the time domain alone. The example of distinguishing a 60 Hz component in two similar signals is used to illustrate the power of frequency domain analysis.

05:00

📊 Understanding the DFT Equation and its Visualization

This paragraph delves into the mathematical foundation of the DFT, explaining the transformation of a time-domain signal into the frequency domain. The script uses the DFT equation to demonstrate how the time signal is multiplied by a complex exponential, representing a sine and cosine of a specific frequency. A MATLAB app is introduced to visually show how the DFT correlates the time signal with different frequencies, highlighting the process of calculating the correlation for various frequencies and the concept of rotation through matrix multiplication.

10:04

🌐 Exploring FFT Efficiency and Practical Signal Analysis

The script explains the computational efficiency of the FFT, which takes advantage of symmetries in the DFT matrix multiplication to reduce calculation time. It emphasizes the practical use of FFT in signal processing, discussing the interpretation of the FFT's real and imaginary components and the significance of the absolute value for determining the magnitude of frequencies in a signal. The difference between one-sided and two-sided FFT is introduced, explaining the reflection of the spectrum and the implications of the Nyquist theorem on frequency analysis.

15:06

📈 Bin Width, Frequency Resolution, and One-Sided FFT Coding Example

The final paragraph discusses the concept of bin width in the FFT and how it relates to frequency resolution. It explains that a longer data period or more samples can lead to a narrower bin width and improved frequency resolution. The script also addresses the misconception that padding a signal with zeros increases resolution, clarifying that it only improves visualization without adding new signal information. The paragraph concludes with a MATLAB live script example that demonstrates how to calculate and plot a one-sided FFT, emphasizing the process of converting the FFT output to a frequency spectrum and the importance of scaling for certain applications.

Mindmap

Keywords

💡Vibration Analysis

Vibration analysis is a method used to study the mechanical vibrations that occur in various systems and structures. In the context of the video, it involves testing hardware on a shaker table to understand how it responds to random vibrations, which is crucial for ensuring the durability and reliability of the hardware. The script mentions this process to introduce the need for analyzing the signal's frequency components.

💡Shaker Table

A shaker table is a device used to apply controlled vibrations to a test object, simulating real-world conditions. In the video, the shaker table is essential for creating the random vibrations that the hardware must withstand, allowing for the measurement of its response to these vibrations.

💡Accelerometers

Accelerometers are devices that measure acceleration forces. They are used in the script to capture the hardware's response to the vibrations applied by the shaker table. The data from these devices is critical for performing vibration analysis and understanding the system's dynamic behavior.

💡Digital Computer

A digital computer is an electronic device that processes data using binary digits. In the video, the digital computer is used to capture and analyze the measurements from the accelerometers, transforming the analog signals into a digital format that can be processed and analyzed using software tools.

💡Discrete Fourier Transform (DFT)

The Discrete Fourier Transform is a mathematical technique that transforms a time-domain signal into its frequency-domain representation. The script explains that DFT is used to analyze the frequency components of the signal captured from the hardware, which is essential for understanding the signal's characteristics that are not evident in the time domain.

💡Fast Fourier Transform (FFT)

The Fast Fourier Transform is an efficient algorithm to compute the DFT. The script emphasizes the importance of FFT as it allows for a rapid calculation of the DFT, which would otherwise be computationally intensive, especially for signals with a large number of samples.

💡Frequency Domain

The frequency domain refers to the representation of a signal in terms of its frequency components. The video script explains that transforming a signal into the frequency domain can reveal important features of the signal, such as the presence of specific frequency components like the 60 Hz peak in the example given.

💡Amplitude Spectrum

The amplitude spectrum is a graphical representation of the amplitudes of the frequency components of a signal. In the context of the video, the amplitude spectrum is one way to visualize the results of the DFT or FFT, showing the magnitude of each frequency component present in the signal.

💡Power Spectral Density

Power spectral density is a measure of the power of a signal per unit frequency. The script mentions it as one of the insights that can be gained from frequency-domain analysis, which is particularly useful in understanding the distribution of power across different frequencies in a signal.

💡Nyquist Frequency

The Nyquist frequency is half the sampling rate of a signal and represents the highest frequency that can be accurately represented in the sampled data. The script refers to the Nyquist frequency when discussing the range of frequencies that can be analyzed using the FFT and the importance of considering both positive and negative frequencies in the analysis.

💡One-Sided and Two-Sided FFT

The script distinguishes between one-sided and two-sided FFT, explaining that a two-sided FFT includes both positive and negative frequencies, while a one-sided FFT focuses only on the positive frequencies. This distinction is important for interpreting the results of the FFT and understanding the spectrum of the signal.

💡Bin Width

Bin width refers to the frequency resolution of the FFT, which is the spacing between individual frequency components in the spectrum. The script discusses how bin width affects the ability to resolve close frequencies and how it can be adjusted by changing the length of the signal or by padding with zeros.

💡Signal Length

Signal length is the duration of the signal being analyzed, measured in samples or time. The video script explains that increasing the signal length can improve frequency resolution, making it easier to identify specific frequency components within the signal.

Highlights

Introduction to vibration analysis on hardware using a shaker table and accelerometers to measure responses.

Explanation of the importance of analyzing the frequency spectrum of signals for insights beyond the time domain.

Introduction to the Discrete Fourier Transform (DFT) and its role in transforming signals from the time domain to the frequency domain.

Efficiency of the Fast Fourier Transform (FFT) algorithm in computing the DFT by reducing computational redundancy.

The rationale behind using DFT to reveal signal features not evident in the time or spatial domains.

Demonstration of how DFT can differentiate between signals with and without a significant 60 Hz component.

The mathematical formulation of DFT and its interpretation involving complex exponentials.

Graphical demonstration of the DFT process using a MATLAB app to show the correlation between time signals and different frequencies.

Understanding the DFT as a matrix multiplication that represents a rotation from time to frequency domain.

Practical use of the absolute value of the FFT for analyzing the magnitude of frequencies without considering phase.

Difference between one-sided and two-sided FFT, and the implications for analyzing positive and negative frequencies.

The concept of bin width in FFT and its relation to frequency resolution and signal sampling.

Technique of padding signals with zeros to adjust bandwidth and improve frequency signal visualization without increasing resolution.

Writing code for a one-sided FFT in MATLAB, including plotting the magnitude of the response against frequency.

Explanation of scaling the one-sided FFT for applications requiring understanding of power in frequency bands.

Resources and links provided for further learning about FFT and related signal processing topics.

Encouragement to subscribe for more Tech Talk videos and mention of the organization of videos at mathworks.com.

Transcripts

play00:00

Imagine you're running a vibration

play00:01

analysis on some piece of hardware

play00:03

that you're developing.

play00:04

And the hardware is on a shaker table

play00:06

which applies random vibrations to the hardware.

play00:08

And you measure how the hardware responds with accelerometers.

play00:12

This measurement is captured with a digital computer.

play00:15

And, therefore, what you get out is a finite amount

play00:18

of data that is sampled at a regular interval.

play00:21

Now, in the case of vibrations, as well as

play00:24

many other applications, it's often

play00:26

helpful to look at the spectrum of the signal,

play00:29

that is, to separate the time domain

play00:31

signal into the frequency components that make it up.

play00:34

And, once we have frequency information,

play00:36

now we might choose to look at the amplitude spectrum

play00:39

or the power spectrum or the power spectral density.

play00:42

And each of these provide some insight into the signal

play00:45

that we can't get from the time domain alone.

play00:48

Now, with finite discrete data, like we have here,

play00:51

the first step to getting to any one of these representations

play00:54

is the Discrete Fourier Transform, or DFT.

play00:58

And the most efficient way to compute the DFT

play01:02

is using a Fast Fourier Transform algorithm, or FFT.

play01:06

And so, for this video, what I want to do

play01:08

is answer a few common questions that you might have

play01:11

regarding the DFT and the FFT.

play01:14

I think it's going to be pretty interesting and useful.

play01:17

So I hope you stick around for it.

play01:18

I'm Brian and welcome to a MATLAB Tech Talk.

play01:22

All right, so, to begin our first question,

play01:24

we want to ask is, why are we using

play01:26

the discrete Fourier transform?

play01:28

Well, the DFT transforms a signal from the time domain

play01:31

or a spatial domain like distance

play01:34

into the frequency domain.

play01:36

And one of the main reasons for making this transformation

play01:38

is because the features of a signal that we're interested in

play01:41

are not always obvious in the time or spatial domains.

play01:45

For example, here I have two time domain signals

play01:48

that are sampled at 200 hertz.

play01:50

And the question I have for you is, which of these

play01:53

has a significant 60 hertz component?

play01:56

It's not terribly obvious, right?

play01:58

They both look pretty similar.

play02:00

But if we transform them into the frequency domain,

play02:03

it's much easier to answer.

play02:05

I mean, it's clearly this first signal

play02:08

because there's this large 60hz peak.

play02:11

So we can use the frequency domain

play02:14

to understand the frequency makeup of a signal.

play02:17

To understand how the DFT is doing this transformation,

play02:20

we should look at the equation.

play02:22

And I know that there's lots of symbols here,

play02:24

but it's actually pretty straightforward.

play02:27

This blue variable x sub n is the discrete time domain signal

play02:31

that we're starting with.

play02:32

And we're going to transform it into the frequency domain

play02:35

signal x sub k.

play02:37

And, to do this, we multiply the time signal

play02:39

with this yellow part, which is e raised to a complex number.

play02:43

And if you're not familiar with complex exponentials,

play02:46

this is equal to the cosine of the exponent plus i

play02:49

times the sine of the exponent.

play02:51

So, essentially, what the DFT is doing

play02:54

is multiplying the time signal by a sine and cosine signal

play02:59

of a particular frequency given by this variable k.

play03:02

And then it's summing the result.

play03:05

And we do this summation for different values of k,

play03:08

or for different frequencies.

play03:12

All right, now, I think we can get a little intuition into how

play03:15

this equation works with just a simple graphical demonstration.

play03:20

All right, I made a little MATLAB app here

play03:22

to show you how the DFT works.

play03:24

Here the time signal x sub n is just a pure sine

play03:27

wave with 10 samples.

play03:28

So, per the definition of the DFT,

play03:31

we multiply this signal with e raised

play03:33

to an imaginary exponent, which I'm calling this whole thing

play03:36

the correlating signal.

play03:38

And, hopefully, the name will make sense shortly.

play03:42

Now, if we set k equals 0, then our correlating signal

play03:45

is just e to the 0, which produces

play03:48

a constant real value of 1 and an imaginary value of 0.

play03:52

And, when we multiply this with our time signal

play03:54

and then sum the result, we get a value that is really low.

play03:58

And, mathematically, this is because, when

play04:00

we multiply the time signal by 1,

play04:03

we get the exact same signal back.

play04:06

And so, essentially, we're really just summing

play04:08

the values in our time signal.

play04:10

And there are equal positive values--

play04:12

that's these four right here--

play04:14

as there are negative values, which are these four.

play04:17

And so they cancel each other out to near 0.

play04:21

And the way that we can think about this really low value

play04:24

is that our time domain signal is not correlated very well

play04:28

with a signal with 0.

play04:29

Frequency.

play04:31

Now let's move on to a new set of frequencies, say,

play04:34

k equals 1.

play04:35

Our correlating signal now consists

play04:38

of a sine and cosine wave with a period equal to the length

play04:41

of the time signal.

play04:42

And if we multiply these with x sub n and then sum the result,

play04:46

the value is larger.

play04:49

And we can visually see that the correlating

play04:51

signal is near the same frequency as our time signal.

play04:54

And so, at least for the imaginary component,

play04:57

which is perfectly out of phase with our time signal,

play05:00

the product of the 2 is always negative.

play05:03

And, therefore, the summation is also going to be negative.

play05:07

So there's a strong correlation between the two at k equals 1.

play05:12

And if we move to k equals 2, the correlation drops again.

play05:16

And this is all the DFT is doing.

play05:19

It's going through n different frequencies

play05:22

where k goes from 0 to n minus 1 and calculates the correlation

play05:26

between it and the time signal.

play05:30

That's pretty cool, that we can think of the DFT

play05:33

as producing the correlation between our time signal

play05:36

and a bunch of different frequencies.

play05:38

But there's another cool way that we

play05:40

can think about the DFT.

play05:41

And that is as a rotation with matrix multiplication.

play05:46

If we go back to the equation, we

play05:48

can rewrite it as a matrix multiplication. x sub n

play05:52

is just a 1 by n vector of discrete time data.

play05:56

And the yellow exponential is an n

play05:58

by n matrix of complex numbers.

play06:00

And the first column corresponds to the sines and cosines

play06:04

associated with k equals 0.

play06:05

And the second column is k equal 1,

play06:08

and so on, all the way up to k equals n minus 1.

play06:11

And now, when you perform this multiplication,

play06:14

for the first component of x of sub k,

play06:16

we get the inner product between the time signal

play06:19

and the frequencies at k equals 0.

play06:21

The second component is the inner product with k

play06:24

equals 1 and so on, all the way up.

play06:27

So, in this form, it's a bit easier

play06:30

to see that the DFT is performing

play06:31

this rotation between one set of basis functions, this x sub n,

play06:36

into another, this capital X of k.

play06:40

And this n by n matrix is what is

play06:42

achieving that rotation from time into complex exponentials.

play06:47

And, actually, this is a good segue into the fast Fourier

play06:51

transform.

play06:52

This matrix multiplication is easy to do

play06:54

if the length of the signal is relatively short.

play06:57

If there's only 10 samples, then this is a 10 by 10 matrix.

play07:00

But if you're working with a signal that

play07:02

has thousands or tens of thousands of samples,

play07:05

then performing this matrix multiplication

play07:07

could become computationally costly.

play07:10

But it turns out that, due to various symmetries

play07:13

in this multiplication, a lot of the operations are duplicated.

play07:17

And so you can perform a calculation once

play07:19

and then populate that answer in several locations.

play07:23

And FFT algorithms take advantage

play07:26

of duplicate operations to reduce the number

play07:28

of overall calculations.

play07:30

So they produce the exact same result as the DFT,

play07:34

just in a more efficient way.

play07:37

And, for a good explanation of the FFT algorithm

play07:39

and how these computational efficiencies actually

play07:42

made the DFT a viable option for science and engineering,

play07:46

check out Veritasium's excellent video on the topic.

play07:49

Link is in the description below.

play07:53

All right, now that we know that the ft is just an efficient way

play07:56

to calculate the DFT, I want to use the last bit of this video

play08:00

to answer a few practical questions

play08:02

and dive a little deeper into how we use

play08:05

and interpret the results.

play08:07

And the first question is, why do we sometimes

play08:10

just look at the absolute value of the FFT?

play08:15

Well, recall that the ft produces a complex result.

play08:18

And the way that we can interpret this

play08:20

is that the real part of the FFT is

play08:23

how well the time signal correlates to a cosine wave

play08:25

of a given frequency.

play08:27

And the imaginary part is how well

play08:29

it correlates to a sine wave of the same frequency.

play08:32

And knowing both of these is necessary

play08:35

if you want to know the phase of the frequency

play08:38

in your original signal or if you

play08:40

want to be able to reconstruct that signal exactly

play08:43

from frequency data.

play08:44

But if all you're interested in is the magnitude

play08:48

of the frequency, that is, how much of a particular frequency

play08:51

there is in your signal, regardless of phase,

play08:54

then you just have to look at the absolute value.

play08:59

So, for many signal processing applications,

play09:02

like answering our 60 hertz question,

play09:05

you don't need a real and imaginary component

play09:08

to determine that.

play09:09

You just need the magnitude.

play09:11

So we take the absolute value to get that magnitude.

play09:16

All right, so, for the next question,

play09:18

I want to talk about what the difference is

play09:20

between a one-sided and two-sided FFT.

play09:23

The answer involves understanding

play09:25

that the FFT returns both the positive

play09:28

and the negative frequencies, so two sides.

play09:30

And if you take the FFT starting at k

play09:32

equals 0 and go up to k equals n minus 1,

play09:35

then the positive frequencies are on the left,

play09:37

and the negative frequencies are on the right.

play09:39

And the Nyquist frequency is the boundary between the two.

play09:42

This is based on the Nyquist sampling theorem which

play09:45

states that we can only know signal information up

play09:48

to 1/2 of the sampling rate.

play09:51

Now, sometimes it's helpful to shift the FFT such

play09:54

that the negative signals are on the left

play09:56

and the positive are on the right.

play09:57

But it's not necessary as long as you

play09:59

understand which are negative and which are positive.

play10:03

All right, so back to the question.

play10:05

If you're looking at the entire range of the FFT,

play10:08

then this is a two-sided FFT whereas, with a one-sided FFT,

play10:12

you're just looking at the positive frequencies, just one

play10:15

side of the spectrum.

play10:17

And why would we do this?

play10:19

I mean, why would we throw away half of the information?

play10:23

Well, first off, if x sub n is a real signal, that

play10:27

is, it's not complex, and we take the absolute value

play10:31

of the FFT of x sub n, then the resulting spectrum

play10:35

is mirrored between the positive and the negative frequencies.

play10:39

And we can see why this is the case here.

play10:41

Let me hide the time signal so that we can just

play10:43

see the correlating signal.

play10:45

We know that, when k equals 0, this

play10:48

corresponds to 0 frequency.

play10:50

It's neither positive nor negative.

play10:52

But, for k equals 1, the frequency

play10:54

has a period of the length of the time signal.

play10:57

And going to k equals 2, the frequency

play11:00

has a period 1/2 of the length of the time signal.

play11:04

And this continues as k increases.

play11:06

We get 1/3 and 1/4 and so on, all the way up to the Nyquist

play11:11

frequency.

play11:12

Now, I know that this is going to be a little hard to see.

play11:15

But if we increase k beyond this point,

play11:17

the frequency starts to decrease.

play11:20

And not just that, but the frequency is also negative.

play11:24

And we can see that a little bit easier here.

play11:26

Notice that between k equals 9, which is the lowest

play11:29

negative frequency, and k equals 1, which is the lowest

play11:32

positive frequency, the correlating signal

play11:35

is the exact same frequency.

play11:37

It's just negative.

play11:39

Now, you'll notice that the real component isn't changing sine

play11:42

here.

play11:43

And that's because cosine is an even function.

play11:46

So the cosine of a positive number

play11:49

is the same as the cosine of a negative number.

play11:51

But the imaginary component does change sine

play11:54

since sine is an odd function.

play11:58

This means that, between k equals 1 and k equals 9,

play12:01

the magnitude of the FFT stays the same.

play12:04

And the same is true for k equals 2 and 8 and 3 and 7

play12:08

and so on until we reach the Nyquist frequency.

play12:12

Now, k equals 0 and k equals whatever the Nyquist is

play12:16

are both unique values that aren't

play12:18

duplicated anywhere else.

play12:19

So we want to keep both of those frequencies

play12:22

in a one-sided FFT, along with the rest

play12:24

of the positive frequencies.

play12:26

So, when there's an even number of time samples,

play12:29

like we have here with n equals 10, then, for a one-sided FFT,

play12:34

we need to keep n divided by 2 plus 1 points in our FFT.

play12:39

And that plus 1 accounts for the Nyquist frequency.

play12:43

However, if we have an odd number of samples,

play12:46

say, n equals 11, then we don't actually

play12:49

get the Nyquist frequency in the FFT

play12:50

because it sort of gets jumped over, in this case,

play12:53

between k equals 5 and k equals 6.

play12:55

And, therefore, with an odd number,

play12:58

we take n divided by 2, which leaves us with 1/2

play13:02

left over since it's odd.

play13:03

And, therefore, we round that up.

play13:05

So for 11 samples, the one-sided FFT would have 6 points in it.

play13:11

All right, we keep talking about positive and negative

play13:14

frequencies.

play13:14

But I haven't explained how the variable k corresponds

play13:18

to the exact spectrum frequency.

play13:20

We know that k equals 0 corresponds to 0 hertz.

play13:23

And I mentioned earlier that k equals 1 corresponds

play13:26

to a frequency with a period equal to the length of the time

play13:30

signal and that k equals 2 produces two waves

play13:33

in that same period and so on.

play13:35

So k up to the Nyquist frequency refers to the number of cycles

play13:40

within a time period equal to the length of the time domain

play13:44

signal.

play13:45

So if we want our spectrum frequency

play13:47

in hertz or in cycles per second,

play13:50

then it's just k cycles divided by the number

play13:53

of seconds in the signal.

play13:55

Or we can write this as k times the sampling frequency divided

play14:00

by the number of samples.

play14:02

So we can plot the FFT against frequency

play14:05

using this conversion.

play14:07

Now, you might also hear the term bin width.

play14:10

And this is the width of each frequency bin in the FFT.

play14:15

So if we go back to the spectrum that we calculated here,

play14:18

bin width is just the width in frequency

play14:21

between each of these samples.

play14:22

So how far is it between sample zero and sample one?

play14:25

And then from sample one to sample two and so on.

play14:28

And we already know this answer.

play14:31

We just set k equals to 1 in this equation.

play14:34

And we get the width between two samples.

play14:37

For example, I have this blue time signal

play14:40

that has a dominant 60 hertz frequency.

play14:42

And I have 0.1 seconds of data at 200 hertz.

play14:46

The FFT is on the right.

play14:48

And we can see that we have a bin width of 10 hertz,

play14:51

and there's this small peak at 60 hertz.

play14:54

Now, if we want a narrower bin width,

play14:58

it's as easy as using a longer period of data

play15:01

or just using more samples.

play15:03

Watch, as I increase the signal length,

play15:06

the bin width gets smaller.

play15:09

And we can also see that the 60 hertz peak really

play15:12

starts to become obvious.

play15:13

And this is because, with more data,

play15:16

we're also increasing the frequency resolution.

play15:18

We're getting more signal per frequency bin.

play15:23

However, we can also adjust the bandwidth

play15:25

without having to add additional data.

play15:28

And we can do that simply by padding the signal with 0's.

play15:32

For example, if we start with the exact same 0.1

play15:34

seconds of data and we add 0's to the end of the signal,

play15:38

then we can see that once again the bandwidth is reduced.

play15:43

However, even though this is improving visualization,

play15:46

it's not increasing frequency resolution.

play15:49

We're essentially just interpolating

play15:51

the frequency signal and filling it in with more dense sampling.

play15:56

Adding 0's doesn't change the overall frequency resolution

play15:59

since we're not adding any additional signal.

play16:02

And we can see that here with our 60 hertz peak.

play16:04

It's more like a little bump.

play16:08

All right, I hope that all of this bin width stuff

play16:11

is making sense.

play16:12

And I know we've talked about a bunch of different aspects

play16:14

of the FFT.

play16:15

So I think, to help everything sink in a bit

play16:18

and maybe make approaching the FFT a little less daunting,

play16:21

let's walk through writing the code for a one-sided FFT

play16:25

in a MATLAB live script.

play16:28

All right, to start, I have this time domain signal.

play16:31

It's just a pure 3-hertz sine wave.

play16:34

And there's 40 samples sampled at 40 hertz.

play16:37

So I've got 1 second of data.

play16:39

So now let's build up the one-sided FFT.

play16:43

And, first off, let's just take the FFT of the signal

play16:46

and then plot the result. And this might

play16:48

be how someone new might start.

play16:51

It's like, hey, I took the FFT, let me plot it and see

play16:53

what it looks like.

play16:54

But since the result is a complex vector, when

play16:57

you plot it, it shows both the real and imaginary components

play17:00

on a single graph.

play17:01

And it doesn't really look like much.

play17:04

So, instead, we could plot the real and imaginary components

play17:08

on two separate graphs.

play17:10

However, for this example, we just

play17:12

want to look at the magnitude of the response, which we can get

play17:15

by taking the absolute value.

play17:17

And check this out, we have our two peaks

play17:21

mirrored about the Nyquist frequency just as we expect.

play17:25

Now, to get the one-sided FFT, we just

play17:29

look at half of the spectrum.

play17:31

But, of course, since I have an even number of time samples,

play17:35

we need that plus one in there so that we can capture

play17:37

the Nyquist frequency as well.

play17:40

So so far, so good, except now we

play17:43

want to plot this against frequency in hertz.

play17:46

So we have k going from 0 to n over 2 to account for the 21

play17:51

samples in our one-sided FFT.

play17:53

And we convert that to frequency by multiplying it

play17:57

by the sample frequency divided by the number of samples.

play18:01

And, finally, we can plot this.

play18:03

And, as expected, the peak is right at 3 hertz.

play18:07

Now, you might often see that the one-sided FFT is scaled

play18:11

to account for the information in the negative frequencies

play18:13

that we excluded.

play18:14

But if your goal is to just understand

play18:17

which frequencies make up your time signal,

play18:19

then the scaling isn't necessary.

play18:21

For example, we can see here that there is a 3 hertz

play18:24

component in our signal.

play18:25

And it doesn't matter that the value of 20 at 3 hertz

play18:29

doesn't relate to anything specific.

play18:32

Now, scaling the one-sided FFT will be important

play18:35

if you want to understand a quantity,

play18:37

like how much power is in that frequency band.

play18:39

But we're going to talk about the power

play18:41

spectrum in a future video.

play18:43

And we're going to cover scaling there.

play18:45

All right, so, hopefully, what we covered in this video,

play18:47

each of these steps to get the one-sided FFT makes sense.

play18:50

And if you want to try this out yourself

play18:52

or check out some of the resources

play18:53

where you can learn more, I've left links

play18:55

to everything down below.

play18:57

Now, don't forget to subscribe to this channel

play18:59

so that you don't miss any future videos.

play19:01

And, also, you can find all of the Tech Talk videos

play19:04

across many different topics nicely organized

play19:06

at mathworks.com.

play19:08

And if you liked this video, then you

play19:09

might be interested to learn about the Fourier

play19:11

transform in our video on the Z transform.

play19:15

All right, thanks for watching.

play19:17

And I'll see you next time.

Rate This

5.0 / 5 (0 votes)

الوسوم ذات الصلة
DFTFFTSignal ProcessingMATLABFrequency DomainTime DomainNyquist FrequencyFourier TransformData AnalysisEngineering
هل تحتاج إلى تلخيص باللغة الإنجليزية؟