Fourier transfom using matlab help

In summary, to plot sin(2*pi*t/P) and cos(2*pi*t/P) you need to use the "re,im" function which takes a vector of time samples and plots the sin(2*pi*t/P) values and the cos(2*pi*t/P) values as pairs.
  • #1
gustavo_a1986
1
0
Fourier transfom using matlab...help
where can i get files .m about this?
 
Physics news on Phys.org
  • #2
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:
  • #3
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".
 
  • #4
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.
 

1. What is a Fourier transform and why is it important?

A Fourier transform is a mathematical operation that decomposes a time-dependent signal into its constituent frequencies. It is important because it helps us understand the frequency components of a signal and can be used for tasks such as filtering, noise reduction, and data compression.

2. How is a Fourier transform performed using Matlab?

In Matlab, a Fourier transform can be performed using the fft function. This function takes in a vector of data and returns the discrete Fourier transform of the data.

3. What is the difference between a one-dimensional and two-dimensional Fourier transform?

A one-dimensional Fourier transform is used for signals that vary over time, while a two-dimensional Fourier transform is used for images or data that varies over both time and space. A two-dimensional Fourier transform can also be thought of as a combination of two one-dimensional transforms, one for the horizontal axis and one for the vertical axis.

4. How can I interpret the results of a Fourier transform?

The results of a Fourier transform will show the frequency components of the signal, with the amplitude representing the strength of each frequency. A higher amplitude indicates a stronger presence of that frequency in the signal. The phase of each component can also be analyzed to understand the relationship between different frequencies in the signal.

5. Are there any limitations or caveats to using Fourier transforms in Matlab?

One limitation of using Fourier transforms in Matlab is that the data being analyzed must be discrete and evenly spaced. Additionally, the results of a Fourier transform are affected by the length of the data being analyzed, so it is important to make sure the data is properly padded or truncated to avoid artifacts in the results.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
963
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
32
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
Back
Top