Exemple #1
0
/**
 * gwy_spectra_set_spectrum:
 * @spectra: A spectra object.
 * @i: Index of a spectrum to replace
 * @new_spectrum: A #GwyDataLine Object containing the new spectrum.
 *
 * Replaces the ith spectrum in the spectra object with a the
 * supplied spectrum, new_spectrum. It takes its own reference
 * to the New_Spectrum dataline.
 *
 * Since: 2.7
 **/
void
gwy_spectra_set_spectrum(GwySpectra *spectra,
                         guint i,
                         GwyDataLine *new_spectrum)
{
    GwySpectrum *spec;

    g_return_if_fail(GWY_IS_SPECTRA(spectra));
    g_return_if_fail(GWY_IS_DATA_LINE(new_spectrum));
    g_return_if_fail(i < spectra->spectra->len);

    spec = &g_array_index(spectra->spectra, GwySpectrum, i);
    g_object_ref(new_spectrum);
    g_object_unref(spec->ydata);
    spec->ydata = new_spectrum;
}
Exemple #2
0
/**
 * gwy_spectra_add_spectrum:
 * @spectra: A spectra object.
 * @new_spectrum: A GwyDataLine containing the spectrum to append.
 * @x: The physical x coordinate of the location of the spectrum.
 * @y: The physical y coordinate of the location of the spectrum.
 *
 * Appends a new_spectrum to the spectra collection with a position of x, y.
 * gwy_spectra_add takes a refference to the supplied spectrum.
 *
 * Since: 2.7
 **/
void
gwy_spectra_add_spectrum(GwySpectra *spectra,
                         GwyDataLine *new_spectrum,
                         gdouble x, gdouble y)
{
    GwySpectrum spec;

    g_return_if_fail(GWY_IS_SPECTRA(spectra));
    g_return_if_fail(GWY_IS_DATA_LINE(new_spectrum));

    g_object_ref(new_spectrum);
    spec.x = x;
    spec.y = y;
    spec.ydata = new_spectrum;
    spec.selected = FALSE;
    g_array_append_val(spectra->spectra, spec);
}
Exemple #3
0
/**
 * gwy_data_line_psdf:
 * @data_line: data line
 * @target_line: result data line
 * @windowing: windowing method
 * @interpolation: interpolation method
 *
 * Copmutes power spectral density function and stores the values in
 * @target_line.
 **/
void
gwy_data_line_psdf(GwyDataLine *data_line, GwyDataLine *target_line, gint windowing, gint interpolation)
{
    GwyDataLine *iin, *rout, *iout;
    gint i, order, newres, oldres;

    g_return_if_fail(GWY_IS_DATA_LINE(data_line));

    oldres = data_line->res;
    order = (gint) floor(log ((gdouble)data_line->res)/log (2.0)+0.5);
    newres = (gint) pow(2,order);

    iin = (GwyDataLine *)gwy_data_line_new(newres, data_line->real, TRUE);
    rout = (GwyDataLine *)gwy_data_line_new(newres, data_line->real, TRUE);
    iout = (GwyDataLine *)gwy_data_line_new(newres, data_line->real, TRUE);

    /*resample to 2^N (this could be done within FFT, but with loss of precision)*/
    gwy_data_line_resample(data_line, newres, interpolation);

    gwy_data_line_fft(data_line, iin, rout, iout, gwy_data_line_fft_hum,
                   windowing, 1, interpolation,
                   TRUE, TRUE);

    gwy_data_line_resample(target_line, newres/2.0, GWY_INTERPOLATION_NONE);

    /*compute module*/
    for (i = 0; i < (newres/2); i++) {
        target_line->data[i] = (rout->data[i]*rout->data[i] + iout->data[i]*iout->data[i])
            *data_line->real/(newres*newres*2*G_PI);
    }
    target_line->real = 2*G_PI*target_line->res/data_line->real;

    /*resample to given output size*/
    gwy_data_line_resample(target_line, oldres/2.0, interpolation);


    g_object_unref(rout);
    g_object_unref(iin);
    g_object_unref(iout);

}