01. Digital_Engineering_HW1
01. Digital_Engineering_HW1
[toc]
Digital_Engineering_HW1
문제
1
2
3
4
5
6
7
8
9
10
1. Program in C language to print as follows:
---
Type the values of 5 sampled points: 0 1.2 1.5 2.3 2.5
Digitized signal after quantization and coding is 100 100 101 101 110
---
2. Cosider followings
- The analog input voltage level is from - 5V to 5V
- The quantization level is 8.
- -5V is mapped to Quantization level 0 and 0V is mapped to Quantization level 4.
정답
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define _CRT_SECUR_NO_WARNINGS
#include <stdio.h>
// 양자화 함수
int q_lvls_f(double x) {
int q = (x - (-5.0)) / 1.25;
if (q > 7) {
q = 7;
}
return q;
}
// 양자화 레벨 부여 함수
void d_to_b(int lvl, int count_bit) {
for (int i = count_bit - 1; i >= 0; i--) {
if ((lvl >> i) & 1) { // 비트 연산자
printf("1");
} else {
printf("0");
}
}
printf(" ");
}
int main(){
double s_pnts[5];
int q_lvls[5];
printf("Type the values of 5 sampled points: ");
for (int i = 0; i < 5; i++) {
scanf("%lf", &s_pnts[i]);
q_lvls[i] = q_lvls_f(s_pnts[i]);
}
printf("Digitized signal after quantization and coding is ");
for (int i = 0; i < 5; i++) {
d_to_b(q_lvls[i], 3);
}
printf("\n");
return 0;
}
결과
1
2
Type the values of 5 sampled points: 0 1.2 1.5 2.3 2.5
Digitized signal after quantization and coding is 100 100 101 101 110
End.