Brain computer Interface (EEG)

Discussion in 'Programmer's Corner' started by hanukaran, Mar 29, 2012.

  1. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    I'm Prabakaran Munusamy .Doing Final year project on 'Brainwave pattern recognition' . I'm using Matlab as My platform.I'm a beginner.I already learn to load the file to read the EEG data in Matlab using excel data. I got the graph but in amplitude and time. I need to change the time to frequency.I'm not so sure how to change it to frequency.Is that I need to use FFT. Can any one guide me please.I attached the picture of my result...please anyone can guide me..I can learn faster
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    I presume that your sampling frequency is 250Hz.
    Most of the amplitude is from -10 to +10 with some at -20 to +20.
    The signal to noise ratio is poor and amplitude is low.
    There is no EEG signal that I recognize.
    The problem is in the signal acquisition, electrodes and amplifiers.

    goggle EEG to see what to expect:

    http://en.wikipedia.org/wiki/Electroencephalography

    Please state the clinical conditions how the data is acquired (position, rest, sleeping, eyes closed, etc.)
     
    Last edited: Mar 31, 2012
    hanukaran likes this.
  3. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    actually my project is need to detect brainwave whether it is in alpha state or other condition.I try to get the data.Most of data is in EDF file .I'm searching data in txt file or excel file. Do you have any suggestion.Or please give me some time....i will try to get the data...I realy need your guide.I'm very glad that you reply my question.

    Thanks and regards,

    Prabakaran Munusamy
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    10 secs @ 250sps would be 2500 data points.
    Can you post a txt file of the data?
     
    hanukaran likes this.
  5. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    i agree with MrChips but if you think FFT will help, read matlab help or try this code sample

    Code ( (Unknown Language)):
    1.  
    2. function FFT_test
    3.  
    4. %% ********************************************
    5. %%      Basic example of FFT in MATLAB
    6. %%          provided by panic mode
    7. %% ********************************************
    8.  
    9. clc; clear all; close all; % always start fresh,
    10.                            % reset and close anything that may be open
    11.  
    12. f1 = 1750;                 % pick signal frequency, because here
    13.                            % we generate our own samples instead of
    14.                            % reading data from file for example
    15.            
    16. Fs = 512000;               % recall Nyquist sampling frequency, it must be
    17.                            % at least twice that of sampled signal
    18.                            % but it is better if it is higher than that
    19.  
    20. L = 100000;                % length of signal (number of sample values)
    21.  
    22. T  = 1./Fs;                % sampling period
    23. t  = [0:L-1]*T;            % time scale for time domain
    24. f = Fs/2*linspace(-1,1,L); % frequency scale for freq. domain
    25.  
    26. signal=cos(2*pi*f1*t);     % generated signal is anything we like
    27.  
    28. FFTsignal = fft(signal)/L; % fft of signal (freq domain)
    29.  
    30. figure();                  % always create new figure for your plots
    31.  
    32. subplot(2,1,1),plot(t,signal); % top graph is time domain signal
    33. axis([0 3/f1 -1.1 1.1]);   % set convenient axis limits for plot
    34. title('Signal in time domain'); % indicate what the plot represents
    35.  
    36. subplot(2,1,2),plot(f,abs(fftshift(FFTsignal))); % bottom is freq. domain
    37. axis([-2*f1 2*f1 -1.1 1.1]); % set convenient axis limits for plot
    38. title('Signal in frequency domain'); % indicate what the plot represents
    39.  
    40.  
     
    hanukaran likes this.
  6. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    the text file is about 23mb....But have choose some electrodes only which is T4,T6,FP2,F4,C4,P4.Maybe i can attached this file.
     
  7. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    Does this information can help....
     
  8. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    what is the sampling frequency? is it still 250Hz?
    if so then this is what first channel looks like:
     
    • eeg.jpg
      eeg.jpg
      File size:
      30.6 KB
      Views:
      40
    Last edited: Mar 31, 2012
    hanukaran likes this.
  9. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    Code ( (Unknown Language)):
    1.  
    A=xlsread ('C:\Users\PraBaKAraN\Desktop\mail\The data which tested T4 until P4')
    T4=A:),1),T6=A:),2),Fp2=A:),3),F4=A:),4),C4=A:),5),P4=A:),6)
    plot (T4)
    plot(abs(fft(T4)));

    is that i need to include the coding which you sent before this to get the first channel.
    Im not sure whether i'm in right path doing this project..can you guide me little specific...sorry ...:)
     
  10. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    you are on a right track but this is not quite done yet.

    graph looks ok but it is shifted version of FFT so
    - first half is positive frequencies (0..125Hz),
    - second half is negative frequencies (-125...0Hz)
    the second half is is simply mirrored version of first half.
    instruction fftshift corrects the shift allowing display of
    -125...+125Hz.


    bigger issue is that there is no indication of actual frequency.
    your graph shows 0...3000 which is not right if the sampling was done at 250Hz. (see attached)

    also what are the values of your y-axis?

    and finally, you don't create new figures. this means that each plot overwrites previous one.
    so you don't get to see output of "plot(T4)" because it is immediately replaced by
    output of "plot(abs(fft(T4)))". to fix this you need to use either subplot or create separate figures.
     
    Last edited: Apr 1, 2012
    powerinverter and hanukaran like this.
  11. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    this looks better:
     
    hanukaran likes this.
  12. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    something like this should work for any number of channels.
    it will display time and frequency domain scales correctly
    (should work for any length of recording).
    however, Matlab is interpreter meaning it is slow so don't go crazy on file size.

    Code ( (Unknown Language)):
    1.  
    2. function FFT_test
    3.  
    4. %% ********************************************
    5. %%      Basic example of FFT in MATLAB
    6. %%          provided by panic mode
    7. %% ********************************************
    8.  
    9. clc; clear all; close all;  % always start fresh,
    10.                             % reset and close anything that may be open
    11.  
    12. EEG=xlsread('eeg.xls');     % read in XLS file, then get...
    13. [L,ch]=size(EEG);           % length of recording and number of channels
    14.  
    15. Fs = 250;                   % specify sampling frequency
    16. T=1/Fs;                     % calculate sample period and ...
    17. t  = [0:L-1]*T;             % time scale for time domain plot
    18. f = Fs/2*linspace(-1,1,L);  % frequency axis for FFT plot
    19.                            
    20. for n = 1:ch                            % for each channel...
    21.     figure(n);                          % create new figure and plot..
    22.     subplot(2,1,1);                     % the top graph is...  
    23.     plot(t,EEG(:,n));                   % time domain signal
    24.     xlabel('seconds');                  % display units (seconds)        
    25.     title(['Channel: ',n+48]);          % give it some description
    26.     FFTch(:,n) = fft(EEG(:,n))/L;       % then do the FFT of signal
    27.     subplot(2,1,2);                     % bottom graph is...
    28.     plot(f,abs(fftshift(FFTch(:,n))));  % FFT in frequency domain
    29.     xlabel('Hz');                       % display units (Hz)    
    30. end  
    31.                                        
    32.  
     
    Last edited: Apr 1, 2012
    hanukaran likes this.
  13. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    thanks for coding..its really helpful...
    so from this frequency i got..i need to mentioned whether this data beta,alpha or delta...am I right sir.....
     
  14. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    sir another one ..if we use fft..is that means that the noise all removed? or should remove by other function? :)
     
  15. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    ...seriously???
     
  16. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    "The Fourier transform is useful for extracting a signal from a noisy background."
    i read in one journal....that's why i'm asking...or is that this data is enough to do the classification...
     
  17. panic mode

    Senior Member

    Oct 10, 2011
    1,320
    304
    if you collect some noisy signal, you can run it through FFT. this gives you frequencies and magnitudes of all components that make that signal (noise as well). to remove noise, you simply pick signals of interest (subset of what FFT gives you) and generate your own new signal OR clear (zero out) all unwanted frequencies and run inverse fourier transform. this will give you new signal but only with frequency components you picked (hopefully you picked the right ones).

    reading journals is fine but if you want to complete a project you better pick some book on signal processing and get up to speed with fourier. everything mentioned here is basics, probably 2nd year calculus. so, what are you studying?
     
    hanukaran likes this.
  18. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    actually i'm studying in Electronic (computer)..Degree..with the result im having here..is that i'm able to do the classification..:)
     
  19. bertus

    Administrator

    Apr 5, 2008
    15,647
    2,346
    hanukaran likes this.
  20. hanukaran

    Thread Starter New Member

    Mar 29, 2012
    21
    0
    You don't have to know everything, if you know where to find it.
    When you do ask questions, you may look stupid.
    When you do NOT ask questions, you will STAY stupid......hehe..like like
     
Loading...