Fourier transfom using matlab help

  • Context: MATLAB 
  • Thread starter Thread starter gustavo_a1986
  • Start date Start date
  • Tags Tags
    Fourier Matlab
Click For Summary

Discussion Overview

The discussion revolves around using MATLAB for performing Fourier transforms, specifically focusing on the Fast Fourier Transform (FFT) function and its applications in plotting functions involving sine and cosine. Participants seek assistance with MATLAB code and understanding the underlying concepts of Fourier transforms.

Discussion Character

  • Technical explanation
  • Homework-related
  • Exploratory

Main Points Raised

  • One participant requests help finding .m files related to Fourier transforms in MATLAB.
  • Another participant provides a detailed example of using the FFT function to plot a specific function, explaining how to construct the input vector for the FFT based on the function's components.
  • There is a mention that FFT and IFFT are built-in commands in MATLAB and not implemented as .m files.
  • A separate inquiry is made about computing and plotting sine and cosine functions using a specific function format, asking for clarification on how to return the respective vectors for sine and cosine values.

Areas of Agreement / Disagreement

Participants generally agree on the use of built-in FFT commands in MATLAB, but there are multiple inquiries and examples presented without a consensus on the best approach for specific tasks.

Contextual Notes

Some assumptions about the input vectors and their construction for the FFT are not fully detailed, and there may be dependencies on the definitions of terms used in the context of Fourier transforms.

gustavo_a1986
Messages
1
Reaction score
0
Fourier transfom using matlab...help
where can i get files .m about this?
 
Physics news on Phys.org
The command you need to use is fft(V,n)

Let's look at example...

Let's suppose we want to plot the function f(t) = 3 + cos(2t) - 4sin(6t)
using the discrete Fourier transform

first we need to define a vector for the time interval

t = linspace(0,2*pi,4096); should suffice

(that is we will create a vector of 4096 evenly spaced number between 0 and 2*pi)

now we will write your function

alrighty, in our vector, V, that is to be used in the fft command

the first element corresponds to any constants (or items of zero order frequency)

thus the first element of V will be 3.

The next frequency, 1, does not show up, so the second element of V is zero

The next frequency, 2, appears in a cosine and the amplitude of this frequency is 1 (the leading coefficient in front of cos(2t)).

So our vector V is now [3 0 1].

But how do we differentiate between a cosine and a sine? Well the cosine is the real part of the decomposition of exp(i*theta). So what we really need to take is the real part of this vector. So the first part of this function can be written as

real(fft([3 0 1],4096)) (need same # of elements both t and the fft)

We also need to add in the sine term

sin corresponds to the imaginary parts of the decomposition of exp(i*theta)
The only sine term has a frequency of 6 with amplitude -4. Thus,

V = [0 0 0 0 0 0 4];

Because exp(i*theta) = cos(theta*t) - i*sin(theta*t)

we must actually take the opposite of any amplitudes with imaginary functions associated with them. Thus if we had the function

h(t) = i + 3sin(2t) - 5sin(3t) our vector V must be [-1 0 -3 5];
make sense?

remember, the first element corresponds to constant
the second will correspond to frequency of order 1
thus the seventh element will correspond to frequencies of order 6.

to incorporate the sine term its fft is given by

imag(fft([0 0 0 0 0 0 4],4096))

so the entire code could be written as


t = linspace(0,2*pi,4096);

V1 = [3 0 1];
V2 = [0 0 0 0 0 0 4];

ft = real(fft(V1,4096)) + imag(fft(V2,4096));
gt = 3 + cos(2*t) - 4*sin(6*t);

if we wanted to plot to make sure...

plot(t,ft,t,gt,'g-'); grid on
title('Plot of 3 + cos(2t) - 4sin(6t)')
ylabel('f(t)')
xlabel('t')

this should produce a plot with two overlapping curves. hope this helps
 
Last edited:
gustavo_a1986 said:
Fourier transfom using matlab...help
where can i get files .m about this?

I believe that fft and ifft are inbuilt commands and are not implemented as "m files".
 
Help

How to compute and plot sin(2*pi*t/P) and cos(2*pi*t/P) using [re,im}=plot_pair(t,P) where t is a vector of time samples to be computed and plotted and P is the period of the sin/cosine pair to compute.

Return: re-vector of same length as t contains sin(2*pi*t/P) values
im-vector of same length as t containing cos(2*pi*t/P) values

this makes use of the complex numbers somehow where.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 32 ·
2
Replies
32
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
5
Views
3K