how to obtain the frequencies from the fft function

조회 수: 541 (최근 30일)
sharvari samant
sharvari samant 2013년 9월 30일
댓글: Daniel 2022년 12월 15일
after the fft of the input signal,how to get the frequencies?
  댓글 수: 2
irem asci
irem asci 2020년 4월 6일
I have 10 seconds of EEG recording that I have used fft on. How can I obtain the frequencies?
numberOfSamples = 20000
samplingRate = 2000
eegFile = readtable('Hit_0_EEG1.txt');
electrodeTimeSeries = eegFile.EEG1;
timeSeries = electrodeTimeSeries(1:numberOfSamples);
y = fft(timeSeries);
posFreq = y(1:(numberOfSamples/2));%
spec = abs(posFreq);
Matan Dor hai
Matan Dor hai 2022년 5월 29일
fs = 2000; % sample rate N = len(your_data); % 20000 in your case fshift = (-N/2:N/2-1)*(fs/N); Y = fftshift(fft(your_data); Y = abs(Y).^2 / N; plot(fshift,Y) % 2 sided fft
fshift = (0:N/2-1)*(fs/N); Yshift = Y(N/2+1:end); plot(fshift,Yshift) % right sided fft

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

답변 (6개)

dpb
dpb 2013년 9월 30일
Frequency is totally dependent upon the sample rate of the time signal and duration.
Sampling relationships --
Fmax=1/2dt; T=Ndt; df=Fmax/(N/2); T=1/df

Wayne King
Wayne King 2013년 9월 30일
편집: Wayne King 2013년 11월 7일
dpb is correct, you can use that to create a meaningful frequency vector
For an even length signal, the most common interval is (-Fs/2, Fs/2]
Fs = 1000;
t = 0:1/Fs:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
xdft = fftshift(fft(x));
df = Fs/length(x);
freq = -Fs/2:df:Fs/2-df;
plot(freq,abs(xdft))
For an odd-length signal, it's common to have an open interval (-Fs/2,Fs/2) where the starting point is -Fs/2+ df/2 and the ending point is Fs/2-df/2
Fs = 1000;
t = 0:1/Fs:1;
x = cos(2*pi*100*t)+randn(size(t));
xdft = fftshift(fft(x));
df = Fs/length(x);
half_res = df/2;
freq = -Fs/2+half_res:df:Fs/2-half_res;
plot(freq,abs(xdft))
Of course for a real-valued signal, if you are only interested in magnitude, you only need 1/2 the frequency axis and magnitudes.
If you have the Signal Processing Toolbox, you can use periodogram to get a power spectrum or power spectral density estimate that will output a frequency vector for you.
  댓글 수: 1
Daniel
Daniel 2022년 12월 15일
Are you sure the frequency order is not the following? Not sure why Matlab does not include this in the documentation.
freq = Fs/N*[(0:N/2) -1*((N/2-1):-1:1)]
Unrecognized function or variable 'Fs'.

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


Daniel Frisch
Daniel Frisch 2020년 11월 12일
easyFFT is not part of Matlab itself, but you have to download it and put the path where it is located to Matlab's path, for example using the addpath() function.
I also helped you with PCA. You have to differentiate between the PCA vector (coeff) in the 3D multivariate space, and the time signals in x,y,z data(:,2:4) or the time signals in the PCA base system, score.
addpath('path/to/folder/of/easyFFT.m')
% Generate random data
L = 1000;
Fs = 5000;
t = (1:L)'/Fs;
f = 200;
data = [ t, sin(2*pi*f*t), cos(2*pi*f*t), t*0];
data(:,2:4) = data(:,2:4) + randn(size(data(:,2:4)))*.1; % add some noise
% Extract data
t = data(:,1);
L = size(data,1);
Accel = data(:,2:4);
% Perform PCA
[coeff,score,latent] = pca(Accel); % need to identify the dominant tremor axis of the 3D accelerometer
% Plot multivariate data in 3D
figure()
plot3([zeros(1,3);(coeff(:,1).*sqrt(latent))'], [zeros(1,3);(coeff(:,2).*sqrt(latent))'], [zeros(1,3);(coeff(:,3).*sqrt(latent))'], 'DisplayName','PCA Base')
hold on
scatter3(data(:,2), data(:,3), data(:,4), 'DisplayName','Data')
axis equal
xlabel('x'), ylabel('y'), zlabel('z')
legend;
% Plot time data, separate for each PCA axes
figure();
plot(t,score, 'DisplayName','Accel along PCA axes');
% 1D Time signal along most dominant tremor axis
score1 = score(:,1); % extract signal projected on most dominant tremor axis coef(:,1)
[Y,f] = easyFFT( score1, length(score1), 1, Fs );
figure();
plot(f, abs(Y), 'DisplayName','Dominant Tremor FFT');
  댓글 수: 7
Daniel Frisch
Daniel Frisch 2020년 11월 13일
I'm not sure, maybe download easyFFT again, make sure you use Matlab R2020b, and otherwise send me a working example to daniel.frisch\at\posteo.de.
KR
KR 2020년 11월 15일
Thanks, Daniel. Re-downloading easyFFT resolved the issue. Thanks again for all of your help!

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


Daniel Frisch
Daniel Frisch 2020년 8월 31일
You can use my little tool easyFFT. It automatically calculates the frequency vector in addition to the FFT.
  댓글 수: 2
KR
KR 2020년 11월 12일
Hi Daniel,
Do you mind identifying my error in using your easyFFT function? Please note that I need to perform the easyFFT on the first component derived from pca (which I haven't been able to work yet).
data = table2array(acceler);
t = data(:,1);
L = size(data,1);
Accel = data(:,2);
Fs = 5000;
Fn = Fs/2;
coeff = pca(Accel); %need to identify the dominant tremor axis of the 3D accelerometer
figure()
plot(pca(Accel))
legend({'X';'Y';'Z'})
[Y,f] = easyFFT(Accel); %error states 'undefined function or variable 'easyFFT'
Daniel Frisch
Daniel Frisch 2021년 10월 13일
Hi, the "undefined function or variable" error means that the function is not on the path. Either put the file easyFFT.m in your current folder, or add the folder containing it via the addpath() function.

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


Jiahaw Fu
Jiahaw Fu 2021년 10월 12일

Mark Newman
Mark Newman 2022년 5월 16일
The FFT gives you a list of results. Each item in the list represents a sinusoid with a different frequency. The position of each item in the list tells you its frequency. See the following video for more details: https://www.youtube.com/watch?v=3aOaUv3s8RY

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by