From: Cesare on
Hi!
I'm playing with matlab princomp for performing PCA. I'm breaking a random signal into its component and then I'm trying to reconstruct it using all the components. I'd expect an almost perfect reconstruction, however I notice big difference between the original and reconstructed signal. Below is the code, am I doing something wrong or is it a numerical problem?
Thanks a lot in advance,
Cesare

CODE ============================================


clear
clc

% Number of points:
Npt = 100;
% Number of trials:
Ntr = 20;
dat = rand(Npt, Ntr);
[COEFF,SCORE,latent] = princomp(dat.');

%% Reconstructing
tr = 10; % trial that we are trying to reconstruct
reconstructed_sig = zeros(Npt,1);
for comp=1:Npt
reconstructed_sig(:) = reconstructed_sig(:) + SCORE(tr,comp) * COEFF(:,comp);
end

%% Plotting
figure
hold all
plot(dat(:,tr) - mean(dat(:,tr)));
plot(reconstructed_sig)
From: Cesare on
"Cesare " <cmfornewsgroup(a)gmail.com> wrote in message <heebg8$f26$1(a)fred.mathworks.com>...
> Hi!
> I'm playing with matlab princomp for performing PCA. I'm breaking a random signal into its component and then I'm trying to reconstruct it using all the components. I'd expect an almost perfect reconstruction, however I notice big difference between the original and reconstructed signal. Below is the code, am I doing something wrong or is it a numerical problem?
> Thanks a lot in advance,
> Cesare
>
> CODE ============================================
>
>
> clear
> clc
>
> % Number of points:
> Npt = 100;
> % Number of trials:
> Ntr = 20;
> dat = rand(Npt, Ntr);
> [COEFF,SCORE,latent] = princomp(dat.');
>
> %% Reconstructing
> tr = 10; % trial that we are trying to reconstruct
> reconstructed_sig = zeros(Npt,1);
> for comp=1:Npt
> reconstructed_sig(:) = reconstructed_sig(:) + SCORE(tr,comp) * COEFF(:,comp);
> end
>
> %% Plotting
> figure
> hold all
> plot(dat(:,tr) - mean(dat(:,tr)));
> plot(reconstructed_sig)


Ok, to better restate the question:
suppose I record 30 repetition of the same stochastic time-signal of length 100. In this case I have 100 random variables and 30 trials. Then the input to princomp is a matrix of size 40-by-100? So that each column of coeff represents one of the extracted components in my time signal?
Thanks,
Cesare
From: Peter Perkins on
Cesare wrote:

> I'm playing with matlab princomp for performing PCA. I'm breaking a random signal into its component and then I'm trying to reconstruct it using all the components. I'd expect an almost perfect reconstruction, however I notice big difference between the original and reconstructed signal. Below is the code, am I doing something wrong or is it a numerical problem?

Cesare, take a look at the code in the PCARES function to see how to do this. Or just use PCARES.

Hope this helps.
 | 
Pages: 1
Prev: taking datas from access database
Next: spfun