#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 1000
// 电量表滞回算法
void hysteresis(int *input, int *output, int n, int threshold) {
int i, sign = 0;
for (i = 0; i < n; i++) {
if (abs(input[i]) >= threshold) {
sign = input[i] > 0 ? 1 : -1;
}
output[i] = sign;
}
}
int main() {
int input[N] = {0};
int output[N] = {0};
int n, threshold, i;
//死循环 状态机
printf("请输入信号长度n:");
scanf("%d", &n);
printf("请输入阈值threshold:");
scanf("%d", &threshold);
printf("请输入信号:");
for (i = 0; i < n; i++) {
scanf("%d", &input[i]);
}
hysteresis(input, output, n, threshold);
printf("输出结果:");
for (i = 0; i < n; i++) {
printf("%d ", output[i]);
}
return 0;
}
8位机电量表滞回接口
最新推荐文章于 2024-07-17 16:32:20 发布