我有以下代码用于通过检测QRS峰值来计算ECG信号的心率:
public class Heart_Rate {
public static void main(String[] args) throws IOException{
// Read Text file
Path filePath = Paths.get("heartrate.txt");
Scanner scanner = new Scanner(filePath);
List<Double> rawData = new ArrayList<Double>();
while (scanner.hasNext()) {
if (scanner.hasNextDouble()) {
rawData.add(scanner.nextDouble());
} else {
scanner.next();
}
}
System.out.println(rawData);
//Find Max value for Threshold Level
Double maximum = Collections.max(rawData);
Double threshold = 0.7*maximum;
System.out.println("Maximum = " + maximum);
System.out.println("Threshold = " + threshold);
//Calculate Heart Rate from list "Raw Data"
int upflag = 0;
int last = 1;
int p = 0;
int t = 0;
int count = 0;
//List<Double> heartRate = new ArrayList<Double>();
int heartRate2[] = new int[50];
for (int i = 0; i < rawData.size(); i++) {
if (rawData.get(i)> threshold){
if (upflag == 0){
if (last > 0){
t = i - last;
p = 100*60/t;
//100 is the sampling rate
heartRate2[count] = p;
count = count + 1;
//heartRate.add(p);
}
last = i;
}
upflag = 50;
}
else {
if (upflag > 0){
upflag = upflag -1;
}
}
}
System.out.println("Count = " + count);
System.out.println("Heart Rate = " + heartRate2);
System.out.println("Heart Rate = " + heartRate2);
}
}
当我将计算出的心率值(p)添加到我的ArrayList(称为HeartRate)时,我收到了一个正确的值数组。 但是,我试图将我的所有值更改为int并将我的值保存在整数数组(称为heartRate2)中我得到以下结果: 心率= [I @ dd1e765 我需要我的值是整数,因为心率是以每分钟的节拍计算的。我也尝试将double值转换为int,但最终得到的结果与上面类似。
答案 0 :(得分:0)
使用Arrays.toString(arr)
为某个数组String
获取有意义的arr
表示。