finding non-discrete frequencies in FFT

3 views (last 30 days)
alon
alon on 6 Oct 2013
Commented: dpb on 7 Oct 2013
i am trying to use FFT to find the Fourier transform of an EEG signal. for now i only manage to see frequencies which are natural numbers, but i want to be able to check also other numbers (e.g to see 5.1 and 5.8 Hz and not only 5 and 6 Hz). That is to say, i want a smoother curve of the frequency distribution.
the code I am using now:
function [X,freq]=positiveFFT(x,Fs)
N=length(x); %get the number of points
k=0:N-1; %create a vector from 0 to N-1
T=N/Fs; %get the frequency interval
freq=k/T; %create the frequency range
X=fft(x)/N; % normalize the data
%only want the first half of the FFT, since it is redundant
cutOff = ceil(N/2);
%take only the first half of the spectrum
X = X(1:cutOff);
freq = freq(1:cutOff);
------
%EEG.data(7,:,10) is the wave that i want to find the frequencies of, 128 is %the sampling rate
[YfreqDomain,frequencyRange] = positiveFFT(EEG.data(7,:,10),128);
positiveFFT = figure;
stem(frequencyRange,abs(YfreqDomain));
set(positiveFFT,'Position',[500,500,500,300])
xlabel('Freq (Hz)')
ylabel('Amplitude')
title('Using the positiveFFT function')
grid
axis([0,20,0,6])
clear 'positiveFFT';
thank you!

Answers (1)

dpb
dpb on 6 Oct 2013
Edited: dpb on 7 Oct 2013
frequency resolution df is 1/T = 1/(Ndt)
So, for baseband analysis to get higher resolution must have longer sample time at given sample rate (more samples iow).
If you can't take more data, you can artificially increase resolution (in essence interpolate in frequency domain) by padding the time domain with additional zeros and then doing the fft
  1 Comment
dpb
dpb on 7 Oct 2013
Not sure what's wrong -- I made an addition but it doesn't show in the Answer section on my viewer even though the text does if Edit it--so I'll add it as a comment, too...
ADDENDUM:
I didn't really look at your code in detail; I presumed since I saw Fs that you were computing the frequency from it and the vector length but I see that you indeed aren't --
function [X,freq]=positiveFFT(x,Fs)
N=length(x); %get the number of points -- ok
k=0:N-1;
T=N/Fs; % the frequency interval -- no, this is total time
% here's your problem -- you've got [0:N]/(N/Fs) --> 0:Fs
freq=k/T; % the frequency range -- not what you're looking for...
% use
df=Fs/N; % delta-f
freq=k*df; % instead
Then, I'd suggest using
floor(N/2)
instead of
ceil()
to avoid the overlap to set the actual length to use in displaying results, etc. but that's a minor point.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!