21 September 2022 0 4K Report

I am encountering some challenges with single channel and multichannel EEG DMD MATLAB code. Can someone help please?

clc

clearvars

close all

%%

[Signal, Fs] = ............................... % EEG signal

% i = 13400;

i = 11100; % number of samples

n = 0:1/Fs:799/Fs; % Range

mode_sel=12;

%%

Signal = hamming(800).*Signal(i+1:i+0.05*Fs); % preprocessing noise or artifact remove

%%

K = 650;

X = hankel(Signal(1:K),Signal(K:end-1)); % hankelization of 1st row

% X = HankelMatrix(Signal(1:end-1),650);

Xprime = hankel(Signal(2:K+1),Signal(K+1:end));

% Xprime = HankelMatrix(Signal(2:end),650);

[P,L,b] = DMD(X,Xprime,mode_sel);

% O = log1(L)*1000;

sigmodes = zeros(800,mode_sel);

Xhat = zeros(650, 151);

for i = 1:mode_sel

for j = 1:151

Xhat(:,j) = P(:,i)*L(i,i)^(j-1)*b(i); % Unknown equat

end

sigmodes(:,i) = [Xhat(:,1); Xhat(end,2:end)'];

end

figure(1)

subplot(7,2,[1 2])

plot(n,Signal,'b','LineWidth',1)

axis tight

set(gca,'FontSize',14)

for i = 1:mode_sel

subplot(7,2,i+2)

plot(n,real(sigmodes(:,i)),'b','LineWidth',1) % plot

axis tight

set(gca,'FontSize',14)

end

xlabel('Time (s)')

ylabel('Amplitude')

%%

figure(2)

subplot(5,1,1)

plot(n,Signal,'b','LineWidth',1)

axis tight

set(gca,'FontSize',14)

xlabel('Time (s)');

ylabel('Amplitude');

title('(a)')

subplot(5,1,[2 3 4 5])

hht(real(sigmodes), Fs);%ylim([0 1000])

set(gca,'FontSize',14)

title('(b)')

%%

function [Phi, Lambda, b] = DMD(X,Xprime,r)

[U,Sigma,V] = svd(X,'econ'); % singular value decomposition

Ur = U(:,1:r);

Sigmar = Sigma(1:r,1:r);

Vr = V(:,1:r); % Step 1

Atilde = Ur'*Xprime*Vr/Sigmar;

[W,Lambda] = eig(Atilde); % Step 2

% Step 3

Phi = Xprime*(Vr/Sigmar)*W;

alpha1 = Sigmar*Vr(1,:)';

b = (W*Lambda)\alpha1;

end

More Akah Precious's questions See All
Similar questions and discussions