Making Frequency vs. Time Plot from FFT using EEG Data

89 vues (au cours des 30 derniers jours)
Evan Haley
Evan Haley le 7 Avr 2020
Commenté : dpb le 8 Avr 2020
I am performing FFT on EEG data. My ultimate goal is to have a frequency by time plot. However, the range of frequencies should be from 0Hz to 120Hz. My FFT results give me frequencies that are in the 10^4 range. How can I limit these frequencies so that my results are in the correct range? Below is my code. My sampling rate is 2kHz and the number of samples is 20,000. Any help would be appreciated I understand Foureier Transforms but I am new to MatLab.
time = xlsread('Time.xlsx');
electrodeTimeSeries = eegFile.EEG1;
timeSeries = electrodeTimeSeries(1:numberOfSamples);
y = fft(timeSeries);
posFreq = y(1:(numberOfSamples/2)); %
spec = abs(posFreq);
plot(time,spec);

Réponses (1)

dpb
dpb le 7 Avr 2020
Modifié(e) : dpb le 8 Avr 2020
Sampling frequency, Fs = 2 kHz --> dt = 1/Fs
Fmax = 1/2dt --> Fs/2 --> Fmax = 1 kHz
The signal is sampled such that baseband FFT will have frequency of 0-1 kHz. You may only be interested in 0-120 Hz because that's where all the action is in the signal, but you'll have calculated 0-1 kHz. Matlab doesn't have a builtin zoom FFT; you'll just need to only take the section of the result of interest.
See doc fft for example of one-sided PSD from time signal; significant points using your variables would be
Fs = 2000; % Sampling frequency
T = 1/Fs; % Sampling period
L = numel(time); % Length of signal
y = fft(timeSeries); % FFT the signal -- 2-sided frequency, complex
P2 = abs(Y/L); % 2-sided PSD -- 2-sided frequency, real magnitude
P1 = P2(1:L/2+1); % 1-sided PSD -- 1-sided frequency, real magnitude
P1(2:end-1) = 2*P1(2:end-1); % Scale to match time series magnitude (*)
posFreq = Fs*(0:(L/2))/L; % I'd use 'f' here for a variable, but am using your nomenclature
From your information above, presuming it is correct, with Fs=2000 and L=20000; then we'll find that
>> f=Fs*(0:(L/2))/L;
>> [f(1) f(end)]
ans =
0 1000
>>
as we suspected early on. Also, then
>> df=f(2)-f(1)
df =
0.1000
>>
So, to keep the first 120 Hz of the PSD, need 120/df --> 1200 elements.
I have no idea what you intend by the statement "My ultimate goal is to have a frequency by time plot."
The entire time series is converted in the FFT so the frequency is the content of the entire waveform. If you intend to look at some portion of the time signal and compare a given peak or somesuch, then you would have to process the time series over the desired time sections and compare those results.
  4 commentaires
Evan Haley
Evan Haley le 8 Avr 2020
Hello dpb
Your response was very helpful. I have achieved an amplitude by frequency plot with the correct results. When I mentioned the frequency by time plot, I am trying to develop a graph that shows how frequencies change over the duration of data collection. This would then be turned into a heat map later.
dpb
dpb le 8 Avr 2020
OK, I figured that was where you were headed...if have the Signal Processing TB, look at pspectrum with the 'spectogram' option. It also has the facility to return only a section of the overall frequency range.
To just do FFT/PSD with time you'll have to segment the signal into intervals and process each individually.

Connectez-vous pour commenter.

Catégories

En savoir plus sur EEG/MEG/ECoG dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by