Beispiel #1
0
qreal QtfeCanal::evalf(qreal t) const
{
	if(t<=0.0) return first.y();
	if(t>=1.0) return last.y();

	for(int i=0 ; i<list.size()-1 ; ++i)
	{
		qreal x0 = list[i]->x();
		qreal x1 = list[i+1]->x();

		if(t < x0 || t > x1)
			continue;

		qreal y0 = list[i]->y();
		qreal y1 = list[i+1]->y();
		qreal v0 = (i>0) ? (list[i+1]->y() - list[i-1]->y()) : (list[1]->y() - list[0]->y());
		qreal v1 = (i<list.size()-2) ? (list[i+2]->y() - list[i]->y()) : (list[list.size()-1]->y() - list[list.size()-2]->y());

		qreal res = qMin(qMax(interp2(y0, v0, y1, v1, (t-x0)/(x1-x0)), 0.0), 1.0);
		return res;
	 }
	return 0.0;
}
Beispiel #2
0
/*!
   main thread function. Get data buffer, perform fft and scaling,
   write to spectrum buffer.
 */
void Spectrum::processData(unsigned char *data, unsigned char bptr)
{
    unsigned int  j    = bptr * sizes.advance_size;
    unsigned char *ptr = &data[j];
    for (int i = 0; i < sizes.sample_length; i++) {
        double tmpr;
        double tmpi;
        switch (bits) {
        case 16:
        {
            // convert 16 bit
            int ii = ptr[1];
            ii = (ii << 8) | ptr[0];
            if (ii & 0x8000) ii |= ~0xffff;
            tmpr = ii / 32768.0;
            ptr += 2;
            ii   = ptr[1];
            ii   = (ii << 8) | ptr[0];
            if (ii & 0x8000) ii |= ~0xffff;
            tmpi = ii / 32768.0;
            ptr += 2;
            j   += 4;
        }
        break;
        case 24:
        {
            // convert 24 bit signed integer sample to floating point by placing data into
            // 32-bit signed int
            // data is in ptr[0](LSB) ... ptr[2](MSB)
            //
            int ii = (ptr[2] << 24) | (ptr[1] << 16) | (ptr[0] << 8);

            // divide by (2^31 - 1) - (2^8 -1) = 2147483647 - 255 = 2147483392
            // actual float range then [1.0: -1.000000119]
            tmpr = ii / 2147483392.0;
            ptr += 3;

            // repeat for other stereo channel sample
            ii   = (ptr[2] << 24) | (ptr[1] << 16) | (ptr[0] << 8);
            tmpi = ii / 2147483392.0;
            ptr += 3;
            j   += 6;
        }
        break;
        case 32:
        {
            // convert 32 bit sample to floating point
            // data is in ptr[0](LSB)..ptr[3](MSB)

            // put data into 32-bit signed int
            int ii = (ptr[3] << 24) | (ptr[2] << 16) | (ptr[1] << 8) | ptr[0];

            // divide by (2^31 - 1) = 2147483647
            tmpr = ii / 2147483647.0;
            ptr += 4;

            // repeat for other stereo channel sample
            ii   = (ptr[3] << 24) | (ptr[2] << 16) | (ptr[1] << 8) | ptr[0];
            tmpi = ii / 2147483647.0;
            ptr += 4;
            j   += 8;
        }
        break;
        default:
            tmpr = 0.;
            tmpi = 0.;
            break;
        }
        in[i][0] = tmpr * window[i];
        in[i][1] = tmpi * window[i];
        if (j == sizes.chunk_size) {
            // make buffer circular
            j   = 0;
            ptr = &data[0];
        }
    }

    // done reading raw data, emit signal so audioReader can procede
    emit(done());
#ifdef Q_OS_WIN
    (fftw_executep) (plan);
#else
    fftw_execute(plan);
#endif
    if (settings.value(s_sdr_iqcorrect[nrig],s_sdr_iqcorrect_def[nrig]).toBool()) {
        for (int i = 0; i < sizes.sample_length; i++) {
            // correct IQ imbalance
            int    j    = sizes.sample_length - i - 1;
            double real = out[i][0] + out[j][0] - (out[i][1] + out[j][1]) * errfunc[i][1] + (out[i][0] - out[j][0]) * errfunc[i][0];
            double imag = out[i][1] - out[j][1] + (out[i][1] + out[j][1]) * errfunc[i][0] + (out[i][0] - out[j][0]) * errfunc[i][1];
            spec_tmp[i] = real * real + imag * imag;
        }
    } else {
        for (int i = 0; i < sizes.sample_length; i++) {
            spec_tmp[i] = (out[i][0] * out[i][0] + out[i][1] * out[i][1]);
        }
    }

    double bga, sigma;
    measureBackground(bga, sigma, spec_tmp);

    if (settings.value(s_sdr_iqdata[nrig],s_sdr_iqdata_def[nrig]).toBool()) {
        if (calibCnt == (SIG_CALIB_FREQ - 1)) {
            measureIQError(bga, spec_tmp);
            calibCnt = 0;
        } else {
            calibCnt++;
        }
    }

    for (int i = 0; i < sizes.sample_length; i++) {
        spec_tmp[i] = log(spec_tmp[i]);
#ifdef Q_OS_LINUX
        if (isinf(spec_tmp[i])) spec_tmp[i] = -1.0e-16;
#endif
    }

    measureBackgroundLog(bga, sigma, spec_tmp);

    // put upper limit on background. Prevents display "blacking out"
    // from static crashes
    if (bga > 0.0) bga = 0.0;
    if (settings.value(s_sdr_peakdetect[nrig],s_sdr_peakdetect_def[nrig]).toBool()) {
        detectPeaks(bga, sigma, spec_tmp);
    }

    if (settings.value(s_sdr_click[nrig],s_sdr_click_def[nrig]).toBool()) {
    //if (clickFilter) {
        clickRemove(bga, sigma, spec_tmp);

        // re-measure background since click removal changes it
        // measureBackgroundLog(bga,sigma,spec_tmp);
    }


    if (settings.value(s_sdr_scale[nrig],s_sdr_scale_def[nrig]).toInt() == 2) {
        interp2(spec_tmp, tmp4, bga); // expand by 2 using linear interpolation
    } else {
        // IF offset included here
        // for (int i=0;i<sizes.display_length;i++) {
        double tmp = ((settings.value(s_sdr_offset[nrig],s_sdr_offset_def[nrig]).toInt()-addOffset) *
                      sizes.spec_length * settings.value(s_sdr_scale[nrig],s_sdr_scale_def[nrig]).toInt()) / (SAMPLE_FREQ * 1000.0);
        int offsetPix = -(int) tmp;
        for (int i = 0; i < sizes.spec_length; i++) {
            unsigned int j = (sizes.spec_length - offsetPix - MAX_H / 2 + i) % sizes.spec_length;
            spec_tmp[j] = (spec_tmp[j] - bga + 2.0) * 25.0;
            if (spec_tmp[j] < 0.0) {
                spec_tmp[j] = 0.0;
            } else if (spec_tmp[j] > 255.0) {
                spec_tmp[j] = 255.0;
            }
            tmp4[i] = spec_tmp[j];
        }
    }
    unsigned int cnt = 0;
    for (int i = 0; i < sizes.display_length; i++) {
        output[i] = (unsigned char) tmp4[i];
        cnt      += output[i];
    }
    background = cnt / sizes.display_length;  // background measurement
    emit(spectrumReady(output, background));

    if (calcErrorNext) {
        calcError(false);
        calcErrorNext = false;
    }
}
void Masek::normaliseiris(Masek::filter *image, int xiris, int yiris, int riris, 
                          int xpupil, int ypupil, int rpupil,
                          char *eyeimage_filename,
						  int radpixels, int angulardiv, 
						  Masek::filter *polar_array, Masek::IMAGE *polar_noise)
{
//global DIAGPATH
int radiuspixels;
int angledivisions;
double r;
double *theta, *b, xcosmat, xsinmat, rmat;
filter xo, yo;
int i, j;
double x_iris, y_iris, r_iris, x_pupil, y_pupil, r_pupil, ox, oy;
int sgn;
double phi;
double a;
//FILE *fid;
//IMAGE tmpimage;
int *x, *y, *xp, *yp;
int len;
double sum, avg;
int count;

//printfilter(image, "image.txt");
radiuspixels = radpixels + 2;
angledivisions = angulardiv-1;


theta = (double*)malloc(sizeof(double)*(angledivisions+1));
for (i = 0; i<angledivisions+1; i++)
	theta[i] = 2*i*PI/angledivisions;

x_iris = (double)xiris;
y_iris = (double)yiris;
r_iris = (double)riris;

x_pupil = (double)xpupil;
y_pupil = (double)ypupil;
r_pupil = (double)rpupil;

//% calculate displacement of pupil center from the iris center
ox = x_pupil - x_iris;
oy = y_pupil - y_iris;

if (ox <= 0)
    sgn = -1;
else if (ox > 0)
    sgn = 1;


if (ox==0 && oy > 0)
    sgn = 1;


//a = ones(1,angledivisions+1)* (ox^2 + oy^2);
a = ox*ox+oy*oy;

//% need to do something for ox = 0
if (ox == 0)
    phi = PI/2;
else
    phi = atan(oy/ox);

b = (double*)malloc(sizeof(double)*(angledivisions+1));
xo.hsize[0] = (radiuspixels-2);
xo.hsize[1] = angledivisions+1;
xo.data = (double*)malloc(sizeof(double)*(angledivisions+1)*(radiuspixels-2));

yo.hsize[0] = (radiuspixels-2);
yo.hsize[1] = angledivisions+1;
yo.data = (double*)malloc(sizeof(double)*(angledivisions+1)*(radiuspixels-2));

//% calculate radius around the iris as a function of the angle
for (i = 0; i<angledivisions+1; i++)
{
	b[i] = sgn*cos(PI - phi - theta[i]);
	r = sqrt(a)*b[i]+sqrt(a*b[i]*b[i]-(a-r_iris*r_iris));
	r -= r_pupil;
	
	//% calculate cartesian location of each data point around the circular iris
	//% region
	xcosmat = cos(theta[i]);
	xsinmat = sin(theta[i]);
/*% exclude values at the boundary of the pupil iris border, and the iris scelra border
% as these may not correspond to areas in the iris region and will introduce noise.
%
% ie don't take the outside rings as iris data.*/

	for (j = 0; j<radiuspixels; j++)
	{
		rmat = r*j/(radiuspixels-1);
		rmat += r_pupil;
		if (j>0 && j<radiuspixels-1)
		{
			xo.data[(j-1)*(angledivisions+1)+i] = rmat*xcosmat+x_pupil;
			yo.data[(j-1)*(angledivisions+1)+i] = -rmat*xsinmat+y_pupil;
		}
	}
}

/*

% extract intensity values into the normalised polar representation through
% interpolation
[x,y] = meshgrid(1:size(image,2),1:size(image,1)); */
interp2(image, &xo, &yo, polar_array);

//% create noise array with location of NaNs in polar_array
polar_noise->hsize[0] = polar_array->hsize[0];
polar_noise->hsize[1] = polar_array->hsize[1];
polar_noise->data = (unsigned char*)malloc(sizeof(unsigned char)*polar_noise->hsize[0]*polar_noise->hsize[1]);
memset(polar_noise->data, 0, polar_noise->hsize[0]*polar_noise->hsize[1]);

count=0;

for (i = 0; i<polar_noise->hsize[0]*polar_noise->hsize[1]; i++)
{
    if (isnan(polar_array->data[i])) // Lee: renamed from "isnan"
	{
		polar_noise->data[i] = 1;
		count++;
	}
	else
	{
		polar_noise->data[i] = 0;
        polar_array->data[i] = polar_array->data[i]/255;
	}
}

//printfilter(polar_array, "polar.txt");
//printimage(polar_noise, "polar_noise.txt");

//% start diagnostics, writing out eye image with rings overlayed

//% get rid of outling points in order to write out the circular pattern
for (i = 0; i<xo.hsize[0]*xo.hsize[1]; i++)
{
	if (xo.data[i]>image->hsize[1])
		xo.data[i] = image->hsize[1];
	else if (xo.data[i]<1)
		xo.data[i] = 1;
	xo.data[i] = roundND(xo.data[i]);
}

for (i = 0; i<yo.hsize[0]*yo.hsize[1]; i++)
{
	if (yo.data[i]>image->hsize[0])
		yo.data[i] = image->hsize[0];
	else if (yo.data[i]<1)
		yo.data[i] = 1;
	yo.data[i] = roundND(yo.data[i]);
}


/*tmpimage.hsize[0] = image->hsize[0];
tmpimage.hsize[1] = image->hsize[1];
tmpimage.data = (unsigned char*)malloc(sizeof(unsigned char)*tmpimage.hsize[0]*tmpimage.hsize[1]);
for (i = 0; i<tmpimage.hsize[0]*tmpimage.hsize[1]; i++)
{
	if (_isnan(image->data[i]))  // Lee: renamed from "isnan"
		tmpimage.data[i] = 0;
	else
		tmpimage.data[i] = (int)image->data[i];
}*/



/*for (i = 0; i<yo.hsize[0]*yo.hsize[1]; i++)
	tmpimage.data[(int)((yo.data[i]-1)*tmpimage.hsize[1]+(xo.data[i])-1)] = 255;
*/

//%get pixel coords for circle around iris
len = circlecoords(x_iris,y_iris,r_iris,image->hsize, -1, &x, &y);


//ind2 = sub2ind(size(image),double(y),double(x));
/*fid = fopen("xy.txt", "w");
for (i = 0; i<len; i++)
{
	fprintf(fid, "%d %d %d\n", i+1, x[i], y[i]);
	tmpimage.data[(y[i]-1)*tmpimage.hsize[1]+(x[i]-1)] = 255;
}
fclose(fid);*/
//%get pixel coords for circle around pupil

len = circlecoords(x_pupil,y_pupil,r_pupil,image->hsize, -1, &xp, &yp);
/*for (i = 0; i<len; i++)
	tmpimage.data[(yp[i]-1)*tmpimage.hsize[1]+(xp[i]-1)] = 255;*/
//printimage(&tmpimage, "tmpimage.txt");


/*% write out rings overlaying original iris image
%w = cd;
%cd(DIAGPATH);
imwrite(image,[eyeimage_filename,'-normal.jpg'],'jpg');

%cd(w);

% end diagnostics
*/
//%replace NaNs before performing feature encoding
sum = 0;
for (i = 0; i<polar_array->hsize[0]*polar_array->hsize[1]; i++)
{
    if (isnan(polar_array->data[i])) // Lee: renamed from "isnan"
		sum+=0.5;
	else
		sum+=polar_array->data[i];
}
avg = sum/(polar_array->hsize[0]*polar_array->hsize[1]);

for (i = 0; i<polar_array->hsize[0]*polar_array->hsize[1]; i++)
{
    if (isnan(polar_array->data[i]))
		//polar_array->data[i] = sqrt((double)-1);//LEE:added
		polar_array->data[i] = avg;
}

free(xp);
free(yp);
free(x);
free(y);

free(theta);
free(b);
free(xo.data);
free(yo.data);

//printfilter(polar_array, "polar_array.txt");
}