frequency vector in a fft

조회 수: 22 (최근 30일)
SYML2nd
SYML2nd 2019년 6월 13일
편집: Daniel Frisch 2020년 8월 31일
Hi all,
I am trying to do the fft of a signal (here attached cc.txt), unfortunately I do not understand which frequency I should associate at each value of the fft, in other word I did not understand how to create the frequency vector. I have tried to apply what I've read here https://it.mathworks.com/help/matlab/ref/fft.html and I have done this code, but unfortunately the frequency vector and the fft have different lenght, so an error results.
Can you help, what I am doing wrong in this code and why???
Thank you in advance
cc1=readtable('cc.txt')
cc=table2array(cc1(:,2:2))
L=length(cc)
ccf= fft(cc)
Tinc=0.001
Fs=1/Tinc
fn=Fs/2
L=length(cc)
f = Fs*(0:(L/2))/L;
plot(f,ccf)

채택된 답변

Star Strider
Star Strider 2019년 6월 13일
Try this:
plot(f,ccf(1:numel(f))*2)
That should do what you want. (It plots the ‘positive half’ of the fft result, from D-C (0 Hz) to the Nyquist frequency, and the correct amplitude, multiplying the returned amplitude by 2.)

추가 답변 (3개)

SYML2nd
SYML2nd 2019년 6월 13일
First of all thank you for your answer. But I have still doubts?
So was my frequency correct?
I didn't get why you multiplied the returned amplitude by 2
So, doing
ccf(1:numel(f))
am I am taking just part of the fft (from the first to the lenght of the f vector)?
Am I discarding a part of the fft because it exceeds the Nyquist limit?
Thank u in advance
  댓글 수: 1
Star Strider
Star Strider 2019년 6월 13일
The Fourier transform output represents both the ‘positive’ and ‘negative’ frequencies (on either side of 0 Hz), so the energy is equally divided between the two sides. Multiplying by 2 corrects for this and approximates the amplitude of the time-domain signal.
Am I am taking just part of the fft (from the first to the lenght of the f vector)?
Am I discarding a part of the fft because it exceeds the Nyquist limit?
Exactly. It actually does not exceed the Nyquist frequency (although that is the maximum frequency you can uniquely represent in a sampled signal). It instead eliminates the mirror-image negative half of the fft output. You can see this by constructing an appropriate frequency vector, then using fftshift on both the frequency vector and the fft output. If ‘Fn’ is the Nyquist frequency, the result of the fftshift function will plot the fft output from -Fn to +Fn.

댓글을 달려면 로그인하십시오.


Daniel Frisch
Daniel Frisch 2020년 8월 31일
편집: Daniel Frisch 2020년 8월 31일
You can use my little function called easyFFT that does exactly that for you: it calculates & returns a frequency vector along with the spectrum.

Georges Theodosiou
Georges Theodosiou 2020년 10월 13일
Mr. Francesco Saverio Ciani,
Please lety me help you a bit. Function findpeaks() helps in your problem.
With regards and friendship, Georges Theodosiou

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by