예제 #1
0
void main()
{
	//initialize intermediary values to zero
	for(n = 0; n < 11; n++)
	{
		w[n] = 0;
	}

	DSK6713_init();		// Initialize the board support library, must be called first
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_16KHZ);

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	while(1)						// main loop - do nothing but wait for interrupts
	{
	}
}
예제 #2
0
void main()
{
	DSK6713_init();		// Initialize the board support library, must be called first
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

    //convert coefficients to Q15 format
    short i,j;
    for(i = 0; i < 33; i++)
    {
    	w[i] = 0;
    }

    for(i = 0; i < 11; i++)
    {
    	for(j = 0; j < 3; j++)
    	{
    		NUM_s[i][j] = NUM[i][j] << 5;
    		DEN_s[i][j] = DEN[i][j] << 5;
    	}
    }

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_16KHZ);

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	while(1)						// main loop - do nothing but wait for interrupts
	{
	}
}
예제 #3
0
/********************************** init_hardware() **********************************/  
void init_hardware()
{
    // Initialize the board support library, must be called first 
    DSK6713_init();
    
    // Start the AIC23 codec using the settings defined above in config 
    H_Codec = DSK6713_AIC23_openCodec(0, &Config);

	/* Function below sets the number of bits in word used by MSBSP (serial port) for 
	receives from AIC23 (audio port). We are using a 32 bit packet containing two 
	16 bit numbers hence 32BIT is set for  receive */
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);	

	/* Configures interrupt to activate on each consecutive available 32 bits 
	from Audio port hence an interrupt is generated for each L & R sample pair */	
	MCBSP_FSETS(SPCR1, RINTM, FRM);

	/* These commands do the same thing as above but applied to data transfers to  
	the audio port */
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);	
	MCBSP_FSETS(SPCR1, XINTM, FRM);	
}
예제 #4
0
파일: sine.c 프로젝트: kronocharia/RTDSPlab
/******************************* init_hardware() ************************************/
void init_hardware()
{
    // Initialize the board support library, must be called first 
    DSK6713_init();
    
    // Start the codec using the settings defined above in config 
    H_Codec = DSK6713_AIC23_openCodec(0, &Config);

	/* Defines number of bits in word used by MSBSP for communications with AIC23
	 NOTE: this must match the bit resolution set in in the AIC23 */
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);
	
	/* Set the sampling frequency of the audio port. Must only be set to a supported 
	   frequency (8000/16000/24000/32000/44100/48000/96000) */
	
	DSK6713_AIC23_setFreq(H_Codec, get_sampling_handle(&sampling_freq));

}
예제 #5
0
void main()
{


	// initialize the save buffers
	for(j = 0; j < 2; j++){
		for (i=0;i<SAVES;i++) {
			cde_save[i] = 0;
			pcf_save[i] = 0;
			clockoffset_save[i] = 0.0;
			fde_save[i] = 0.0;
			imax_save[i] = 0;
			recbuf_start_clock_save[i] = 0;
			ppm_estimate_save[i] = 0.0;
			ytilde_save[i] = 0.0;
			state_prediction[j][i] = 0.0;
			state_estimate[j][i] = 0.0;
		}
	}

	// set up the fractionally shifted buffers
	for(k = 0; k < FER; k++){
		fractionalShift = ((double) k )/((double) FER); // number of samples to shift
		for (i=-N;i<=N;i++){
			x = ((double) i - fractionalShift)*BW;
			if (x==0.0) {
				y = 32767.0;
			}
			else
			{
				t = ((double) i - fractionalShift)*CBW;
				y = 32767.0*cos(2*PI*t)*sin(PI*x)/(PI*x); // double
			}
			j = i;
			if (j<0) {
				j += L; // wrap
			}
			allMyDelayedWaveforms[k][j] = (short) y;
		}
	}

	// set up the cosine and sin matched filters for searching
	// also initialize searching buffer
	for (i=0;i<M;i++){
		t = i*CBW;				// time
		y = cos(2*PI*t);		// cosine matched filter (double)
		mfc[i] = (float) y;		// cast and store
		y = sin(2*PI*t);		// sine matched filter (double)
		mfs[i] = (float) y;     // cast and store
		buf[i] = 0;             // clear searching buffer
	}

	// initialize clock buffers
	for (i=0;i<L;i++) {
		clockbuf[i] = 0;
		clockbuf_shifted[0][i] = 0;
		clockbuf_shifted[1][i] = 0;
	}

	// initialize sinc pulse buffer
	for (i=0;i<LL;i++)
		sincpulsebuf[i] = 0;

	// set up clock buffer and sinc pulse buffer
	// to play modulated sinc centered at zero
	for (i=-N;i<=N;i++){
		x = i*BW;
		if (i!=0) {
			t = i*CBW;
			y = 32767.0*cos(2*PI*t)*sin(PI*x)/(PI*x); // double
		}
		else {
			y = 32767.0;
		}
		j = i;
		if (j<0) {
			j += L; // wrap
		}
		clockbuf[j] = (short) y;
		j = i;
		if (j<0) {
			j += LL; // wrap
		}
		sincpulsebuf[j] = (short) y;
	}

	// set up inphase and quadrature sinc pulses for coarse and fine delay estimators
	j = 0;
	for (i=-N;i<=N;i++){
		x = i*BW;
		if (i!=0) {
			t = i*CBW;
			si[j] = (float) (cos(2*PI*t)*sin(PI*x)/(PI*x));
			sq[j] = (float) (sin(2*PI*t)*sin(PI*x)/(PI*x));
		}
		else {
			si[j] = 1.0;
			sq[j] = 0.0;
		}
		j++;
	}

	DSK6713_init();		// Initialize the board support library, must be called first
	DSK6713_LED_init(); // initialize LEDs
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ);

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	DSK6713_LED_toggle(3);

	while(1)						// main loop
	{
		if ((state==2)&&(delay_est_done==0)){  // TIME TO COMPUTE DELAY ESTIMATES

			DSK6713_LED_toggle(1);	// toggle LED here for diagnostics

			/*****************
			 * 				 *
			 * ESTIMATION    *
			 * 				 *
			 ****************/

			// compute coarse delay estimate
			zmax = 0.0;				// maximum
			imax = 0;				// index of maximum
			for (i=0;i<(2*M-1);i++){  // lag index
				z = 0;
				for (j=0;j<(2*N+1);j++) {
					z+= si[j]*recbuf[i+j];  // correlation at lag i
				}
				if (abs(z)>zmax) {
					zmax = abs(z);  // store maximum
					imax = i;       // store index of maximum
				}
			}
			cde = recbuf_start_clock + imax + N;  // coarse delay estimate (DRB: +N here because si is already shifted by N)
			// cde  is the number of samples elapsed since we launched the S->M sinc pulse

		    // compute fine delay estimate
			zi = 0.0;  // in phase
			zq = 0.0;  // quadrature
			for (j=0;j<(2*N+1);j++) {
				zi+= si[j]*recbuf[imax+j];  // correlation at lag imax
				zq+= sq[j]*recbuf[imax+j];  // correlation at lag imax
			}
			pcf = atan2(zq,zi)*(2*INVPI); // assumes wc = pi/2
			fde = (float) cde + pcf;

			// compute actual clock offset
			// the value computed here is always non-negative and
			// represents the number of samples the master clock is ahead of the slave clock
			// (or the number of samples the slave clock is behind the master clock)
			// S->M sinc pulse was launched at time 0
			// M->S sinc pulse was received at time fde (should be positive)
			// to synchronize, we want slave clock ticks to appear at fde/2 + k*L for k=0,1,....
			clockoffset = fde*0.5;

			// testing/debugging
			imax_save[save_index] = imax;
			recbuf_start_clock_save[save_index] = recbuf_start_clock;
			cde_save[save_index] = cde;
			pcf_save[save_index] = pcf;
			fde_save[save_index] = fde;
			clockoffset_save[save_index] = clockoffset;


			//If first time running
			if(!hasSaved && save_index == 0){
			   state_estimate[0][0] = clockoffset* TS;
			   state_estimate[1][0] = 0;
			   state_prediction[0][1] = clockoffset * TS;
			   state_prediction[1][1] = 0;
			}

			else
			{   // save_index > 0
			    ytilde = clockoffset * TS - state_prediction[0][save_index];  // innovation (difference between current observation and prediction)


			    state_estimate[0][save_index] = state_prediction[0][save_index] + ((double) K1)*ytilde;  // filtered clock offset estimate
			    state_estimate[1][save_index] = state_prediction[1][save_index] + ((double)K2)*ytilde;  // filtered frequency offset estimate

			    //Determine if a glitch has happened


			    if (save_index+1<SAVES) {
			        // generate predictions for next observation (make sure multiplication by LL doesn't cause datatype problems)
			        state_prediction[0][save_index+1] = state_estimate[0][save_index] +  state_estimate[1][save_index] * (double)T0;//* LL;
			        state_prediction[1][save_index+1] = state_estimate[1][save_index];
			    }
			    else if(save_index + 1 == SAVES){
			    	state_prediction[0][0] = state_estimate[0][save_index] + state_estimate[1][save_index]* (double)T0;//* LL;
			    	state_prediction[1][0] = state_prediction[1][save_index];
			    }
			}

			//Calculate the rate offset
			if(!hasSaved && save_index < 1){
				if(save_index == 0)
					rateoffset_estimate = 0;
				else
					rateoffset_estimate = TS * (clockoffset_save[save_index] - clockoffset_save[save_index - 1]);
			}

			//Otherwise, use kalman filter
			else{
				rateoffset_estimate = state_prediction[0][save_index] - state_estimate[0][save_index];

			}

			//

			if(clockoffset_save[save_index] > L && clockoffset_save[save_index - 1] < L)
				adjustedclockoffset = clockoffset_save[save_index] + 5 * L * rateoffset_estimate;
			else if(clockoffset_save[save_index] > L && clockoffset_save[save_index - 1] < L)
				adjustedclockoffset = clockoffset_save[save_index] + 3 * L *rateoffset_estimate;
			else
				adjustedclockoffset = clockoffset_save[save_index] + 4 * L * rateoffset_estimate;
			////////


			j = (short) adjustedclockoffset; // casting from float to short just truncates, e.g., 3.99 becomes 3
			fractionalShift = adjustedclockoffset - (double) j; // fractionalShift >= 0 and < 1 tells us how much of a sample is left
			k = (short) (fractionalShift * (double) FER + 0.5);  // this now rounds and givse results on 0,...,FER
			if (k==FER) {  // we rounded up to the next whole sample
				k = 0;
				j++;
			}
			for (i=0;i<L;i++) {
				ell = j+i;

				while (ell>=L) {
					ell = ell-L;
				}

				if (current_clockbuf==0) {
					clockbuf_shifted[1][ell] = allMyDelayedWaveforms[k][i];  // write other buffer
				}
				else {
					clockbuf_shifted[0][ell] = allMyDelayedWaveforms[k][i];  // write other buffer
				}

			}

			// when can we swap buffers?
			buffer_swap_index = j+L/2;  // midpoint of the silent part (I think)
			while (buffer_swap_index>=L)
				buffer_swap_index = buffer_swap_index-L;

			// tell the ISR the calculations are done
			delay_est_done = 1;

			// update save index
			save_index++;
			if (save_index>=SAVES)  // wrap
				{
				save_index = 0;
				hasSaved = 1;
				}

			DSK6713_LED_toggle(1);	// toggle LED here for diagnostics

		}
		else if (buffer_just_swapped==1) {
			// this code computes the next buffer and attempts to corect for the frequency offset
			buffer_just_swapped = 0;
			// copy appropriate fractionally shifted clock buffer to shifted clock buffer
			adjustedclockoffset = adjustedclockoffset + ((double) L)*one_over_beta;  // adjust latency of next pulse
			while (adjustedclockoffset>((double) L))
				adjustedclockoffset = adjustedclockoffset - (double) L;
			j = (short) adjustedclockoffset; // casting from float to short just truncates, e.g., 3.99 becomes 3
			fractionalShift = adjustedclockoffset - (double) j; // fractionalShift >= 0 and < 1 tells us how much of a sample is left
			k = (short) (fractionalShift * (double) FER);  // this also truncates and should give result on 0,...,FER-1
			for (i=0;i<L;i++) {
				ell = j+i;
				if (ell>=L) {
					ell = ell-L;
				}
				if (current_clockbuf==0) {
					clockbuf_shifted[1][ell] = allMyDelayedWaveforms[k][i];  // write other buffer
				}
				else {
					clockbuf_shifted[0][ell] = allMyDelayedWaveforms[k][i];  // write other buffer
				}

			}
		} // if ((state==2)&&(delay_est_done==0))
	}  // while(1)
}  // void main
예제 #6
0
void main()
{
	DSK6713_init();		// Initialize the board support library, must be called first
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_8KHZ);

	//initialize buffers to zero
	init();

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	//temporary variable for real-imag swapping for ifft, placed here for convenience
	float temp = 0;

	while(1)						// main loop - do nothing but wait for interrupts
	{
		if(pingFlag == 1){
			for(n = 0; n < FFT_LENGTH; n++){
				if(n < (ORDER - 1)){
					pingU[n] = Z[n];
				}
				else{
					pingU[n] = PING[n - (ORDER - 1)];
				}
			}
//			cfftr2_dit(pingU,w,FFT_LENGTH); //TI floating-pt complex FFT
//			bitrev(pingU,ix,FFT_LENGTH); //freq scrambled->bit-reverse X

			for(n = 0; n < FFT_LENGTH; n++){
//				V[n] = cmplxMult(h[n],pingU[n]);

				V[n] = pingU[n];

				//swap real and imaginary for ifft, remember to uncomment temp as well
//				temp = V[n].re;
//				V[n].re = V[n].im;
//				V[n].im = temp;
			}

//			cfftr2_dit(V,w,FFT_LENGTH) ; //TI floating-pt complex ifft
//			bitrev(V,ix,FFT_LENGTH); //freq scrambled->bit-reverse X

			for(n = ORDER - 1; n < FFT_LENGTH; n++)
			{
				outputPING[n] = V[n].re * 32768;
			}

			for(n = (FFT_LENGTH - (ORDER - 1)) - (ORDER -1); n < FFT_LENGTH - (ORDER - 1); n++)
			{
				Z[n] = PING[n];
			}
			lflag = 1;
		}
		if(pongFlag == 1){
			for(n = 0; n < FFT_LENGTH; n++){
				if(n < (ORDER - 1)){
					pongU[n] = Z[n];
				}
				else{
					pongU[n] = PONG[n - (ORDER - 1)];
				}
			}

//			cfftr2_dit(pongU,w,FFT_LENGTH) ; //TI floating-pt complex FFT
//			bitrev(pongU,ix,FFT_LENGTH); //freq scrambled->bit-reverse X

			for(n = 0; n < FFT_LENGTH; n++){
//				V[n] = cmplxMult(h[n],pongU[n]);

				V[n] = pongU[n];

//				swap real and imaginary for ifft, remember to uncomment temp as well
//				temp = V[n].re;
//				V[n].re = V[n].im;
//				V[n].im = temp;
			}
//			cfftr2_dit(V,w,FFT_LENGTH) ; //TI floating-pt complex ifft
//			bitrev(V,ix,FFT_LENGTH); //freq scrambled->bit-reverse X

			for(n = ORDER - 1; n < FFT_LENGTH; n++)
			{
				outputPONG[n] = V[n].re * 32768;
			}

			for(n = (FFT_LENGTH - (ORDER - 1)) - (ORDER -1); n < FFT_LENGTH - (ORDER - 1); n++)
			{
				Z[n] = PONG[n];
			}
			lflag = 1;
		}
	}
}
void main()
{

	// set up the cosine and sin matched filters for searching
	// also initialize searching buffer
	for (i=0;i<M;i++){
		t = i*0.25;				// time
		y = cos(2*PI*t);		// cosine matched filter (double)
		mfc[i] = (float) y;		// cast and store
		y = sin(2*PI*t);		// sine matched filter (double)
		mfs[i] = (float) y;     // cast and store
		buf[i] = 0.0;             // clear searching buffer
		fbuf[i] = 0.0;
	}

	// initialize input buffer
	for (i=0;i<BL;i++)
		inbuf[i] = 0.0;

	// initialize clock buffer
	for (i=0;i<L;i++)
		clockbuf[i] = 0;

	// set up clock buffer to play modulated sinc centered at zero
	for (i=-N;i<=N;i++){
		x = i*BW;
		if (i!=0) {
			t = i*0.25;
			y = ((double) CLOCKAMPLITUDE)*cos(CARRIERKHZ*PI*t)*sin(PI*x)/(PI*x); // double
		}
		else {
			y = ((double) CLOCKAMPLITUDE);
		}
		j = i;
		if (j<0) {
			j += L; // wrap
		}
		clockbuf[j] = (short) y;
	}



	DSK6713_init();		// Initialize the board support library, must be called first
	DSK6713_LED_init(); // initialize LEDs
    hCodec = DSK6713_AIC23_openCodec(0, &config);	// open codec and get handle

	// Configure buffered serial ports for 32 bit operation
	// This allows transfer of both right and left channels in one read/write
	MCBSP_FSETS(SPCR1, RINTM, FRM);
	MCBSP_FSETS(SPCR1, XINTM, FRM);
	MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
	MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);

	// set codec sampling frequency
	DSK6713_AIC23_setFreq(hCodec, DSK6713_AIC23_FREQ_16KHZ);

	// interrupt setup
	IRQ_globalDisable();			// Globally disables interrupts
	IRQ_nmiEnable();				// Enables the NMI interrupt
	IRQ_map(IRQ_EVT_RINT1,15);		// Maps an event to a physical interrupt
	IRQ_enable(IRQ_EVT_RINT1);		// Enables the event
	IRQ_globalEnable();				// Globally enables interrupts

	while(1)						// main loop
	{
	}
}