QAM modifications

This commit is contained in:
2025-09-29 15:51:08 +02:00
parent f614b794aa
commit 4f3f3ea620

View File

@ -15,23 +15,31 @@ struct qam_system_s {
typedef struct qam_system_s qam_system;
void init_constellation (qam_system *qam) {
int sm = sqrt(qam->M);
int sm = (int)sqrt(qam->M);
qam->constellation = (double complex**)malloc(sizeof(double complex*) * sm);
for (int i = 0; i < sm; i++) {
qam->constellation[i] = (double complex*)malloc(sizeof(double complex) * sm);
}
double norm_factor = sqrt((double)(qam->M - 1) / 3.0); // Pour puissance unitaire
for (int i = 0; i < sm; i++) {
double complex ip = -(sm - 1) + 2 * i;
for (int j = 0; j < sm; j++) {
double complex qp = -(sm - 1) + 2 * j;
qam->constellation[i][j] = ip + I * qp;
qam->constellation[i][j] /= sqrt((qam->M-1)/3.0); // Pour puissance unitaire
qam->constellation[i][j] = (ip + I * qp) / norm_factor;
}
}
}
void free_constellation(qam_system *qam) {
int sm = (int)sqrt(qam->M);
for (int i = 0; i < sm; i++)
free(qam->constellation[i]);
free(qam->constellation);
}
void bits_to_symbols (qam_system *qam, int *bits, int nb_bits, double complex *symbols) {
int nb_symbols = nb_bits / qam->k;
int sm = sqrt(qam->M);
@ -76,9 +84,7 @@ int main () {
double complex* s = (double complex*)malloc(sizeof(double complex) * total_samples);
modulate(&qam, symbols, nb_symbols, s);
for(int i=0; i<sqrt(qam.M); i++)
free(qam.constellation[i]);
free(qam.constellation);
free_constellation(&qam);
free(s);
return 0;