function [bpm] = test()
close('all');
instrreset
TIMEOUT = 5;    %time to wait for data before aborting
XPOINTS = 50;   %number of points along x axis

%create serial object to represent connection to mymbed
mymbed = serial('COM5','BaudRate', 9600, 'DataBits', 8);   %change depending on mymbed configuration

set(mymbed,'Timeout',TIMEOUT);        %adjust timeout to ensure fast response when mymbed disconnected

fopen(mymbed);        %open serial connection
fprintf(mymbed,1,'async');
x=0;
vec = [];
while (x <= 1000)
    values = fscanf(mymbed, '%f');  
    disp(values);
    vec = [vec values];
    x = x+1;
end
fclose(mymbed);

pause(2);
%Plot data
t = 1:length(vec);
figure(1);
plot((t/200),(5*vec));
title('Regular Signal')
xlabel('Time (s)');
ylabel('Voltage (V)');

[tempPks,tempLocs,w,p]= findpeaks(vec,'MinPeakProminence',.1);
avg = mean(tempPks);
Apks = tempPks(tempPks>avg);
tApks = tempLocs(tempPks>avg);

timeElapsed = length(vec)/200;
bpm = (length(Apks)/timeElapsed)*(.45*60)

delete(instrfind({'Port'},{'COM5'}))
instrreset
device = serial('COM5','BaudRate', 9600, 'DataBits', 8);   %change depending on mymbed configuration

set(device,'Timeout',TIMEOUT);        %adjust timeout to ensure fast response when mymbed disconnected

fopen(device);        %open serial connection
fprintf(device,1,'async');
%to read and write to a serial port
tempStr = [' ' num2str(bpm)];
fprintf(device,'%c',strcat('BPM :',tempStr));
fclose(device);
end