-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsignal.c
89 lines (80 loc) · 1.98 KB
/
signal.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* signal.c
*
* Copyright (c) 1999 Pekka Riikonen, priikone@poseidon.pspt.fi.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* 1999-08-21: By Pekka Riikonen <priikone@poseidon.pspt.fi>
* - much improved AM signal calculation
*
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include "signal.h"
/*
* Generates the AM signal.
*/
double *generate_am_signal(Signal *ps)
{
unsigned int x, y, i;
double fc, ft, fp, A;
double pi2, m, t, tmp1, tmp2;
double *signal;
/*
* Monitor frequency's.
*
* Example line from XF86Config:
*
* Modeline "1152x864" 135
* 1152 1464 1592 1776
* 864 864 876 908
* fp = 135
* ft = tone frequency to be broadcasted
* fc = carrier frequency
*/
fp = ps->o_fp * 1e6; /* Mhz */
ft = ps->o_tone; /* Tone (Hz) */
fc = ps->o_carr; /* Carrier (Hz) */
/* Settings and pre-calculations */
A = 255 / 4.0; /* amplitude */
m = 1.0; /* amplitude */
pi2 = (2 * M_PI); /* 2 * pi */
/*
* Pre-calculate the AM signal.
*/
signal = (double *)malloc(sizeof(double) *
(ps->o_res_x * ps->o_res_y));
i = 0;
t = 0;
for (y = 0; y < ps->o_res_y; y++) {
tmp1 = cos(pi2 * t * ft / fp + M_PI);
if (ps->o_square)
tmp1 = (tmp1 < 0) ? -1 : 1;
for (x = 0; x < ps->o_res_x; x++) {
tmp2 = cos(pi2 * t * fc / fp);
signal[i++] = A * tmp2 * (m + tmp1);
t++;
}
t += ps->o_fh - ps->o_res_x;
}
return signal;
}
/*
* Generates the FM signal.
*/
double *generate_fm_signal(Signal *ps)
{
return 0;
}