Code covered by the BSD License  

Highlights from
Brain-Machine Interface (BMI) based on Electroencephalography (EEG)

image thumbnail

Brain-Machine Interface (BMI) based on Electroencephalography (EEG)

by

 

Real-Time Discrete Wavelet Transform and ANFIS classifier for Brain-Machine Interface based on EEG

[Coeffs,L]=wtAnalysis(data,level,wName,Fs,plotv)
function [Coeffs,L]=wtAnalysis(data,level,wName,Fs,plotv)
% This function was written to anayze signals using Discrete Wavelet 
% Transform (DWT).

% data: vector nx1 or 1xn
if iscolumn(data)
    data=data';
end
% Compute DWT coefficients
[C,L] = wavedec(data,level,wName);
wpt = wpdec(data,level,wName);
wt=wp2wtree(wpt);
% Create DWT coefficients matrix
Coeffs=zeros(length(L)-1,L(length(L)-1));
temp=1;
for i=1:length(L)-1
    Coeffs(i,:)=[C(temp:L(i)+temp-1),zeros(1,L(length(L)-1)-L(i))];
    temp=L(i)+temp;
end
% Create time vector
temp=int16((length(L)-1)/2);
temp=double(temp);
t=0:1/Fs:(length(data)-1)/Fs;
% Plot data when user needs it
if plotv
    if temp<=4
%       Create white and fullscreen figure
        figure;
        set(gcf, 'Position', get(0,'Screensize')); 
        set(gcf,'Color',[1,1,1]);
%       Plot original signal
        subplot(temp+1,1,1);
        plot(t,data,'k');
        title('Signal','fontsize',12,'FontWeight','bold');
        xlabel('Time (sec)');
        xlim([0 max(t)]);
        ylim([min(data),max(data)]);
        ylabel('Voltage (mV) ');
%       Plot coefficients
        for i=1:length(L)-1
            if i==1
                subplot(temp+1,2,i+2);
                plot(linspace(0,max(t),L(i)),Coeffs(i,1:L(i)),'k');
                ylabel(['cA_',num2str(level)],'fontsize',12,'FontWeight','bold');
                xlim([0 (length(data)-1)/Fs]);
                ylim([min(Coeffs(i,1:L(i))),max(Coeffs(i,1:L(i)))]);
            else
                subplot(temp+1,2,i+2);
                plot(linspace(0,max(t),L(i)),Coeffs(i,1:L(i)),'k');
                ylabel(['cD_',num2str(level+2-i)],'fontsize',12,'FontWeight','bold');
                xlim([0 (length(data)-1)/Fs]);
                ylim([min(Coeffs(i,1:L(i))),max(Coeffs(i,1:L(i)))]);
                if i==length(L)-2||i==length(L)-1
                    xlabel('Time (sec)');
                end
            end
        end
    else
        disp('Too many levels to plot');
    end
end
% Print range of each wavelet decomposition level
if plotv
    C_f=Fs/2;
    for i=1:level;
        disp(['cD',num2str(i),': ',num2str(C_f/2,4),'-',num2str(C_f,4),' Hz']);
        C_f=C_f/2;
        if i==level
           disp(['cA',num2str(level),': 0-',num2str(C_f,4),' Hz']);
        end
    end
end

Contact us