1D constellation + precalculated sqrt(M)
This commit is contained in:
48
QAM/qam.c
48
QAM/qam.c
@ -208,6 +208,32 @@ void free_constellation(qam_system* qam) {
|
||||
free(qam->constellation);
|
||||
}
|
||||
|
||||
// Préambule QAM
|
||||
void generate_preamble(qam_system* qam, double complex* preamble, int L) {
|
||||
// L 1er symboles de la constellation
|
||||
for (int i = 0; i < L; i++) {
|
||||
preamble[i] = qam->constellation[i % qam->M];
|
||||
}
|
||||
}
|
||||
|
||||
// Concatène le préambule avec le signal modulé
|
||||
double complex* concat_preamble_signal(double complex* preamble_mod, int preamble_len, double complex* s_mod, int nb_symbols, int N) {
|
||||
int total_samples = (preamble_len + nb_symbols) * N;
|
||||
double complex* s_concat = malloc(sizeof(double complex) * total_samples);
|
||||
|
||||
// Copier le préambule modulé
|
||||
for (int i = 0; i < preamble_len * N; i++) {
|
||||
s_concat[i] = preamble_mod[i];
|
||||
}
|
||||
|
||||
// Copier le signal modulé après le préambule
|
||||
for (int i = 0; i < nb_symbols * N; i++) {
|
||||
s_concat[preamble_len * N + i] = s_mod[i];
|
||||
}
|
||||
|
||||
return s_concat;
|
||||
}
|
||||
|
||||
int main () {
|
||||
// Initialisation du system qam
|
||||
qam_system qam;
|
||||
@ -232,13 +258,23 @@ int main () {
|
||||
double complex* symbols = malloc(sizeof(double complex) * nb_symbols);
|
||||
bits_to_symbols(&qam, input_bits, nb_bits, symbols);
|
||||
|
||||
// Modulation
|
||||
int total_samples = qam.N * nb_symbols;
|
||||
// Initialisation du préambule
|
||||
int L = 16;
|
||||
int total_samples = qam.N * (nb_symbols + L);
|
||||
|
||||
double complex* preamble = malloc(sizeof(double complex) * L);
|
||||
generate_preamble(&qam, preamble, L);
|
||||
double complex* preamble_mod = malloc(sizeof(double complex) * L * qam.N);
|
||||
modulate(&qam, preamble, L, preamble_mod);
|
||||
|
||||
double complex* s_mod = malloc(sizeof(double complex) * nb_symbols * qam.N);
|
||||
modulate(&qam, symbols, nb_symbols, s_mod);
|
||||
|
||||
double complex* s = malloc(sizeof(double complex) * total_samples);
|
||||
modulate(&qam, symbols, nb_symbols, s);
|
||||
double complex* s_with_preamble = concat_preamble_signal(preamble_mod, L, s_mod, nb_symbols, qam.N);
|
||||
|
||||
// Ajout du bruit
|
||||
add_noise(s, total_samples, 0);
|
||||
add_noise(s_with_preamble, total_samples, 0);
|
||||
|
||||
FILE *fp_ref = fopen("constellation_ref.dat", "w");
|
||||
fill_constellation_data(&qam, fp_ref);
|
||||
@ -248,12 +284,12 @@ int main () {
|
||||
//add_dephasage(s, M_PI / 6.0, total_samples);
|
||||
|
||||
// AJout de decalage de fréquence
|
||||
//add_freq(&qam, s, 1, total_samples);
|
||||
add_freq(&qam, s_with_preamble, 0, total_samples);
|
||||
|
||||
// Démodulation
|
||||
FILE *fp_constel = fopen("constellation.dat", "w");
|
||||
uint8_t* output_bits = (uint8_t*)malloc(nb_bits * sizeof(uint8_t));
|
||||
demodulate(&qam, s, nb_symbols, output_bits, fp_constel);
|
||||
demodulate(&qam, s_mod, nb_symbols, output_bits, fp_constel);
|
||||
fclose(fp_constel);
|
||||
|
||||
// Reconstruction du texte
|
||||
|
||||
Reference in New Issue
Block a user