Example #1
0
void dft_run(dft_plan_t *plan, void *in, void *out) {
	switch(plan->mode) {
	case COMPLEX_2_COMPLEX:
		dft_run_c2c(plan,in,out);
		break;
	case REAL_2_REAL:
		dft_run_r2r(plan,in,out);
		break;
	case COMPLEX_2_REAL:
		dft_run_c2r(plan,in,out);
		break;
	}
}
Example #2
0
/**@ingroup plp_sink
 * Prints or displays the signal according to the selected mode.
 */
int work(void **inp, void **out) {
	int n,i,j;
	int mode;
	float *r_input;
	_Complex float *c_input;
	dft_plan_t *plan;

	strdef(xlabel);

	if (mode_id != NULL) {
		if (param_get_int(mode_id,&mode) != 1) {
			mode = 0;
		}
	} else {
		mode = 0;
	}
	memset(signal_lengths,0,sizeof(int)*2*NOF_INPUT_ITF);
	for (n=0;n<NOF_INPUT_ITF;n++) {
		if (is_complex && mode != MODE_PSD) {
			signal_lengths[2*n] = get_input_samples(n)/2;
			signal_lengths[2*n+1] = signal_lengths[2*n];
		} else {
			signal_lengths[n] = get_input_samples(n);
		}
		if (get_input_samples(n) != last_rcv_samples) {
			last_rcv_samples = get_input_samples(n);
#ifdef _COMPILE_ALOE
			modinfo_msg("Receiving %d samples at tslot %d\n",last_rcv_samples,
					oesr_tstamp(ctx));
#endif
		}
	}

#ifdef _COMPILE_ALOE
	if (print_not_received) {
		for (n=0;n<NOF_INPUT_ITF;n++) {
			if (MOD_DEBUG) {
				ainfo_msg("ts=%d, rcv_len=%d\n",oesr_tstamp(ctx),get_input_samples(n));
			}
			if (!get_input_samples(n)) {
				printf("ts=%d. Data not received from interface %d\n",oesr_tstamp(ctx),n);
			}

		}
	}
#endif


#ifdef _COMPILE_ALOE
	if (oesr_tstamp(ctx)-last_tstamp < interval_ts) {
		return 0;
	}
	last_tstamp = interval_ts;
#endif


	switch(mode) {
	case MODE_SILENT:
		break;
	case MODE_PRINT:
		for (n=0;n<NOF_INPUT_ITF;n++) {
			if (inp[n]) {
				print_signal(inp[n],get_input_samples(n));
			}
		}
	break;
	case MODE_SCOPE:
#ifdef _COMPILE_ALOE
		snprintf(xlabel,STR_LEN,"# sample (ts=%d)",oesr_tstamp(ctx));
#else
		snprintf(xlabel,STR_LEN,"# sample");
#endif
		if (is_complex) {
			set_legend(c_legends,2*NOF_INPUT_ITF);
		} else {
			set_legend(r_legends,NOF_INPUT_ITF);
		}
		set_labels(xlabel,"amp");

		for (n=0;n<NOF_INPUT_ITF;n++) {
			if (inp[n]) {
				if (is_complex) {
					c_input = inp[n];
					for (i=0;i<signal_lengths[2*n];i++) {
						pl_signals[2*n*INPUT_MAX_SAMPLES+i] = (double) __real__ c_input[i];
						pl_signals[(2*n+1)*INPUT_MAX_SAMPLES+i] = (double) __imag__ c_input[i];
					}
				} else {
					r_input = inp[n];
					for (i=0;i<signal_lengths[n];i++) {
						pl_signals[n*INPUT_MAX_SAMPLES+i] = (double) r_input[i];
					}
				}
			}

		}

		plp_draw(pl_signals,signal_lengths,0);
	break;
	case MODE_PSD:
#ifdef _COMPILE_ALOE
		snprintf(xlabel,STR_LEN,"freq. idx (ts=%d)",oesr_tstamp(ctx));
#else
		snprintf(xlabel,STR_LEN,"freq. idx");
#endif

		set_labels(xlabel,"PSD (dB/Hz)");

		set_legend(fft_legends,NOF_INPUT_ITF);

		for (i=0;i<NOF_INPUT_ITF;i++) {
			if (signal_lengths[i]) {
				if (fft_size) {
					signal_lengths[i] = signal_lengths[i]>fft_size?fft_size:signal_lengths[i];
				}
				plan = find_plan(signal_lengths[i]);
				c_input = inp[i];
				r_input = inp[i];
				if (!plan) {
					if ((plan = generate_new_plan(signal_lengths[i])) == NULL) {
						moderror("Generating plan.\n");
						return -1;
					}
				}
				if (is_complex) {
					dft_run_c2r(plan, c_input, &f_pl_signals[i*INPUT_MAX_SAMPLES]);
				} else {
					dft_run_r2r(plan, r_input, &f_pl_signals[i*INPUT_MAX_SAMPLES]);
				}
				/*if (!is_complex) {
					signal_lengths[i] = signal_lengths[i]/2;
				}*/
				for (j=0;j<signal_lengths[i];j++) {
					pl_signals[i*INPUT_MAX_SAMPLES+j] = (double) f_pl_signals[i*INPUT_MAX_SAMPLES+j];
				}
			}
		}
		for (i=NOF_INPUT_ITF;i<2*NOF_INPUT_ITF;i++) {
			signal_lengths[i] = 0;
		}
		plp_draw(pl_signals,signal_lengths,0);

	break;
	default:
		moderror_msg("Unknown mode %d\n",mode);
		return -1;

	}
	return 0;
}