Computing power of a specific EEG band using stft

14 views (last 30 days)
Hello,
I have a project with a simple purpose - I have to compute power of few bands of EEG signal using STFT and Welch method (I want to see STFT of EEG signal, PSD and compute power).
I'm in the beginning of code, but I already have some issues with it.
% Getting EEG signal
A = importdata('abs.txt'); % Import data from *.txt
N= 238.305; %input ('Enter overall time: '); % Overall time
fs= 128;%input ('Enter sampling rate: '); % Getting sampling rate
[s , r] = size (A); % Getting vector size
t=(0:1/fs:N)';% Creating time vector for future use
f=(-fs/2:fs/(length(t)-1):fs/2)'; % Creating frequency vector
[S,F,T,P]=spectrogram(A(:,2),256,20,256,fs); % STFT of a signal
spectrogram(A(:,2),256,20,256,fs,'yaxis'); % STFT of a signal
% Plotting
figure; % Plotting STFT of a signal and signal in time
subplot(2,1,2)
imagesc(T,F,abs(S)/length(A(:,2)))% STFT
colormap(jet(256))
title('STFT')
xlabel('Time [sec]')
ylabel('Frequency [Hz]')
axis ([ 0 N 2 25]) ;
xlabel('Time [Sec]'); ylabel('Frequency [Hz]');
subplot(2,1,1)
plot(t,A(1:end-1,2))% In time
axis ([0 N min(A(:,2)) max(A(:,2))])
title('Channel A2')
xlabel('Time [sec]')
ylabel('V [\muv]')
%Welch method
figure;
subplot(2,1,1) % TEST ONLY - original matlab plot
pwelch(A(:,2),fs)
subplot(2,1,2)
pxx=pwelch(A(:,2),fs); %TEST - Computing PSD
plot([0:fs],pxx), grid % TEST ONLY - PSD of a signal
xlabel('Normalized frequency : f/fs')
ylabel('PSD [w/rad]')
  1. If I'm using spectrogram I get STFT image, but by getting STFT matrix and plotting it I'm getting different image. And it is not matter of axis. Therefore, my question is : How does spectrogram works (I read the explanation, but there is no sign of it)?
  2. What is a best window(and length) for this type of task?
  3. By using pwelch I get vector of PSD, but resolution is very bad. For example to compute alpha band I have to sum 8-12 HZ. With fs 128 hz this band is barely single point. How may I improve resolution, without changing results?
Thank you!

Answers (0)

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!