I'm new to EEGLab which is a MATLAB tool that used to analyze EEG data. I want to know if there is a specific way to extract the frequency of an EEG wave at a given time, to a text file using MATLAB.
For ex: 1s 11Hz, 2s 8Hz....
EEG waves range from delta waves starting at 0.5 Hz up to gamma waves typically at 40 Hz and more(even up to 100Hz), the issue you might consider here is that these frequencies are at all times present, since the brain never really "shuts down" certain frequencies. So what is studied in the frequencies in brain oscillations are changes in activity and power of certain frequency ranges. For instance, alpha waves are shown to have more power in the closed eyes state than open eyes. To address your question, you can:
See the EEGLAB wiki and follow a tutorial for which a sample data is also available and see what it can provide for you. See chapter 03 for example.
In the simplest way, see the power activity of EEG signals using Fast Fourier Transform(FFT) in MATLAB in time intervals if you'd like, for which you'll need to know at what intervals of time your data was sampled, this is called sampling frequency Ts. If you have this information, simply look up the Documents on MATLAB fft() or search around the web.
There are two ways to extract frequency information from EEG: 1) Using Fast Fourier Transform (FFT) based methods 2) Using Wavelet Transform (WT) based methods
Of course, you can perform the above analysis using EEGLAB toolbox, but most of the time you don't even need the toolbox to perform such analysis.
For example, if you want to perform FFT based frequency analysis on EEG, you could use some functions in MATLAB such as pmtm.
If you want to perform wavelet transform, you could use cwt.
There documentation is well written and all you need to do is just to feed the data as input and give appropriate parameters in each function.
If you want to know more about the basics, you could always go the EEGLAB wiki or other sources on the web.
Hope this helps!
From your question, it seems that you want to perform some kind of Time-Frequency analysis, that is an analysis in which you extract some frequency information, keeping time information. Importantly, you do not extract a "frequency" from the data (that is a odd request), but you extract some properties of a frequency of interest (typically the energy of a given frequency, expressed as "Power").
Normally, when calculating some basic frequency properties of your EEG data (as the channel spectra of your EEG (see here the EEGlab tutorial) you lose time information.
Time Frequency-analysis overcome this limitation and allow to get the kind of information you want, that is change in frequency energy over time (see here the EEGlab totorial on Time-Frequency).
Running a Time-Frequency analysis require some attention and can be tricky (you can easily make several mistakes) and I would suggest to you to check the lectures by Mike Cohen (check the video tutorials here) or his book "Analyzing Time Series data" (see here). From this resources you can learn perfectly what is a time-frequency analysis and have also some ideas on how Time-Frequency Data are stored in MATLAB.
Once you know that, you can move to your actual problem that is to export your frequency data (arguably, your Power on a given frequency on agiven time). You can see how to do checking this thread in the EEGLAB mailing list.
Below I wrote some code adapted from the thread above that you could as a starting point
%% first you run a time frequency analysis.
% Check the help of 'pop_timef' function for further information
[ersp itc powbase times freqs] = pop_timef( EEG, 1, 1, [-1000 2000] , [3 0.5] ,'type', ...
'phasecoher', 'topovec', 1, 'elocs', EEG.chanlocs, 'chaninfo', EEG.chaninfo, 'title',...
'Channel FPz power', 'padratio', 1, 'plotphase','off');
% select the ordinal number of the frequency you want to export
% NOTE: this means that you are selecting the 1st frequency (by default settings 6 Hz)
% and NOT the 1Hz frequency.
my_freq_n = 1
% to check the frequency selected
freqs(my_freq_n)
% my_time specifies the timepoint you want to export
my_time = 1500
% my_ersp stores the ersp value (that is the result of a specific kind of
% Time-Frequency analysis) for your selected time and your selected frequency.
my_ersp = ersp(my_freq_n, dsearchn(times', my_time))
% export the my_ersp object as a .txt file
save -ascii my_ersp.txt my_ersp
`