Exemplo n.º 1
0
  void IIRFilter::filter(CPX &c)
  {
	  if (!ready)
		  return;
	  c.real(filter(c.real(),xv1,yv1));
	  c.imag(filter(c.imag(),xv2,yv2));
  }
Exemplo n.º 2
0
/*
From Lynn 2nd ed pg 20
x[n] = sin(n * 2 * Pi * f / fs)
f = desired frequency
fs = sampling frequency or 1/sample rate

We calculate 2Pif/fs once and save it as step
so
x[n] = sin(n * stepTone)
----------------
The number of samples per cycle is fixed, but the samples will be taken at different points in
each cycle.  We need to make sure that the spacing between each sample is consistent with the
sample rate and frequency.
A 10hz signal completes a full cycle ever 1/10 sec (1/Freg)
At 48000 sps, this means we need 4800 samples for a complete cytle (sampleRate / freq)
So a 24khz signal will have 2 samples per cycle (48000/24000), which is the Nyquist limit
-----------------
*/
void NCO::genSingle(CPX *_in, quint32 _numSamples, double _dbGain, bool _mix)
{
	CPX cpx;
	for (quint32 i = 0; i < _numSamples; i++) {
		nextSample(cpx);
		cpx.real(cpx.real() * _dbGain);
		cpx.imag(cpx.imag() * _dbGain);
		if (_mix) {
			_in[i].real(_in[i].real() + cpx.real());
			_in[i].imag(_in[i].imag() + cpx.imag());
		} else {
			_in[i].real(cpx.real());
			_in[i].imag(cpx.imag());
		}
	}

}
Exemplo n.º 3
0
int C_FIR_filter::run (const CPX &in, CPX &out) {
	ibuffer[pointer] = in.real();
    qbuffer[pointer] = in.imag();
    counter++;
    if (counter == decimateratio)
        out = CPX (	mac(&ibuffer[pointer - length], ifilter, length),
                        mac(&qbuffer[pointer - length], qfilter, length) );
    pointer++;
    if (pointer == FIRBufferLen) {
        /// memmove is necessary if length >= FIRBufferLen/2 , theoretically possible.
        memmove (ibuffer, ibuffer + FIRBufferLen - length, length * sizeof (double) );
        memmove (qbuffer, qbuffer + FIRBufferLen - length, length * sizeof (double) );
        pointer = length;
    }
    if (counter == decimateratio) {
        counter = 0;
        return 1;
    }
    return 0;
}