Thread Subject: Questions about matlab FFT

Subject: Questions about matlab FFT

From: Ettos

Date: 22 Oct, 2009 17:41:07

Message: 1 of 6

Hi all,
I'm new to matlab FFT algorithm, I'm doing some tests with a simple sine
function. I've got two questions: one about amplitude and the other
about phase.
The code is this:

wave = sin(linspace(0,2*pi,100));
fs = 10000; % Sampling frequency
n = length(wave);
Y = fft(wave);
A = 2*abs(Y)/n; % Amplitude spectrum
phase = angle(Y)*180/pi;

1) Why am I getting amplitude A(2) = 1 only if I multiply abs(Y) by 2?

2) Why am I getting phase(2) = -90 and not zero?

Thank you very much!
Matteo.

Subject: Questions about matlab FFT

From: Matt

Date: 22 Oct, 2009 18:00:20

Message: 2 of 6

Ettos <matmailRIMUOVIQUESTO@europe.com> wrote in message <4ae09934$0$831$4fafbaef@reader5.news.tin.it>...
> Hi all,
> I'm new to matlab FFT algorithm, I'm doing some tests with a simple sine
> function. I've got two questions: one about amplitude and the other
> about phase.
> The code is this:
>
> wave = sin(linspace(0,2*pi,100));
> fs = 10000; % Sampling frequency
> n = length(wave);
> Y = fft(wave);
> A = 2*abs(Y)/n; % Amplitude spectrum
> phase = angle(Y)*180/pi;
>
> 1) Why am I getting amplitude A(2) = 1 only if I multiply abs(Y) by 2?

Because

sin(t)=(exp(jt)-exp(-jt)) /2j

from which you can clearly see that the Fourier coefficients are +/- 1/2j. So, you expect their amplitude to be 0.5

> 2) Why am I getting phase(2) = -90 and not zero?

Because your signal is a sine, not a cosine.

Subject: Questions about matlab FFT

From: Lars

Date: 22 Oct, 2009 18:16:21

Message: 3 of 6

Ettos <matmailRIMUOVIQUESTO@europe.com> wrote in message <4ae09934$0$831$4fafbaef@reader5.news.tin.it>...
> Hi all,
> I'm new to matlab FFT algorithm, I'm doing some tests with a simple sine
> function. I've got two questions: one about amplitude and the other
> about phase.
> The code is this:
>
> wave = sin(linspace(0,2*pi,100));
> fs = 10000; % Sampling frequency
> n = length(wave);
> Y = fft(wave);
> A = 2*abs(Y)/n; % Amplitude spectrum
> phase = angle(Y)*180/pi;
>
> 1) Why am I getting amplitude A(2) = 1 only if I multiply abs(Y) by 2?
>
> 2) Why am I getting phase(2) = -90 and not zero?
>
> Thank you very much!
> Matteo.

hint: fft returns a complex spec. ie one single-freq-signal --> two peaks
solution: just normalize by (n/2)

but:

sin(linspace(0,2*pi,100)) ???

what happened to your fs?

Subject: Questions about matlab FFT

From: Ettos

Date: 22 Oct, 2009 18:50:28

Message: 4 of 6

Lars wrote:


> hint: fft returns a complex spec. ie one single-freq-signal --> two peaks
> solution: just normalize by (n/2)
>

ok! Thanks!

>
> sin(linspace(0,2*pi,100)) ???
>
> what happened to your fs?

In what sense?
I supposed fs to be 10000Hz just to check if the ftt was right (sine
frequency of 100Hz).

Subject: Questions about matlab FFT

From: Ettos

Date: 22 Oct, 2009 19:04:37

Message: 5 of 6

Matt wrote:

>
> Because
>
> sin(t)=(exp(jt)-exp(-jt)) /2j
>
> from which you can clearly see that the Fourier coefficients are +/- 1/2j. So, you expect their amplitude to be 0.5

Thank you for you answer!

Maybe... math is my problem!
I thought that Fourier coefficients were real and in my case are a =
1.56 and b = 49.71 (FT = a - ib ). What do you mean for Fourier
coefficients?

Matteo.

Subject: Questions about matlab FFT

From: Matt

Date: 22 Oct, 2009 20:11:25

Message: 6 of 6

Ettos <matmailRIMUOVIQUESTO@europe.com> wrote in message <4ae0acc7$0$817$4fafbaef@reader5.news.tin.it>...
 What do you mean for Fourier
> coefficients?


I just meant the values of the spectrum

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com