Analyzing frequencies and trigger question?

Applications, development tools, FPGA, C, WEB
Post Reply
memoran
Posts: 2
Joined: Wed Feb 01, 2017 11:02 am

Analyzing frequencies and trigger question?

Post by memoran » Mon Feb 27, 2017 11:56 am

I'm fairly new in RedPitaya programming and not skilled with programming at all.
I have written a small acquisition programm(in c), which should also be able to perform a fft.

My first question concerns the trigger:
Redpitaya is acquiring a signal on input 2. After the trigger condition happened( TRIG_NOW command), the buffer is read out and plotted. But in the plot i have a discontinuity around sample 8000, which i do not understand(see picture withoutsleep). I was able to avoid this problem by using the usleep command after the trigger happened(see picture withsleep). I know that, when the trigger happened, that a standard delay of 8192 samples is implemented. But I cannot explain what happens. The c-code is:

Code: Select all

/* Test program to acquire signals on  a specified input */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "redpitaya/rp.h"

int main(int argc, char **argv) {
	
	/* Initialization of API (important. Must be called first, before any other library method)*/
	if (rp_Init()!=RP_OK){
		printf("RedPitaya API init failed");
		return EXIT_FAILURE;
	}
	
	/*only for testing*/
	FILE *f;
	f = fopen("test.txt", "w");
	
	/*Defining variables*/
	int32_t trig_delay = 0;
	rp_channel_t source = RP_CH_2; /*Channel B*/
	rp_acq_decimation_t acq_dec = RP_DEC_1; /*other dec: 8,64,1024,8192,65536*/
	rp_acq_trig_src_t trig_state = RP_TRIG_SRC_NOW;
	unsigned int acq_sleep = 132;
	unsigned int cnt;
	unsigned int musleep=1;
	
	/*Defining Buffer, Data reader*/
	uint32_t buff_size = 16384;
    float *buff = (float *)malloc(buff_size * sizeof(float));
	
	/*Acquisition part*/
	rp_AcqReset();
	rp_AcqSetDecimation(acq_dec); 
	rp_AcqSetTriggerDelay(trig_delay);
	
	/*Start acquisition*/
	rp_AcqStart();
	usleep(acq_sleep);
	
	/*Wait for trigger condition (while loop), here the trigger is set manually*/
	rp_AcqSetTriggerSrc(trig_state);
	usleep(musleep); % Must be implemented to avoid the discontinuity
	rp_AcqGetOldestDataV(source,&buff_size,buff);
	/*Write data in a file for testing*/
	for(cnt=0; cnt<buff_size; cnt++){
		fprintf(f,"%f \n", buff[cnt]);
	}
	
	/*Releases the library resources, must be called last*/
	free(buff);
	rp_Release();
	fclose(f);
	return EXIT_SUCCESS;
}
My second problem is, that i would like to append this program so that i can analyze the frequencies, but im unable to call the freq_analyzer tool. How can I do that?

Thank you !
memoran
You do not have the required permissions to view the files attached to this post.

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Analyzing frequencies and trigger question?

Post by Nils Roos » Tue Feb 28, 2017 12:06 am

Regarding your first question:
You more or less said it yourself already, when you initiate the manual trigger with rp_AcqSetTriggerSrc(), it marks the start of the post-trigger recording period of (by default) 8192 samples. As long as recording is still active, you should not read from the buffer. If you do, it may happen that you read from sections while they are being updated, which results in discontinuities in the data.
A better alternative than waiting a fixed amount of time is to poll the trigger source, it will reset to IDLE when recording stops. From that point on, the buffer contents remain static until you call rp_AcqStart() again.
i would like to append this program so that i can analyze the frequencies, but im unable to call the freq_analyzer tool.
I suppose you want to analyse a dataset that you acquired in your program and not have the freq_analyzer app do the acquisition, too. In that case you pick the required functions and their infrastructure from the freq_analyzer sources and add them to your code. I might be able to give better hints if I knew what you tried already :mrgreen:

memoran
Posts: 2
Joined: Wed Feb 01, 2017 11:02 am

Re: Analyzing frequencies and trigger question?

Post by memoran » Mon Mar 06, 2017 2:44 pm

Thank you for the answer Nils!!! Regarding the fft:
  1. How can i call the freq_analyzer app in a c-program? ( I always get "undefined reference rpApp_init")
  • How can i implement the fft-function with their infrastructure into a c-program ?(If there is a manual or a description somewhere, i would be happy to read that)
greetings memoran

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Analyzing frequencies and trigger question?

Post by Nils Roos » Tue Mar 07, 2017 12:44 am

How can i implement the fft-function with their infrastructure into a c-program ?(If there is a manual or a description somewhere, i would be happy to read that)
You could look at the spectrum analyzer sourcecode of the RP api (spec_dsp.c and the kiss_fft folder of the api). That is the closest thing to a description that I know of.
How can i call the freq_analyzer app in a c-program? ( I always get "undefined reference rpApp_init")
Do you mean calling functions from the controllerhf.so of the freq_analyzer app, or do you mean compiling the sourcecode of the app into your program? In the latter case, you should remove all code that calls rpApp_... functions, those are only required in the bazaar context.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 79 guests