I have been trying to write the x-axis values (peak only) to txt file using this code (this method is working).
%determine the bpm
%count the dominant peaks in the signal
fid = fopen('y1.txt','a'); %txt naming and append
beat_count = 0;
for k = 2 : length(pbcg)-1
if (pbcg(k) > pbcg(k-1) && pbcg(k) > pbcg(k+1) && pbcg(k) > 1)
beat_count = beat_count + 1;
end
end
fprintf(fid, '%i\n', k); %open writer
fs = 100; %freq 100hz
N = length(pbcg);
duration_in_seconds = N/fs;
duration_in_minutes = duration_in_seconds/60;
BPM_avg = beat_count/duration_in_minutes;
fclose(fid); %close writer
But the problem comes in here when i have modified it to plot the graph segment by segment (i manage to get this done) but the problem is not able to write the x-axis value to the txt file when my code is like this.. anything i done wrong?
%plot segment by segment
data = pbcg;%data value from 1 to 10000
rows = reshape(data, 1000, numel(data)/1000)';%reshape the data into
%matrix by 1000 against total num of element in array and then / 1000)
fid = fopen('y1.txt','a'); %txt naming and append
beat_count = 0;
for e = 1:size(rows,1),
%plot normal & with nodes together
figure,plot(rows(e,:)),hold on,plot(rows(e,:),'ro');
%if statement to find peak
if (pbcg(k) > pbcg(k-1) && pbcg(k) > pbcg(k+1) && pbcg(k)> input('Key in the threshold value: '))
beat_count = beat_count + 1;
peaks(beat_count)=pbcg(k);
end
pause;%pause, on keypress go to next plot
fprintf(fid, 'x_axis%i\n ', peaks); %open writer
end
fclose(fid); %close writer
the result i got was the entire list of peaks even after i enter the threshold value.