Closed yazhengwei closed 1 year ago
Here is an example I wrote: void main() { int ms = LIQUID_MODEM_QPSK; //Modulation signal source msourcecf gen = msourcecf_create_default(); msourcecf_add_modem(gen, 0.00f/frequency/, 0.30f/0.25f//bandwidth/, -30/gain/, ms, 7, 0.20f); const unsigned int buf_len = 800; liquid_float_complex buf[buf_len] = {0.0f}; //spectrum const unsigned int nfft = 2400; spgramcf periodogram = spgramcf_create_default(nfft); //sampling const unsigned int num_samples = 200000; // number of samples unsigned int total_samples = 0; int ftype = LIQUID_FIRFILT_ARKAISER; const unsigned int k = 2/2/; // samples per symbol unsigned int m = 7; // filter delay (symbols) float beta = 0.20f; // filter excess bandwidth factor float bandwidth = /0.10f/0.1f; // loop filter bandwidth symtrack_cccf symtrack = symtrack_cccf_create(ftype, k, m, beta, ms); symtrack_cccf_set_bandwidth(symtrack, bandwidth); symtrack_cccf_print(symtrack); liquid_float_complex syms[buf_len] = { 0.0f }; // recovered symbols unsigned int num_symbols_sync = 0; //Cache windowcf sym_buf = windowcf_create(buf_len);
while (total_samples < num_samples) {
//Signal source generation
msourcecf_write_samples(gen,buf, buf_len /*decim_buf, decim_len*/);
//Spectrum estimation
spgramcf_write(periodogram, buf, buf_len /*decim_buf, decim_len*/);
//Carrier synchronization, symbol recovery
num_symbols_sync = 0;
symtrack_cccf_execute_block(symtrack, buf, buf_len, syms, &num_symbols_sync);
windowcf_write(sym_buf, syms, num_symbols_sync);
total_samples += buf_len;
}
//Input to file
FILE * fid = fopen(OUTPUT_FILENAME, "w");
fprintf(fid, "%% %s : auto-generated file\n", OUTPUT_FILENAME);
fprintf(fid, "clear all;\n");
fprintf(fid, "close all;\n\n");
fprintf(fid, "num_samples=%u;\n", buf_len);
fprintf(fid, "t=0:(num_samples-1);\n");
fprintf(fid, "x=zeros(1,num_samples);\n");
//Time domain data
for (int i = 0; i<buf_len; i++)
fprintf(fid, "x(%4u) = %12.4e + j*%12.4e;\n", i + 1, real(buf[i]), imag(buf[i]));
//Draw a time domain diagram
fprintf(fid, "figure;\n");
fprintf(fid, "subplot(4,1,1);\n");
fprintf(fid, " plot(t,real(x),'r-');\n");
fprintf(fid, " xlabel('time');\n");
fprintf(fid, " ylabel('I Data');\n");
fprintf(fid, " legend('Idata');\n");
fprintf(fid, " axis([0 num_samples -2.0e-2 2.0e-2]);\n");
fprintf(fid, " grid on;\n");
fprintf(fid, "subplot(4,1,2);\n");
fprintf(fid, " plot(t,imag(x),'g-');\n");
fprintf(fid, " xlabel('time');\n");
fprintf(fid, " ylabel('Q Data');\n");
fprintf(fid, " legend('Qdata');\n");
fprintf(fid, " axis([0 num_samples -2.0e-2 2.0e-2]);\n");
fprintf(fid, " grid on;\n");
//Draw a spectrum diagram
float psd0[nfft] = {0.0f};
spgramcf_get_psd(periodogram, psd0);
fprintf(fid, "nfft = %u;\n", nfft);
fprintf(fid, "f = [0:(nfft-1)]/nfft - 0.5;\n");
fprintf(fid, "psd0 = zeros(1,nfft);\n");
for (int i = 0; i<nfft; i++)
fprintf(fid, "psd0(%6u) = %12.4e;\n", i + 1, psd0[i]);
fprintf(fid, "subplot(4,1,3);\n");
fprintf(fid, " plot(f, psd0, '-', 'LineWidth',1.5,'Color',[0 0.5 0.2]);\n");
fprintf(fid, "xlabel('Normalized Frequency [f/F_s]');\n");
fprintf(fid, "ylabel('Power Spectral Density [dB]');\n");
fprintf(fid, "legend('Before mixing','After mixing');\n");
fprintf(fid, "axis([-0.5 0.5 -150 -10]);\n");
fprintf(fid, " grid on;\n");
//Draw a constellation diagram
fprintf(fid, "syms = zeros(1,%u);\n", num_symbols_sync);
//liquid_float_complex * rc = nullptr;
//windowcf_read(sym_buf, &rc);
for (int i = 0; i<num_symbols_sync; i++)
fprintf(fid, "syms(%3u) = %12.8f + j*%12.8f;\n", i + 1, real(syms[i]), imag(syms[i]) == 0.0f ? 1.0e-6f : imag(syms[i]));
fprintf(fid, "subplot(4,1,4);\n");
fprintf(fid, "plot(real(syms),imag(syms),'x','MarkerSize',4);\n");
fprintf(fid, " xlabel('In-phase');\n");
fprintf(fid, " ylabel('Quadrature');\n");
fprintf(fid, " title('Last %u symbols');\n", buf_len);
fprintf(fid, " axis([-1 1 -1 1]*1.6);\n");
fprintf(fid, " axis square;\n");
fprintf(fid, " grid on;\n");
//Release resources
fclose(fid);
msourcecf_destroy(gen);
//firdecim_crcf_destroy(decim);
spgramcf_destroy(periodogram);
symtrack_cccf_destroy(symtrack);
windowcf_destroy(sym_buf);
return 0;
}
I encountered some problems when using it. I used the function "msourcecf_add_modem" to generate a QPSK signal with a frequency of 0 and a bandwidth of 0.3, and then fed it into "symtrack_cccf_executeblock" for symbol recovery and demodulation, but its output constellation was not locked. Can you spare some time from your busy schedule to help me take a look? I would be very grateful!
I encountered some problems when using it. I used the function "msourcecf_add_modem" to generate a QPSK signal with a frequency of 0 and a bandwidth of 0.3, and then fed it into "symtrack_cccf_executeblock" for symbol recovery and demodulation, but its output constellation was not locked. Can you spare some time from your busy schedule to help me take a look? I would be very grateful!