Filter löschen
Filter löschen

am getting the following error, can someone elaborate the error please.. there is no missing and 0 in my data.. all matix is 15000 by 26 dimensions.

1 Ansicht (letzte 30 Tage)
Error using findpeaks
Expected Y to be real.

Antworten (1)

Rik
Rik am 19 Nov. 2017
Bearbeitet: Rik am 19 Nov. 2017
Apparently there are complex numbers in your matrix. This can happen as a side-effect of the rounding that sometimes happens because Matlab is a computer program.
You can check that the size of your imaginary part is about the size of your machine precision by using
if ~any(abs(imag(Y))<eps)
%don't use ~any(imag(Y)<eps) (example: Y=1-j*0.5*eps)
%Thanks for the correction Walter
Y=real(Y);
end
The dimensions of your matrix are generally not relevant, your actual code is. It tells us nothing that your code begins with if true. Next time, copy at least all the text in red and try to condense your code to the smallest sample that results in the error, so we can reproduce it.
  10 Kommentare
Mirbahar Naadiya
Mirbahar Naadiya am 24 Nov. 2017
Bearbeitet: Walter Roberson am 24 Nov. 2017
I am trying this way, can you tell how to multiply the windows size in seconds by with sampling frequency with. in my case its 100 hz
data = load ('user_1703.txt');
accX = data(:,3)/9.8;%3rd column of the CSV file is the values of Accelerometer X
accY = data(:,4)/9.8;%4th column of the CSV file is the values of Accelerometer Y
accZ = data(:,5)/9.8;%5th column of the CSV file is the values of Accelerometer Z
%**********************************************************************[m,n]=size(accX);
acc = ones(1,m);
%%************Initialization of the statistical values of the windows******%
avgX=zeros(1,500);
avgY=zeros(1,500);
avgZ=zeros(1,500);
avgACC=zeros(1,500);
maxACC=-3*ones(1,500); %these -3 and 100 values are random values which makes the inital values look a lot different than the actual values
minACC=-3*ones(1,500);
maxX=100*ones(1,500);
maxY=100*ones(1,500);
maxZ=100*ones(1,500);
minX=-100*ones(1,500);
minY=-100*ones(1,500);
minZ=-100*ones(1,500);
stdX=zeros(1,500);
stdY=zeros(1,500);
stdZ=zeros(1,500);
stdACC=zeros(1,500);
XYcorr=zeros(1,500);
XZcorr=zeros(1,500);
YZcorr=zeros(1,500);
energy=zeros(1,500);
%**************************************************************************
%**************************************************************************
for i=1:m
acc(i)=sqrt((accX(i)^2+accY(i)^2+accZ(i)^2));
end
i=1;
j=1;
windowsize=50;
%*******In each iteration, statistical values of a window are calculated
%and raw data(accX,accY,accZ) index is inceremented by windowsize/2 to
%provide %50 overlapping*************************************************%
while(i<=m-52)
corrmatrix=corrcoef([accX(i:i+windowsize-1),accY(i:i+windowsize-1),accZ(i:i+windowsize-1)]);
XYcorr(j)=corrmatrix(1,2);
XZcorr(j)=corrmatrix(1,3);
YZcorr(j)=corrmatrix(2,3);
avgX(j)=mean(accX(i:i+windowsize-1));
stdX(j)=std(accX(i:i+windowsize-1))
maxX(j)=max(accX(i:i+windowsize-1));
minX(j)=min(accX(i:i+windowsize-1));
avgY(j)=mean(accY(i:i+windowsize-1));
stdY(j)=std(accY(i:i+windowsize-1));
maxY(j)=max(accY(i:i+windowsize-1));
minY(j)=min(accY(i:i+windowsize-1));
avgZ(j)=mean(accZ(i:i+windowsize-1));
stdZ(j)=std(accZ(i:i+windowsize-1));
maxZ(j)=max(accZ(i:i+windowsize-1));
minZ(j)=min(accZ(i:i+windowsize-1));
avgACC(j)=mean(acc(i:i+windowsize-1));
stdACC(j)=std(acc(i:i+windowsize-1));
maxACC(j)=max(acc(i:i+windowsize-1));
minACC(j)=min(acc(i:i+windowsize-1));
energy(j)=sum(abs(fft(acc(i:i+windowsize-1))))/26; %
%Energy is defined as the normalized summation of absolute values of
%Discrete Fourier Transform of a windowed signal sequence
i=i+windowsize/2-1;
j=j+1;
end
%************************************************************************** %This cell represents a matrix consisting of each row representing a
%window and each column representing the statistical attribute
%calculated above%
cell=[maxX.',minX.',avgX.',stdX.',maxY.',minY.',avgY.',stdY.',maxZ.',minZ.',avgZ.',stdZ.',maxACC.',minACC.',avgACC.',stdACC.',XYcorr.',XZcorr.',YZcorr.',energy.'];
%MATLAB has a built-in function to write the matrix given as input into a file of the format of CSV.
%csvwrite('features.csv',cell);
Walter Roberson
Walter Roberson am 24 Nov. 2017
If your sample frequency is 100 Hz then 2.56 seconds is 256 samples, and that would be the window size you would use.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!