Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Feature Extraction for EMG data using PCA

Subject: Feature Extraction for EMG data using PCA

From: anoop

Date: 2 Mar, 2009 16:20:20

Message: 1 of 6

I have a EMG data matrix of size 90(subjects) x 4800(variables). I want to apply PCA to reduce the no. of variables, e.g ( i want matrix of size 90 x 1200 after PCA).
I need a matlab program to do so. suggestions are welcome!!

Subject: Feature Extraction for EMG data using PCA

From: russell.fung@gmail.com

Date: 3 Mar, 2009 14:35:06

Message: 2 of 6

On Mar 2, 10:20=A0am, "anoop " <nomail...@rediffmail.com> wrote:
> I have a EMG data matrix of size 90(subjects) x 4800(variables). I want t=
o apply PCA to reduce the no. of variables, e.g ( i want matrix of size 90 =
x 1200 after PCA).
> I need a matlab program to do so. suggestions are welcome!!

You can write a program to do PCA using subroutines included in basic
Matlab without any extra toolboxes.

You need to find the eigenvectors and eigenvalues of the covariance
matrix of your data, from which you find the most significant
principal components, then you expand your data along the principal
directions.

Subject: Feature Extraction for EMG data using PCA

From: anoop

Date: 4 Mar, 2009 10:53:01

Message: 3 of 6

"russell.fung@gmail.com" <russell.fung@gmail.com> wrote in message <6a1f9244-51d8-4e3b-9fb8-2aefcab53109@y33g2000prg.googlegroups.com>...
> On Mar 2, 10:20=A0am, "anoop " <nomail...@rediffmail.com> wrote:
> > I have a EMG data matrix of size 90(subjects) x 4800(variables). I want t=
> o apply PCA to reduce the no. of variables, e.g ( i want matrix of size 90 =
> x 1200 after PCA).
> > I need a matlab program to do so. suggestions are welcome!!
>
> You can write a program to do PCA using subroutines included in basic
> Matlab without any extra toolboxes.
>
> You need to find the eigenvectors and eigenvalues of the covariance
> matrix of your data, from which you find the most significant
> principal components, then you expand your data along the principal
> directions.

well i wrote the program as given below:
max_PCs=1200;
covariance_matrix=cov(data);
[eigvect,eigval]=eig(covariance_matrix);
eigval=diag(eigval);
[junk,rindices]=sort(-1*eigval);
eigen_values=eigval(rindices);
arranged_eigen_vectors=eigvect(:,rindices);
eigen_values_extacted=eigen_values(1:max_PCs);
principle_components=arranged_eigen_vectors(:,1:max_PCs);
projected_data=xpca*principle_components;

but it takes very long time to execute. could you please give me faster matlab code?? what should i use for training the neural network (projected data or principal components) ??

Subject: Feature Extraction for EMG data using PCA

From: russell.fung@gmail.com

Date: 4 Mar, 2009 14:46:10

Message: 4 of 6

On Mar 4, 4:53=A0am, "anoop " <nomail...@rediffmail.com> wrote:
> "russell.f...@gmail.com" <russell.f...@gmail.com> wrote in message <6a1f9=
244-51d8-4e3b-9fb8-2aefcab53...@y33g2000prg.googlegroups.com>...
> > On Mar 2, 10:20=3DA0am, "anoop " <nomail...@rediffmail.com> wrote:
> > > I have a EMG data matrix of size 90(subjects) x 4800(variables). I wa=
nt t=3D
> > o apply PCA to reduce the no. of variables, e.g ( i want matrix of size=
 90 =3D
> > x 1200 after PCA).
> > > I need a matlab program to do so. suggestions are welcome!!
>
> > You can write a program to do PCA using subroutines included in basic
> > Matlab without any extra toolboxes.
>
> > You need to find the eigenvectors and eigenvalues of the covariance
> > matrix of your data, from which you find the most significant
> > principal components, then you expand your data along the principal
> > directions.
>
> well i wrote the program as given below:
> max_PCs=3D1200;
> covariance_matrix=3Dcov(data);
> [eigvect,eigval]=3Deig(covariance_matrix);
> eigval=3Ddiag(eigval);
> [junk,rindices]=3Dsort(-1*eigval);
> eigen_values=3Deigval(rindices);
> arranged_eigen_vectors=3Deigvect(:,rindices);
> eigen_values_extacted=3Deigen_values(1:max_PCs);
> principle_components=3Darranged_eigen_vectors(:,1:max_PCs);
> projected_data=3Dxpca*principle_components;
>
> but it takes very long time to execute. could you please give me faster m=
atlab code?? what should i use for training the neural network (projected d=
ata or principal components) ??

The PCA function in MATLAB's statistical toolbox may be faster,
although I have never tried it.

You can also ask yourself if you really need an exact PCA solution? If
an approximate solution is good enough, take a look at
http://www.cse.msu.edu/~weng/research/ccipca.m

Russell

Subject: Feature Extraction for EMG data using PCA

From: Greg Heath

Date: 10 Mar, 2009 16:29:00

Message: 5 of 6

On Mar 4, 6:53 am, "anoop " <nomail...@rediffmail.com> wrote:
> "russell.f...@gmail.com" <russell.f...@gmail.com> wrote in message <6a1f9244-51d8-4e3b-9fb8-2aefcab53...@y33g2000prg.googlegroups.com>...
> > On Mar 2, 10:20=A0am, "anoop " <nomail...@rediffmail.com> wrote:
> > > I have a EMG data matrix of size 90(subjects) x 4800(variables). I want t=
> > o apply PCA to reduce the no. of variables, e.g ( i want matrix of size 90 =
> > x 1200 after PCA).
> > > I need a matlab program to do so. suggestions are welcome!!
>
> > You can write a program to do PCA using subroutines included in basic
> > Matlab without any extra toolboxes.
>
> > You need to find the eigenvectors and eigenvalues of the covariance
> > matrix of your data, from which you find the most significant
> > principal components, then you expand your data along the principal
> > directions.

I agree. I do not recommend picking a number like 1200 out
of mid air when you can use the diagonal eigenvalue matrix
to estimate a more practical value. Typical rules of thumb are

1. Exclude eigenvectors associated with eigenvalues that
are less than x% (e.g., 1%) of the maximum eigenvalue.
2. Keep the minimum number of eigenvectors that will
preserve x% of the trace of the covariance matrix.

Recall that

trace(cov(A)) = sum(diag(cov(A)))= sum(eig(A))

> well i wrote the program as given below:
> max_PCs=1200;
> covariance_matrix=cov(data);
> [eigvect,eigval]=eig(covariance_matrix);

Wasted effort calculating 3600 useless eigenvectors

> eigval=diag(eigval);
> [junk,rindices]=sort(-1*eigval);

help fliplr
help flipud

> eigen_values=eigval(rindices);

= junk?

> arranged_eigen_vectors=eigvect(:,rindices);
> eigen_values_extacted=eigen_values(1:max_PCs);
> principle_components=arranged_eigen_vectors(:,1:max_PCs);
> projected_data=xpca*principle_components;
>
> but it takes very long time to execute. could you please give me faster matlab code?? what should i use for training theneuralnetwork (projected data or principal components) ??

C = cov(data); L0 = eig(C); % No eigenvectors
L = diag(L0); cumsumL = cumsum(L);

% Find r to preserve 95% (or your choice) of trace(C), i.e.,
% cumsumL(r-1) < 0.95*cumsumL(end) <= cumsumL(r-1)
% Then use EIGS (NOT EIG) to caclculate exactly r
% eigenvectors

Hope this helps.

Greg

Subject: Feature Extraction for EMG data using PCA

From: Greg Heath

Date: 10 Mar, 2009 16:36:57

Message: 6 of 6

On Mar 4, 6:53=A0am, "anoop " <nomail...@rediffmail.com> wrote:
> "russell.f...@gmail.com" <russell.f...@gmail.com> wrote in message <6a1f9=
244-51d8-4e3b-9fb8-2aefcab53...@y33g2000prg.googlegroups.com>...
> > On Mar 2, 10:20=3DA0am, "anoop " <nomail...@rediffmail.com> wrote:
> > > I have a EMG data matrix of size 90(subjects) x 4800(variables). I wa=
nt t=3D
> > o apply PCA to reduce the no. of variables, e.g ( i want matrix of size=
 90 =3D
> > x 1200 after PCA).
> > > I need a matlab program to do so. suggestions are welcome!!
>
> > You can write a program to do PCA using subroutines included in basic
> > Matlab without any extra toolboxes.
>
> > You need to find the eigenvectors and eigenvalues of the covariance
> > matrix of your data, from which you find the most significant
> > principal components, then you expand your data along the principal
> > directions.
>
> well i wrote the program as given below:
> max_PCs=3D1200;
> covariance_matrix=3Dcov(data);
> [eigvect,eigval]=3Deig(covariance_matrix);
> eigval=3Ddiag(eigval);
> [junk,rindices]=3Dsort(-1*eigval);
> eigen_values=3Deigval(rindices);
> arranged_eigen_vectors=3Deigvect(:,rindices);
> eigen_values_extacted=3Deigen_values(1:max_PCs);
> principle_components=3Darranged_eigen_vectors(:,1:max_PCs);
> projected_data=3Dxpca*principle_components;
>
> but it takes very long time to execute. could you please give me faster m=
atlab code?? what should i use for training theneuralnetwork (projected dat=
a or principal components) ??

If you use principal components, what would you use for targets?

If you are designing a classifier use PLS,
not PCA.

Hope this helps.

Greg

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us