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.

Answers (1)

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 Comments

thank u ... i will take care of mentioning proper error from next time to
Error using findpeaks>parse_inputs (line 191)
Expected Y to be real.
Error in findpeaks (line 134)
= parse_inputs(Yin,varargin{:});
Error in featuresFromBuffer>spectralPeaksFeatures (line 85)
[pks,locs] = findpeaks(p,'npeaks',20,'minpeakdistance',minpkdist);
Error in featuresFromBuffer (line 39)
feat(28:39) = spectralPeaksFeatures(aby, fs);
newf = zeros(size(x,1),66); %#ok<*NODEF>
tstart = tic;
% Use of parfor instead of simple for will use all available workers in
% the local parallel pool (requires Parallel Computing Toolbox)
parfor n = 1:size(x,1)
% Extract features for current data buffers
newf(n,:) = featuresFromBuffer(x(n,:), y(n,:), z(n,:), fs);
fprintf('Buffer #%g\n',n)
end
still has same error there is no imaginary number in data..
We are probably going to need some data to test with.
thank u walter .. i think i haven't prepared data well. can you tell how can i apply sliding window 2.56 with 50% window overlapping on accelrometer x,y,z, axis. please . thats what am trying, i want to know is it the rite way of windowing ???
i=1
j=1
windowsize=2.56
avgX= zeros(1,200)
avgY=zeros(1,200)
avgZ=zeros(1,200)
[m n]=size(accX)
while (i<=m-52)
avgX(j)=mean(accX(i:i+windowsize-1)
avgY(j)=mean(accY(i:i+windowsize-1)
avgZ(j)=mean(accZ(i:i+windowsize-1)
i=i+windowsize/2-1
j=j+1
end
I do not know what it means to have a window size that has a fraction. Is it possible that your window size is to be 256 instead of 2.56 ?
Thank you sir for your response
Actually I am trying to replicate the signal pre processing done on this Data Set: http://archive.ics.uci.edu/ml/datasets/Human+Activity+Recognition+Using+Smartphones# "The sensor signals (accelerometer and gyroscope) were pre-processed by applying noise filters and then sampled in fixed-width sliding windows of 2.56 sec and 50% overlap (128 readings/window)"
You need to multiply the windows size in seconds by your sampling frequency in order to get the window size in terms of number of samples.
Note: I suggest that you use the Communications System Toolbox function buffer() to arrange the data into overlapping segments.
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);
If your sample frequency is 100 Hz then 2.56 seconds is 256 samples, and that would be the window size you would use.

Sign in to comment.

Tags

Asked:

on 19 Nov 2017

Commented:

on 24 Nov 2017

Community Treasure Hunt

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

Start Hunting!