Simultaneous Send Receive in C

Applications, development tools, FPGA, C, WEB
Post Reply
Grut3007
Posts: 5
Joined: Wed Mar 04, 2020 10:18 pm

Simultaneous Send Receive in C

Post by Grut3007 » Thu Mar 05, 2020 4:30 pm

Hello,

I am trying to send out a signal and compare the phase shift to the input. I can get the phase shift but it is different every time. The issue seems to be that the starting point for the data is not consistently at the same value. Is there a way to make sure this starting value stays constant every time the program is run?

I am also wondering if what I am trying to do is possible with the C code or if moving to FPGA programming is necessary.

Code: Select all


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include "redpitaya/rp.h"

int main(int argc, char **argv){
    /* Print error, if rp_Init() function failed */
    if(rp_Init() != RP_OK){
        fprintf(stderr, "Rp api init failed!\n");
    }
//################################SET UP BUFFER#########################################
    uint32_t buff_size = 16384; //16384
    float *buff = (float *)malloc(buff_size * sizeof(float));
//################################GENERATE MODULATING WAVE#########################################
    rp_AcqReset();
    rp_GenReset();
    rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
    rp_GenOutEnable(RP_CH_1);
    rp_AcqSetDecimation(RP_DEC_1);
    rp_AcqSetTriggerDelayNs(133340);
//################################SET UP ACQUIRING THE SIGNAL#########################################
    rp_GenAmp(RP_CH_1, 1.0);
    rp_GenFreq(RP_CH_1, 10000000.0);
    rp_AcqStart();
    sleep(0.0001333); //16385/125000000
//################################READ THE BUFFER#########################################
    rp_GenTrigger(RP_CH_1);
    rp_AcqGetOldestDataV(RP_CH_1, &buff_size, buff);
//###############################PHASE SHIFTING##########################################
    int i;
    double totalReal = 0;
    double totalImaginary = 0;
    double mixReal[buff_size];
    double mixImaginary[buff_size];
    double phi = 0;
    //16385
    for(i = 0; i < buff_size; i++){
        mixReal[i] = buff[i]*sin(((double)i/122880000)*2*3.14*10000000);//need to change argument based on sampling rate
        mixImaginary[i] = buff[i]*cos(((double)i/122880000)*2*3.14*10000000);
        totalReal += mixReal[i];
        totalImaginary += mixImaginary[i];
    }
    phi = atan((totalImaginary/buff_size) / (totalReal/buff_size));
    //rp_GenOutDisable(RP_CH_1);
    int j;
    FILE * fp;
    fp = fopen ("testoutput.txt", "w+");
    for(j = 0; j < buff_size; j++){
        printf("%f\n", buff[j]);
        fprintf(fp, "%f\n",buff[j]);
    }
    printf("%f\n", phi);
    fclose(fp);
    /* Releasing resources */
    free(buff);
    rp_Release();
    return 0;
}


kasaudio
Posts: 50
Joined: Sun Mar 11, 2018 6:03 pm

Re: Simultaneous Send Receive in C

Post by kasaudio » Sun Mar 08, 2020 2:30 am

Far from an expert, just thoughts...

Every "command" from cpu to fpga needs some time to process.

rp_GenFreq(RP_CH_1, 10000000.0); -> at some time
rp_AcqStart(); -> at some time later

Time difference between those two calls is short, but I guess hard to examine and random to some degree also. So there you get inconsistent phase shift.

I would look at the relative phase shift -> difference in phase shift without and with the observed system.

BR!

Grut3007
Posts: 5
Joined: Wed Mar 04, 2020 10:18 pm

Re: Simultaneous Send Receive in C

Post by Grut3007 » Tue Mar 10, 2020 4:12 pm

Thanks for the response!
I am a little confused about what you mean by the observed system. The phase shift i get is anywhere from about -1.5 to about 1.5 and is different every time.

But I guess my followup question would be do you know if there is a way to queue up the acquisition and generation such that they can be initiated by a common trigger?

kasaudio
Posts: 50
Joined: Sun Mar 11, 2018 6:03 pm

Re: Simultaneous Send Receive in C

Post by kasaudio » Wed Mar 11, 2020 10:01 am

I am a little confused about what you mean by the observed system.
I supposed you would like to measure the phase shift between input and output signal of system of interest -> observed system.

Grut3007
Posts: 5
Joined: Wed Mar 04, 2020 10:18 pm

Re: Simultaneous Send Receive in C

Post by Grut3007 » Wed Mar 11, 2020 4:05 pm

ah so my "observed system" is just the output hooked up to the input with a SMA cable.

kasaudio
Posts: 50
Joined: Sun Mar 11, 2018 6:03 pm

Re: Simultaneous Send Receive in C

Post by kasaudio » Wed Mar 11, 2020 10:41 pm

You could measure phase shift using different techniques according to concrete problem. What is written above posts above is just general approach. Normally you are interested in difference of phase shift across frequency range given.

Grut3007
Posts: 5
Joined: Wed Mar 04, 2020 10:18 pm

Re: Simultaneous Send Receive in C

Post by Grut3007 » Tue Apr 07, 2020 7:11 pm

So these forum strings seem to get close to answering the question but dont seem to conclude.

viewtopic.php?f=8&t=48
viewtopic.php?t=402

For post 48 it looks like you can set the registry values to make the them trigger at the same time or edit something in the fpga code. If I set the registry trigger can I set it "on" in the C code and effectively trigger both at the same time?

For post 402 post 2 it seems like ouput and input are linked? but im not seeing that in testing results running the code in C.

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: Google [Bot] and 13 guests