⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph1.c

📁 三星公司的有线数字高频头资料及源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
      }

    	/* read the qam status */
	 		qam_read_status();

    	/* compute status information and display it */
    	sprintf(snr_str,"%5.3f dB",qam_status.snr_estimate);
    	status[SNR_ESTIMATE].val = snr_str;
      switch (QAM_MODE) {
        case QAM_4   : status[SEL_QAM_MODE].val = "QAM-4";     break;
        case QAM_16  : status[SEL_QAM_MODE].val = "QAM-16";    break;
        case QAM_32  : status[SEL_QAM_MODE].val = "QAM-32";    break;
        case QAM_64  : status[SEL_QAM_MODE].val = "QAM-64";    break;
        case QAM_128 : status[SEL_QAM_MODE].val = "QAM-128";   break;
        case QAM_256 : status[SEL_QAM_MODE].val = "QAM-256";   break;
      }
	 		status[LOCK_STATE].val = (QAM_IN_LOCK) ? "In Lock" : "Out of Lock";
    	status_plot(section3,"Equalizer Statistics",status,nstatus);

		} /* end if (runstat) */

    /* prompt for user input */
    if (kbhit()) {
      c = fkey_menu(0,fkey_win, fkeys);
      switch (c) {
	  		case 1 : /* FFE Freeze Control ... add later */
		   		break;
	  		case 2 : /* DFE freeze control ... add later */
		   		break;
	  		case 3 : 
        	lb_ptr[0] = "-- FFE --  -- DFE --";
		   		lb_ptr[1] = "Real Imag  Real Imag";
		   		for (i=0; i<8; i++) {
		     		lb_ptr[2+i] = listbuf[i];
		     		sprintf(lb_ptr[2+i],"%04x %04x %04x %04x",
			     		ffe_taps[14-2*i],ffe_taps[15-2*i],dfe_taps[2*i],dfe_taps[2*i+1]);
		   		}
          /* put in the remaining 4 DFE taps in the list */
		   		for (i=8; i<12; i++) {
		     		lb_ptr[2+i] = listbuf[i];
		     		sprintf(lb_ptr[2+i],"          %04x %04x",
            	dfe_taps[2*i],dfe_taps[2*i+1]);
		   		}
		   		lb_ptr[2+i] = (char *) 0;
		   		table_plot(100,100,lb_ptr);
		   		break;
	  		case 4 : 
        	log_scale = (log_scale) ? 0 : 1;
		   		break;
        case 5 : 
        	runstat = (runstat) ? 0 : 1;
          break;
        case 7 : 
        	show_freq=1;
          break;
        case 8 : 
        	break;
        case 9 : 
        	qam_init(qam_status.acq_script);
          break;
        case 10: 
        	done = 1;
          break;
      }  /* end switch */

      /* refresh menu */
      fkeys[3] = (log_scale)      ? "Linear Scale" : "Log Scale" ;
      fkeys[4] = (runstat)        ? "Stop"         : "Run"       ;
      fkey_menu(1,fkey_win, fkeys);
    }

  } /* end while */

  free(freq_response);
  
  closegraph();
  return QAM_OK;
}
/**************************************************************
* equ_monitor REVA - This routine monitors the performance of the
* QAM Equalizer. The screen is divided into 4 sections ...
* section 1 - real-time plot of real component of equalizer coefficients
* section 2 - imag-time plot of real component of equalizer coefficients
* section 3 - list of statistics computed from equalizer data
* section 4 - either frequency response of equalizer of real-time plot
*             of equalizer error.
* This routine samples the tap weights each pass. The HC11 acquisition is
* not used for the tap plots. The equalizer error plot uses it.
* 1/8/94 - PJM -
**************************************************************/
int equ_monitor_a(void)
{
  int      q, gdriver = DETECT, gmode, errorcode;
  int      xsiz,ysiz;
  int      x1,x2,y1,y2,xctr,yctr;
  int      i,j,c,x,done=0;
  char     msg[80];
  int      section0[4],section1[4],section2[4],section3[4],section4[4];
  int      fkey_win[4];
  int      xdim,ydim;
  int      nbytes,nwords,newdata,ffe,dfe;
  int      ffe_taps[32],dfe_taps[32];
  int      ffe_tmp[32],dfe_tmp[32];
  int      ffe_mag[32] ,dfe_mag[32];
  int      hi,ilo,qlo,i_err,q_err,refresh;
  int      max_tap,min_tap;
  float    offset;
  float    xscale,yscale,hscale,correction;
  float    *freq_response,mag;
  static float  plotbuf[BUFSIZE];
  int      lval1, lval2;
  float    avg_err,snr,fval1,fval2,err_scale,rms_nonlin;
  char     snr_str[32];
  char     *title[4],title_buf[80];
  static int initialized=0;
  static int runstat=1;      /* 1=running, 0=stopped  */
  static int log_scale=0;    /* 1=log scale,0=linear  */
  /* static */ int auto_scale;     /* 0=fixed scale for snr */
  char     *lb_ptr[20],listbuf[16][32],scalebuf[32];
  long     err_sum;
  int      do_fft_calc;
  int      sample_rate;
  int      show_freq=0;
  int      snr_index=0;

  char *fkeys[] = {
    ""    ,
    ""    ,
    "View Taps"     ,
    "Log Tap Scale" ,
    "Stop"          ,
    " "             ,

    "Freq Response" , 
    ""    ,
    "Reacquire"    ,
    "Exit"          ,
  };

  enum equ_status {
	 	LOCK_STATE=0 ,
	 	SEL_QAM_MODE ,
	 	SNR_ESTIMATE ,
  };
  int nstatus = 3;
  plot_status_t status[] = {
    "Lock Status "  , ""       , ""  ,
    "QAM Mode"  , ""       , ""  ,
    "SNR Estimate"  , ""       , "" ,
  };

  freq_response = malloc(DURATION*sizeof(float));
  
  for (i=0; i<64; i++) snr_data[i] = 0.0;

  /* read the qam status */
  qam_read_status();

  /* determine starting menu settings */
  fkeys[3] = (log_scale)     ? "Linear Scale"  : "Log Scale" ;
  fkeys[4] = (runstat)       ? "Stop"           : "Run"       ;

  /* init vars is 1st call */
  if (!initialized || runstat) {
    for (i=0; i<BUFSIZE; i++) plotbuf[i] = 0;
    initialized = 1;
  }

  /* init graphics mode and get screen size */
  initgraph(&gdriver, &gmode, "");
  if ((errorcode = graphresult()) != grOk) {
    printf("Graphics error: %s\n", grapherrormsg(errorcode));
    getch();
    exit(1);
  }
  xsiz = getmaxx();
  ysiz = getmaxy();

  /* now determine the coordinates of each sub-section */
  xdim = (xsiz - 7*EQU_BORDER) / 2;
  ydim = (ysiz - 15*EQU_BORDER) / 2;
  section0[0] = section0[1] = EQU_BORDER;
  section0[2] = xsiz - EQU_BORDER;
  section0[3] = ysiz - EQU_BORDER;
  section1[0] = section1[1] = 3*EQU_BORDER;
  section1[2] = section1[0] + xdim;
  section1[3] = section1[1] + ydim;
  section2[0] = 3*EQU_BORDER;
  section2[1] = section1[3] + 2*EQU_BORDER;
  section2[2] = section2[0] + xdim;
  section2[3] = section2[1] + ydim;
  section3[0] = section1[2] + 2*EQU_BORDER;
  section3[1] = 3*EQU_BORDER;
  section3[2] = section3[0] + xdim;
  section3[3] = section3[1] + ydim;
  section4[0] = section3[0];
  section4[1] = section3[3] + 2*EQU_BORDER;
  section4[2] = section4[0] + xdim;
  section4[3] = section4[1] + ydim;
  fkey_win[0] = 2*EQU_BORDER;
  fkey_win[2] = xsiz - 2*EQU_BORDER;
  fkey_win[1] = ysiz - 2*EQU_BORDER - FKEY_MENU_HEIGHT;
  fkey_win[3] = ysiz - 2*EQU_BORDER;
  fkey_menu(1,fkey_win, fkeys);

  refresh = (runstat) ? 0 : 1;

  while (!done) {
		if (runstat || refresh) {
      /* draw the border */
      refresh = 0;
      setlinestyle(SOLID_LINE,0xffff,THICK_WIDTH);
      setcolor(YELLOW);
      rectangle(section0[0],section0[1],section0[2],section0[3]);
      settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
      settextjustify(CENTER_TEXT,CENTER_TEXT);
      outtextxy(xsiz/2,EQU_BORDER/2,"QAM Adaptive Equalizer Performance Monitor");

      /* draw the section border */
      setcolor(WHITE);
      setlinestyle(SOLID_LINE,0,NORM_WIDTH);
      rectangle(section1[0],section1[1],section1[2],section1[3]);
      rectangle(section2[0],section2[1],section2[2],section2[3]);
      rectangle(section4[0],section4[1],section4[2],section4[3]);
      outtextxy(section1[0]+xdim/2,section1[1]-10,"Magnitude of Equalizer Taps");

      /* sample the equalizer taps */
      if (runstat) {
        for (i=0; i<8; i++) {
          qam_read(MB_R,MB_LDF0+i,&ffe_taps[2*i],&ffe_taps[2*i+1]);
          qam_read(MB_R,MB_LDD0+i,&dfe_taps[2*i],&dfe_taps[2*i+1]);
        }
    	}

    	/* compute the tap magnitude */
    	for (i=0; i<8; i++) {
        mag = (float) ffe_taps[2*i] * ffe_taps[2*i] + (float) ffe_taps[2*i+1] * ffe_taps[2*i+1];
        mag = (mag > 1.0e-06) ? sqrt(mag) : 0.0;
        if (mag > 32767.0) mag = 32767.0;
        ffe_mag[i] = (int) mag;

        mag = (float) dfe_taps[2*i] * dfe_taps[2*i] + (float) dfe_taps[2*i+1] * dfe_taps[2*i+1];
        mag = (mag > 1.0e-06) ? sqrt(mag) : 0.0;
        if (mag > 32767.0) mag = 32767.0;
        dfe_mag[i] = (int) mag;
	    }

  	  /* determine scaling */
    	xscale = 0.5 * (xdim - 2*EQU_BORDER - 8) / 8;
    	if (log_scale)  
      	yscale = 1.0 * (ydim - EQU_BORDER) / (80.0);   /* -60 dB to 20 dB */
      else          
      	yscale = 1.0 * (ydim - EQU_BORDER) / (8.0);

      /* draw hash marks */
      setfillstyle(SOLID_FILL,0);
      bar(1+section1[0],1+section1[1],section1[2]-1,section1[3]-1);
      xctr = section1[0] + xdim/2 + EQU_BORDER/2;
      yctr = section1[3] - EQU_BORDER;
      setcolor(RED);
      setlinestyle(USERBIT_LINE,0x3333,NORM_WIDTH);
      if (log_scale) {
        hscale = (ydim - EQU_BORDER) / 8.0;
        for (i=0; i<8; i++) 
        	line(section1[0],yctr-hscale*i,section1[2],yctr-hscale*i);
      } else {
        hscale = (ydim - EQU_BORDER) / 8.0;
        for (i=0; i<8; i++) 
        	line(section1[0],yctr-hscale*i,section1[2],yctr-hscale*i);
      }
      setlinestyle(SOLID_LINE,0,NORM_WIDTH);

    	/* display the taps */
	 		for (i=0; i < 8; i++) {   /* DFE Equalizer */
      	setfillstyle(SOLID_FILL,1+(i%8));
      	x1 = xctr + 2 + i*xscale;
      	x2 = xctr + 2 + i*xscale + xscale;
				y2 = yctr;
      	if (log_scale) {
		  		if (dfe_mag[i] < 5) 
          	y1 = yctr;
		  		else 
          	y1 = 1.0 * yctr - yscale * (60.0 + 20.0 * log10((float) dfe_mag[i] / 4096.0));
      	} else y1 = 1.0 * yctr - yscale * dfe_mag[i] / 4096.0;
				if (y1 > y2) 
        	y1=y2;
				bar(x1,y1,x2,y2);
    	}
    	for (i=0; i < 8; i++) {   /* FFE Equalizer */
				setfillstyle(SOLID_FILL,1+(i%8));
      	x1 = xctr - 2 - (7-i)*xscale - xscale;
      	x2 = xctr - 2 - (7-i)*xscale;
      	y2 = yctr;
      	if (log_scale) {
					if (ffe_mag[i] < 5) y1 = 1.0 * yctr;
					else y1 = 1.0 * yctr - yscale * (60.0 + 20.0 * log10((float) ffe_mag[i] / 4096.0));
      	} else y1 = 1.0 * yctr - yscale * ffe_mag[i] / 4096.0;
      	if (y1 > y2) y1=y2;
      	bar(x1,y1,x2,y2);
    	}
    	setcolor(WHITE);
    	line(section1[0],yctr,section1[2],yctr);
    	line(xctr,section1[1],xctr,section1[3]);

    	/* label the axis */
    	outtextxy(section1[0]+xdim/4  ,section1[1]+EQU_BORDER,"FFE");
    	outtextxy(section1[0]+3*xdim/4,section1[1]+EQU_BORDER,"DFE");

    	/* display the scale factors */
    	setcolor(WHITE);
    	settextstyle(SMALL_FONT,HORIZ_DIR,2);
    	settextjustify(LEFT_TEXT,CENTER_TEXT);
    	if (log_scale) {
      	hscale = (ydim - EQU_BORDER) / 8;
      	for (i=1; i<8; i++) {
					sprintf(scalebuf,"%4.1fdB",10.0*i-60.0);
					outtextxy(2+section1[0],xctr-i*hscale,scalebuf);
      	}
    	} else {
      	hscale = (ydim - EQU_BORDER) / 8;
      	for (i=1; i<8; i++) {
					sprintf(scalebuf,"%6.1f",1.0*i);
					outtextxy(2+section1[0],xctr-i*hscale,scalebuf);
      	}
    	}
    	settextstyle(SMALL_FONT,HORIZ_DIR,2);
    	settextjustify(RIGHT_TEXT,CENTER_TEXT);
    	if (log_scale) {
      	hscale = (ydim - EQU_BORDER) / 8;
      	for (i=1; i<8; i++) {
        	sprintf(scalebuf,"%4.1fdB",10.0*i-78.06);
        	outtextxy(section1[2]-2,xctr-i*hscale,scalebuf);
      	}
    	} else {
      	hscale = (ydim - EQU_BORDER) / 8;
      	for (i=1; i<8; i++) {
        	sprintf(scalebuf,"%5.3f",0.125*i);
        	outtextxy(section1[2]-2,xctr-i*hscale,scalebuf);
      	}
    	}
    	settextstyle(DEFAULT_FONT,HORIZ_DIR,1);

      /* this gets updated with the qam_read_status() routine */
    	snr_buf[snr_index++] = qam_status.snr_estimate;
        
      if (snr_index >= 16) {
        for (i=0; i<48; i++) snr_data[i] = snr_data[i+16];
        for (i=0; i<16; i++) snr_data[48+i] = snr_buf[i];
        snr_index = 0;
        title[0] = "SNR Estimate";
        title[1] = "Time ->";
        title[2] = "dB";
        line_plot(section2, snr_data, 64, 40.0, PLOT_UNARY, title);
      }

      /* calculate the linearized equalizer freq. response   */
      /* do this only if main tap is greater than all others */
      if (show_freq) {
        show_freq = 0;
        do_fft_calc = 1;
        for (i=0; i<8; i++) {
          if (ffe_mag[i] > ffe_mag[7] || dfe_mag[i] > ffe_mag[7]) 
          	do_fft_calc = 0;
        }
        if (do_fft_calc) {
                ffe = 8;
                dfe = 8;
                equ_freq_response(ffe_taps,dfe_taps,freq_response,ffe,dfe);
          title[0] = "Equalizer Freq. Response";
          sprintf(title_buf,"Carrier Frequency +/- 2.5 MHz");
          title[1] = title_buf;
          title[2] = "Gain(dB)";
          line_plot(section4,freq_response,DURATION,20.0,PLOT_SPECTRUM,title);
        }
      }

    	/* read the qam status */
	 		qam_read_status();

    	/* compute status information and display it */
    	sprintf(snr_str,"%5.3f dB",qam_status.snr_estimate);
    	status[SNR_ESTIMATE].val = snr_str;
    	status[SEL_QAM_MODE].val = "QAM-64";
	 		status[LOCK_STATE].val = (QAM_IN_LOCK) ? "In Lock" : "Out of Lock";
    	status_plot(section3,"Equalizer Statistics",status,nstatus);

		} /* end if (runstat) */

    /* prompt for user input */
    if (kbhit()) {
      c = fkey_menu(0,fkey_win, fkeys);
      switch (c) {
	  		case 1 : /* FFE Freeze Control ... add later */
		   		break;
	  		case 2 : /* DFE freeze control ... add later */
		   		break;
	  		case 3 : 
        	lb_ptr[0] = "-- FFE --  -- DFE --";
		   		lb_ptr[1] = "Real Imag  Real Imag";
		   		for (i=0; i<8; i++) {
		     		lb_ptr[2+i] = listbuf[i];
		     		sprintf(lb_ptr[2+i],"%04x %04x %04x %04x",
			     		ffe_taps[14-2*i],ffe_taps[15-2*i],dfe_taps[2*i],dfe_taps[2*i+1]);
		   		}
		   		lb_ptr[2+i] = (char *) 0;
		   		table_plot(100,100,lb_ptr);
		   		break;
	  		case 4 : 
        	log_scale = (log_scale) ? 0 : 1;
		   		break;
        case 5 : 
        	runstat = (runstat) ? 0 : 1;
          break;
        case 7 : 
        	show_freq=1;
          break;
        case 8 : 
        	break;
	case 9 :
		My_Acquisition();
// papi		qam_init(qam_status.acq_script);
          break;
        case 10: 
        	done = 1;
          break;
      }  /* end switch */

      /* refresh menu */
      fkeys[3] = (log_scale)      ? "Linear Scale" : "Log Scale" ;
      fkeys[4] = (runstat)        ? "Stop"         : "Run"       ;
      fkey_menu(1,fkey_win, fkeys);
    }

  } /* end while */

  free(freq_response);
  
  closegraph();
  return QAM_OK;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -