Esempio n. 1
0
CWToneGen
newCWToneGen (
			  REAL gain,	// dB
			  REAL freq,	// ms
			  REAL rise,	// ms
			  REAL fall,	// ms
			  int size,		// samples
			  REAL samplerate) // samples/sec
{
	CWToneGen cwt = (CWToneGen) safealloc (1, sizeof (CWToneGenDesc),
		"CWToneGenDesc");

	setCWToneGenVals (cwt, gain, freq, rise, fall);
	cwt->size = size;
	cwt->sr = samplerate;

	cwt->osc.gen = newOSC (cwt->size,
		ComplexTone,
		(double) cwt->osc.freq, 0.0, cwt->sr, "CWTone osc");

	// overload oscillator buf
	cwt->buf = newCXB (cwt->size, OSCCbase (cwt->osc.gen), "CWToneGen buf");

	return cwt;
}
DTTSPAGC
newDttSPAgc (AGCMODE mode,
			 COMPLEX * Vec,
			 int BufSize,
			 REAL Limit,
			 REAL attack,
			 REAL decay,
			 REAL slope,
			 REAL hangtime,
			 REAL samprate,
			 REAL MaxGain, REAL MinGain, REAL CurGain, char *tag)
{
	DTTSPAGC a;

	a = (DTTSPAGC) safealloc (1, sizeof (dttspagc), tag);
	a->mode = mode;

	a->attack = (REAL) (1.0 - exp (-1000.0 / (attack * samprate)));
	a->one_m_attack = (REAL) exp (-1000.0 / (attack * samprate));

	a->decay = (REAL) (1.0 - exp (-1000.0 / (decay * samprate)));
	a->one_m_decay = (REAL) exp (-1000.0 / (decay * samprate));

	a->fastattack = (REAL) (1.0 - exp (-1000.0 / (0.2 * samprate)));
	a->one_m_fastattack = (REAL) exp (-1000.0 / (0.2 * samprate));

	a->fastdecay = (REAL) (1.0 - exp (-1000.0 / (3.0 * samprate)));
	a->one_m_fastdecay = (REAL) exp (-1000.0 / (3.0 * samprate));

	strcpy (a->tag, tag);
	a->mask = 2 * BufSize;

	a->hangindex = a->indx = 0;
	a->hangtime = hangtime * 0.001f;
	a->hangthresh = 0.0;
	a->sndx = (int) (samprate * attack * 0.003f);
	a->fastindx = (int)(0.002f*samprate);
	a->gain.fix = 10.0;

	a->slope = slope;
	a->gain.top = MaxGain;
	a->hangthresh = a->gain.bottom = MinGain;
	a->gain.fastnow = a->gain.old = a->gain.now = CurGain;

	a->gain.limit = Limit;

	a->buff = newCXB (BufSize, Vec, "agc in buffer");
	a->circ = newvec_COMPLEX (a->mask, "circular agc buffer");
	a->mask -= 1;

	a->fasthang = 0;
	a->fasthangtime = 0.1f*a->hangtime;

	return a;
}
Esempio n. 3
0
AMD
newAMD (REAL samprate,
	REAL f_initial,
	REAL f_lobound,
	REAL f_hibound,
	REAL f_bandwid,
	int size, COMPLEX * ivec, COMPLEX * ovec, AMMode mode, char *tag)
{
	AMD am = (AMD) safealloc (1, sizeof (AMDDesc), tag);

	am->size = size;
	am->ibuf = newCXB (size, ivec, tag);
	am->obuf = newCXB (size, ovec, tag);
	am->mode = mode;
	init_pll (am, samprate, f_initial, f_lobound, f_hibound, f_bandwid);

	am->lock.curr = 0.5;
	am->lock.prev = 1.0;
	am->dc = 0.0;

	return am;
}
Esempio n. 4
0
void
init_spectrum (SpecBlock * sb)
{
	REAL phase_tmp = 0.0;
	REAL gain_tmp = 1.0;
	COMPLEX *p;
	sb->fill = 0;

	p = newvec_COMPLEX_fftw(sb->size*16,"spectrum accum");
	sb->accum = newCXB (sb->size * 16, p, "spectrum accum");
	p = newvec_COMPLEX_fftw(sb->size, "spectrum timebuf");
	sb->timebuf = newCXB (sb->size, p, "spectrum timebuf");
	p = newvec_COMPLEX_fftw(sb->size, "spectrum timebuf");
	sb->freqbuf = newCXB (sb->size, p, "spectrum freqbuf");
	sb->window = newvec_REAL (sb->size * 16, "spectrum window");
	makewindow (BLACKMANHARRIS_WINDOW, sb->size, sb->window);
	sb->mask = sb->size - 1;
	sb->polyphase = FALSE;
	sb->output =
		(float *) safealloc (sb->size, sizeof (float), "spectrum output");
	sb->coutput = (COMPLEX *)safealloc (sb->size, sizeof (COMPLEX), "spectrum output");;
	sb->plan =
		fftwf_plan_dft_1d (sb->size, (fftwf_complex *) CXBbase (sb->timebuf),
		(fftwf_complex *) CXBbase (sb->freqbuf),
		FFTW_FORWARD, sb->planbits);
	sb->iqfix = newCorrectIQspec2();													// SV1EIA AIR
	sb->iqfix->buffer_counter = 0;														// SV1EIA AIR
	sb->iqfix->im_max_actual = 0;														// SV1EIA AIR
	sb->iqfix->im_max_test = 0;															// SV1EIA AIR
	sb->iqfix->im_min_actual = 0;														// SV1EIA AIR
	sb->iqfix->im_min_test = 0;															// SV1EIA AIR
	sb->iqfix->re_max_actual = 0;														// SV1EIA AIR
	sb->iqfix->re_max_test = 0;															// SV1EIA AIR
	sb->iqfix->re_min_actual = 0;														// SV1EIA AIR
	sb->iqfix->re_min_test = 0;															// SV1EIA AIR

}
Esempio n. 5
0
void
init_spectrum (SpecBlock * sb)
{
	COMPLEX *p;
	sb->fill = 0;

	p = newvec_COMPLEX_16(sb->size*16,"spectrum accum");
	sb->accum = newCXB (sb->size * 16, p, "spectrum accum");
	p = newvec_COMPLEX_16(sb->size, "spectrum timebuf");
	sb->timebuf = newCXB (sb->size, p, "spectrum timebuf");
	p = newvec_COMPLEX_16(sb->size, "spectrum timebuf");
	sb->freqbuf = newCXB (sb->size, p, "spectrum freqbuf");
	sb->window = newvec_REAL (sb->size * 16, "spectrum window");
	makewindow (BLACKMANHARRIS_WINDOW, sb->size, sb->window);
	sb->mask = sb->size - 1;
	sb->polyphase = FALSE;
	sb->output =
		(float *) safealloc (sb->size, sizeof (float), "spectrum output");
	sb->coutput = (COMPLEX *)safealloc (sb->size, sizeof (COMPLEX), "spectrum output");;
	sb->plan =
		fftwf_plan_dft_1d (sb->size, (fftwf_complex *) CXBbase (sb->timebuf),
		(fftwf_complex *) CXBbase (sb->freqbuf),
		FFTW_FORWARD, sb->planbits);
}
Esempio n. 6
0
WSCompander
newWSCompander (int npts, REAL fac, CXB buff)
{
	WSCompander wsc;

	wsc = (WSCompander) safealloc (1,
		sizeof (WSCompanderInfo),
		"WSCompander struct");
	wsc->npts = npts;
	wsc->nend = npts - 1;
	wsc->tbl = newvec_REAL (npts, "WSCompander table");
	wsc->buff = newCXB (CXBsize (buff), CXBbase (buff), "WSCompander buff");
	WSCReset (wsc, fac);
	return wsc;
}
Esempio n. 7
0
/* ---------------------------------------------------------------------------- */
FMD
newFMD(REAL samprate,
       REAL f_initial,
       REAL f_lobound,
       REAL f_hibound,
       REAL f_bandwid,
       int size,
       COMPLEX *ivec,
       COMPLEX *ovec,
       char *tag) {
  FMD fm = (FMD) safealloc(1, sizeof(FMDDesc), tag);

  fm->size = size;
  fm->ibuf = newCXB(size, ivec, tag);
  fm->obuf = newCXB(size, ovec, tag);

  init_pll(fm, samprate, f_initial, f_lobound, f_hibound, f_bandwid);

  fm->lock = 0.5;
  fm->afc = 0.0;
  fm->cvt = (REAL) (0.45 * samprate / (M_PI * f_bandwid));

  return fm;
}
Esempio n. 8
0
LMSR
new_lmsr (CXB signal,
	  int delay,
	  REAL adaptation_rate,
	  REAL leakage, int adaptive_filter_size, int filter_type)
{
  LMSR lms = (LMSR) safealloc (1, sizeof (_lmsstate), "new_lmsr state");

  lms->signal = newCXB(signal->size,CXBbase(signal),"lmadf CXB");
  lms->signal_size = CXBsize (lms->signal);
  lms->delay = delay;
  lms->size = 4096;
  lms->mask = lms->size - 1;
  lms->delay_line = newvec_COMPLEX (lms->size, "lmsr delay");
  lms->adaptation_rate = adaptation_rate;
  lms->leakage = leakage;
  lms->adaptive_filter_size = adaptive_filter_size;
  lms->adaptive_filter = newvec_COMPLEX (128, "lmsr filter");
  lms->filter_type = filter_type;
  lms->delay_line_ptr = 0;

  return lms;
}
Esempio n. 9
0
SpotToneGen
newSpotToneGen (REAL gain,	// dB
		REAL freq, REAL rise,	// ms
		REAL fall,	// ms
		int size, REAL samplerate)
{

  SpotToneGen st = (SpotToneGen) safealloc (1,
					    sizeof (SpotToneGenDesc),
					    "SpotToneGenDesc");

  setSpotToneGenVals (st, gain, freq, rise, fall);
  st->size = size;
  st->sr = samplerate;

  st->osc.gen = newOSC (st->size,
			ComplexTone,
			st->osc.freq, 0.0, st->sr, "SpotTone osc");

  // overload oscillator buf
  st->buf = newCXB (st->size, OSCCbase (st->osc.gen), "SpotToneGen buf");

  return st;
}
Esempio n. 10
0
DTTSPAGC
newDttSPAgc (AGCMODE mode,
			 COMPLEX *Vec,
			 int BufSize,   // Size of the input buffer
			 REAL target,   // The target voltage
			 REAL attack,   // Attack time constant in msec
			 REAL decay,    // Decay time constant in msec
			 REAL slope,    // Rate of change of gain after agc threshold is exceeded
			 REAL hangtime, // Hang Time in msec where NO decay is allowed in the agc
			 REAL samprate, // Sample Rate so time can be turned into sample number
			 REAL MaxGain,  // Maximum allowable gain
			 REAL MinGain,  // Minimum gain (can be -dB / less than 1.0 as in ALC or strong signals on receive
			 REAL CurGain,  // The initial gain setting
			 char *tag)     // String to emit when error conditions occur
{
	DTTSPAGC a;

	a = (DTTSPAGC) safealloc (1, sizeof (dttspagc), tag);
	a->mode = mode;

	// Attack: decrease gain when input signal will produce an output signal above the target voltage
	// Decay:  increase gain when input signal will produce an output signal below the target voltage
	
	// Compute exponential attack rate per sample from attack time and sampler rate.
	a->attack = (REAL) (1.0 - exp (-1000.0 / (attack * samprate))); 
	// Compute 1.0 - attack time.
	a->one_m_attack = (REAL) (1.0 - a->attack);

	// Compute exponential decay rate per sample from attack time and sampler rate.
	a->decay = (REAL) (1.0 - exp (-1000.0 / (decay * samprate)));
	// Compute 1.0 - decay time.
	a->one_m_decay = (REAL) (1.0 - a->decay);

	// Our system has a two track agc response.  The normal one found in most receive
	// systems is the determined from the calculations we just made.
	// Ours has a fast track agc which is designed to prevent large pulse signals from pushing
	// us into serious attack and wait for a long decay when the signal is short duration < 3 time constants for attack

	// Compute exponential fast attack rate per sample from fast attack time and sampler rate.
	a->fastattack = (REAL) (1.0 - exp (-1000.0 / (0.2 * samprate)));
	// Compute 1.0 - fast attack time.
	a->one_m_fastattack = (REAL) (1.0 - a->fastattack);

	// Compute exponential fast decay rate per sample from fast attack time and sampler rate.
	a->fastdecay = (REAL) (1.0 - exp (-1000.0 / (3.0 * samprate)));
	// Compute 1.0 - fast decay time.
	a->one_m_fastdecay = (REAL) (1.0 - a->fastdecay);

	// Save the error identification message
	strcpy (a->tag, tag);

	// This computes the index max for our circular buffer
	a->mask = 2 * BufSize - 1;
	
	// Hangtime:  This is a period of NO allowed decay even though we need to increase gain to stay at target level
	// hangindex is used to compute how deep into the hang interval we are.
	a->hangindex = a->slowindx = 0;
	// Change hang time to hang length in samples using time and sample rate.
	a->hangtime = hangtime * 0.001f;
	//a->hangthresh = 0.0; // not neccessary?
	// We BEGIN applying decreasing gain 3 time constants ahead of the signals arrival to narrow the modulation
	// spread arising from modulating the signal with the agc gain.  The index to application of computed gain
	// sndx and it is computed as number of samples in 3 attack time constants
	a->out_indx = (int) (samprate * attack * 0.003f);

	// We do the same anticipation in the fast channel but we only do two time constants.
	a->fastindx = (int)(0.0027f*samprate);
	// see update.c:SetRAGC()
	a->gain.fix = 10000.0;

	// Slope:  The rate at which gain is decreased as signal strength increases after it exceeds the agc threshold
	// that is, after the required gain to reach the desired output level is LESS THAN the maximum allowable gain.
	a->slope = slope;

	// gain.top = Maxgain which is the maximum allowable gain.  This determines the agc threshold
	a->gain.top = MaxGain;
	// gain.bottom = MinGain is the minimum allowable gain.  If < 0dB or 1.0, then this is an attenuation.
	a->hangthresh = a->gain.bottom = MinGain;
	// Initialize the gain state to an initial value
	a->gain.fastnow = a->gain.old = a->gain.now = CurGain;

	// Set the target voltage.
	a->gain.target = target;

	// Given the vector of input samples,  make a local complex buffer (struct to handle metadata associated with
	// the vector or array of samples
	a->buff = newCXB (BufSize, Vec, "agc in buffer");
	// Use a circular buffer for efficiency in dealing with the anticipatory part of the agc algorithm
	a->circ = newvec_COMPLEX (2 * BufSize, "circular agc buffer");

	// intialize fast hang index to 0
	a->fasthang = 0;

	// Whatever the hangtime is for the slow channel, make the fast agc channel hangtime 10% of it
	a->fasthangtime = 0.1f*a->hangtime;

	return a;
}
Esempio n. 11
0
File: TX.cpp Progetto: g4klx/uWSDR
CTX::CTX(unsigned int bufLen, unsigned int bits, float sampleRate, CMeter* meter, CSpectrum* spectrum, bool swapIQ) :
m_sampleRate(sampleRate),
m_meter(meter),
m_spectrum(spectrum),
m_type(SPEC_TX_POST_FILT),
m_swapIQ(swapIQ),
m_iBuf(NULL),
m_oBuf(NULL),
m_iq(NULL),
m_dcBlock(NULL),
m_dcBlockFlag(true),
m_oscillator1(NULL),
m_oscillator2(NULL),
m_filter(NULL),
m_modulator(NULL),
m_amModulator(NULL),
m_fmModulator(NULL),
m_ssbModulator(NULL),
m_alc(NULL),
m_micGain(0.0F),
m_power(0.0F),
m_speechProc(NULL),
m_speechProcFlag(false),
m_equaliser(NULL),
m_equaliserFlag(false),
m_mode(USB),
m_weaver(true),
m_freq(0.0),
m_lowFreq(0.0),
m_highFreq(0.0),
m_tick(0UL)
{
	wxASSERT(meter != NULL);
	wxASSERT(spectrum != NULL);

	m_filter = new CFilterOVSV(bufLen, bits, sampleRate, 300.0F, 3000.0F);

	m_iBuf = newCXB(m_filter->fetchSize(), m_filter->fetchPoint());
	m_oBuf = newCXB(m_filter->storeSize(), m_filter->storePoint());

	m_iq = new CCorrectIQ(m_oBuf);

	m_dcBlock = new CDCBlock(m_iBuf);

	m_oscillator1 = new COscillator(m_oBuf, sampleRate);
	m_oscillator2 = new COscillator(m_iBuf, sampleRate);

	m_amModulator  = new CAMMod(0.5F, m_iBuf);
	m_fmModulator  = new CFMMod(5000.0F, sampleRate, m_iBuf);
	m_ssbModulator = new CSSBMod(m_iBuf);
	m_modulator    = m_ssbModulator;

	m_alc = new CAGC(agcLONG,	// mode kept around for control reasons alone
			    	m_iBuf,	// input buffer
			    	1.2F,	// Target output
			    	2.0F,	// Attack time constant in ms
			    	10.0F,	// Decay time constant in ms
			    	1.0F,	// Slope
			    	500.0F,	//Hangtime in ms
			    	sampleRate,	// Sample rate
					1.0F,	// Maximum gain as a multipler, linear not dB
			    	0.000001F,	// Minimum gain as a multipler, linear not dB
			    	1.0);		// Set the current gain

	m_speechProc = new CSpeechProc(0.4F, 3.0, m_iBuf);

	m_equaliser = new CEqualiser(sampleRate, bits, m_iBuf);
}