void Formant_drawTracks (Formant me, Graphics g, double tmin, double tmax, double fmax, int garnish) { long itmin, itmax, ntrack = Formant_getMinNumFormants (me); if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; } if (! Sampled_getWindowSamples (me, tmin, tmax, & itmin, & itmax)) return; Graphics_setInner (g); Graphics_setWindow (g, tmin, tmax, 0.0, fmax); for (long itrack = 1; itrack <= ntrack; itrack ++) { for (long iframe = itmin; iframe < itmax; iframe ++) { Formant_Frame curFrame = & my d_frames [iframe], nextFrame = & my d_frames [iframe + 1]; double x1 = Sampled_indexToX (me, iframe), x2 = Sampled_indexToX (me, iframe + 1); double f1 = curFrame -> formant [itrack]. frequency; double f2 = nextFrame -> formant [itrack]. frequency; if (NUMdefined (x1) && NUMdefined (f1) && NUMdefined (x2) && NUMdefined (f2)) Graphics_line (g, x1, f1, x2, f2); } } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, U"Time (s)"); Graphics_textLeft (g, 1, U"Formant frequency (Hz)"); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeftEvery (g, 1.0, 1000.0, 1, 1, 1); } }
void FilterBank_paint (FilterBank me, Graphics g, double xmin, double xmax, double ymin, double ymax, double minimum, double maximum, int garnish) { if (xmax <= xmin) { xmin = my xmin; xmax = my xmax; } if (ymax <= ymin) { ymin = my ymin; ymax = my ymax; } long ixmin, ixmax, iymin, iymax; (void) Matrix_getWindowSamplesX (me, xmin - 0.49999 * my dx, xmax + 0.49999 * my dx, &ixmin, &ixmax); (void) Matrix_getWindowSamplesY (me, ymin - 0.49999 * my dy, ymax + 0.49999 * my dy, &iymin, &iymax); if (maximum <= minimum) { (void) Matrix_getWindowExtrema (me, ixmin, ixmax, iymin, iymax, &minimum, &maximum); } if (maximum <= minimum) { minimum -= 1.0; maximum += 1.0; } if (xmin >= xmax || ymin >= ymax) { return; } Graphics_setInner (g); Graphics_setWindow (g, xmin, xmax, ymin, ymax); Graphics_image (g, my z, ixmin, ixmax, Sampled_indexToX (me, ixmin - 0.5), Sampled_indexToX (me, ixmax + 0.5), iymin, iymax, SampledXY_indexToY (me, iymin - 0.5), SampledXY_indexToY (me, iymax + 0.5), minimum, maximum); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_marksLeft (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, GetFreqScaleText (my v_getFrequencyScale ())); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_textBottom (g, 1, U"Time (s)"); } }
void Formant_scatterPlot (Formant me, Graphics g, double tmin, double tmax, int iformant1, double fmin1, double fmax1, int iformant2, double fmin2, double fmax2, double size_mm, const char32 *mark, int garnish) { if (iformant1 < 1 || iformant2 < 1) return; if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; } long itmin, itmax; if (! Sampled_getWindowSamples (me, tmin, tmax, & itmin, & itmax)) return; if (fmax1 == fmin1) Formant_getExtrema (me, iformant1, tmin, tmax, & fmin1, & fmax1); if (fmax1 == fmin1) return; if (fmax2 == fmin2) Formant_getExtrema (me, iformant2, tmin, tmax, & fmin2, & fmax2); if (fmax2 == fmin2) return; Graphics_setInner (g); Graphics_setWindow (g, fmin1, fmax1, fmin2, fmax2); for (long iframe = itmin; iframe <= itmax; iframe ++) { Formant_Frame frame = & my d_frames [iframe]; if (iformant1 > frame -> nFormants || iformant2 > frame -> nFormants) continue; double x = frame -> formant [iformant1]. frequency; double y = frame -> formant [iformant2]. frequency; if (x == 0.0 || y == 0.0) continue; Graphics_mark (g, x, y, size_mm, mark); } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, Melder_cat (U"%%F_", iformant1, U" (Hz)")); Graphics_textLeft (g, 1, Melder_cat (U"%%F_", iformant2, U" (Hz)")); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeft (g, 2, 1, 1, 0); } }
void GaussianMixture_and_PCA_drawConcentrationEllipses (GaussianMixture me, PCA him, Graphics g, double scale, int confidence, wchar_t *label, long d1, long d2, double xmin, double xmax, double ymin, double ymax, int fontSize, int garnish) { if (my dimension != his dimension) { Melder_warning1 (L"Dimensions don't agree."); return;} SSCPs thee = NULL; int d1_inverted = 0, d2_inverted = 0; if (d1 < 0) { d1 = abs(d1); Eigen_invertEigenvector (him, d1); d1_inverted = 1; } if (d2 < 0) { d2 = abs(d2); Eigen_invertEigenvector (him, d2); d2_inverted = 1; } if ((thee = SSCPs_toTwoDimensions ((SSCPs) my covariances, his eigenvectors[d1], his eigenvectors[d2])) == NULL) goto end; if (d1_inverted) Eigen_invertEigenvector (him, d1); if (d2_inverted) Eigen_invertEigenvector (him, d2); SSCPs_drawConcentrationEllipses (thee, g, -scale, confidence, label, 1, 2, xmin, xmax, ymin, ymax, fontSize, 0); if (garnish) { wchar_t label[40]; Graphics_drawInnerBox (g); Graphics_marksLeft (g, 2, 1, 1, 0); swprintf (label, 40, L"pc %ld", d2); Graphics_textLeft (g, 1, label); Graphics_marksBottom (g, 2, 1, 1, 0); swprintf (label, 40, L"pc %ld", d1); Graphics_textBottom (g, 1, label); } end: forget (thee); }
void FormantFilter_drawFilterFunctions (FormantFilter me, Graphics g, double bandwidth, int toFreqScale, int fromFilter, int toFilter, double zmin, double zmax, int dbScale, double ymin, double ymax, int garnish) { if (! checkLimits (me, FilterBank_HERTZ, toFreqScale, & fromFilter, & toFilter, & zmin, & zmax, dbScale, & ymin, & ymax)) { return; } if (bandwidth <= 0) { Melder_warning (U"Bandwidth must be greater than zero."); } long n = 1000; autoNUMvector<double>a (1, n); Graphics_setInner (g); Graphics_setWindow (g, zmin, zmax, ymin, ymax); for (long j = fromFilter; j <= toFilter; j++) { double df = (zmax - zmin) / (n - 1); double fc = my y1 + (j - 1) * my dy; long ibegin, iend; for (long i = 1; i <= n; i++) { double f = zmin + (i - 1) * df; double z = scaleFrequency (f, toFreqScale, FilterBank_HERTZ); if (z == NUMundefined) { a[i] = NUMundefined; } else { a[i] = NUMformantfilter_amplitude (fc, bandwidth, z); if (dbScale) { a[i] = to_dB (a[i], 10, ymin); } } } setDrawingLimits (a.peek(), n, ymin, ymax, &ibegin, &iend); if (ibegin <= iend) { double fmin = zmin + (ibegin - 1) * df; double fmax = zmax - (n - iend) * df; Graphics_function (g, a.peek(), ibegin, iend, fmin, fmax); } } Graphics_unsetInner (g); if (garnish) { double distance = dbScale ? 10 : 1; char32 const *ytext = dbScale ? U"Amplitude (dB)" : U"Amplitude"; Graphics_drawInnerBox (g); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeftEvery (g, 1, distance, 1, 1, 0); Graphics_textLeft (g, 1, ytext); Graphics_textBottom (g, 1, GetFreqScaleText (toFreqScale)); } }
void MelFilter_drawFilterFunctions (MelFilter me, Graphics g, int toFreqScale, int fromFilter, int toFilter, double zmin, double zmax, int dbScale, double ymin, double ymax, int garnish) { if (! checkLimits (me, FilterBank_MEL, toFreqScale, & fromFilter, & toFilter, & zmin, & zmax, dbScale, & ymin, & ymax)) { return; } long n = 1000; autoNUMvector<double> a (1, n); Graphics_setInner (g); Graphics_setWindow (g, zmin, zmax, ymin, ymax); for (long j = fromFilter; j <= toFilter; j++) { double df = (zmax - zmin) / (n - 1); double fc_mel = my y1 + (j - 1) * my dy; double fc_hz = MELTOHZ (fc_mel); double fl_hz = MELTOHZ (fc_mel - my dy); double fh_hz = MELTOHZ (fc_mel + my dy); long ibegin, iend; for (long i = 1; i <= n; i++) { // Filterfunction: triangular on a linear frequency scale AND a linear amplitude scale. double f = zmin + (i - 1) * df; double z = scaleFrequency (f, toFreqScale, FilterBank_HERTZ); if (z == NUMundefined) { a[i] = NUMundefined; } else { a[i] = NUMtriangularfilter_amplitude (fl_hz, fc_hz, fh_hz, z); if (dbScale) { a[i] = to_dB (a[i], 10, ymin); } } } setDrawingLimits (a.peek(), n, ymin, ymax, &ibegin, &iend); if (ibegin <= iend) { double fmin = zmin + (ibegin - 1) * df; double fmax = zmax - (n - iend) * df; Graphics_function (g, a.peek(), ibegin, iend, fmin, fmax); } } Graphics_unsetInner (g); if (garnish) { double distance = dbScale ? 10 : 1; char32 const *ytext = dbScale ? U"Amplitude (dB)" : U"Amplitude"; Graphics_drawInnerBox (g); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeftEvery (g, 1, distance, 1, 1, 0); Graphics_textLeft (g, 1, ytext); Graphics_textBottom (g, 1, GetFreqScaleText (toFreqScale)); } }
void FilterBank_drawFrequencyScales (I, Graphics g, int horizontalScale, double xmin, double xmax, int verticalScale, double ymin, double ymax, int garnish) { iam (FilterBank); int myFreqScale = FilterBank_getFrequencyScale (me); if (xmin < 0 || xmax < 0 || ymin < 0 || ymax < 0) { Melder_warning (U"Frequencies must be >= 0."); return; } if (xmin >= xmax) { double xmint = my ymin; double xmaxt = my ymax; if (ymin < ymax) { xmint = scaleFrequency (ymin, verticalScale, myFreqScale); xmaxt = scaleFrequency (ymax, verticalScale, myFreqScale); } xmin = scaleFrequency (xmint, myFreqScale, horizontalScale); xmax = scaleFrequency (xmaxt, myFreqScale, horizontalScale); } if (ymin >= ymax) { ymin = scaleFrequency (xmin, horizontalScale, verticalScale); ymax = scaleFrequency (xmax, horizontalScale, verticalScale); } long n = 2000; autoNUMvector<double> a (1, n); Graphics_setInner (g); Graphics_setWindow (g, xmin, xmax, ymin, ymax); double df = (xmax - xmin) / (n - 1); for (long i = 1; i <= n; i++) { double f = xmin + (i - 1) * df; a[i] = scaleFrequency (f, horizontalScale, verticalScale); } long ibegin, iend; setDrawingLimits (a.peek(), n, ymin, ymax, & ibegin, & iend); if (ibegin <= iend) { double fmin = xmin + (ibegin - 1) * df; double fmax = xmax - (n - iend) * df; Graphics_function (g, a.peek(), ibegin, iend, fmin, fmax); } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_marksLeft (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, GetFreqScaleText (verticalScale)); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_textBottom (g, 1, GetFreqScaleText (horizontalScale)); } }
void PowerCepstrogram_paint (PowerCepstrogram me, Graphics g, double tmin, double tmax, double qmin, double qmax, double dBmaximum, int autoscaling, double dynamicRangedB, double dynamicCompression, int garnish) { if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; } if (qmax <= qmin) { qmin = my ymin; qmax = my ymax; } long itmin, itmax, ifmin, ifmax; if (! Matrix_getWindowSamplesX (me, tmin - 0.49999 * my dx, tmax + 0.49999 * my dx, & itmin, & itmax) || ! Matrix_getWindowSamplesY (me, qmin - 0.49999 * my dy, qmax + 0.49999 * my dy, & ifmin, & ifmax)) { return; } autoMatrix thee = Data_copy (me); double min = 1e308, max = -min; for (long i = 1; i <= my ny; i++) { for (long j = 1; j <= my nx; j++) { double val = TO10LOG (my z[i][j]); min = val < min ? val : min; max = val > max ? val : max; thy z[i][j] = val; } } double dBminimum = dBmaximum - dynamicRangedB; if (autoscaling) { dBminimum = min; dBmaximum = max; } for (long j = 1; j <= my nx; j++) { double lmax = thy z[1][j]; for (long i = 2; i <= my ny; i++) { if (thy z[i][j] > lmax) { lmax = thy z[i][j]; } } double factor = dynamicCompression * (max - lmax); for (long i = 1; i <= my ny; i++) { thy z[i][j] += factor; } } Graphics_setInner (g); Graphics_setWindow (g, tmin, tmax, qmin, qmax); Graphics_image (g, thy z, itmin, itmax, Matrix_columnToX (thee.get(), itmin - 0.5), Matrix_columnToX (thee.get(), itmax + 0.5), ifmin, ifmax, Matrix_rowToY (thee.get(), ifmin - 0.5), Matrix_rowToY (thee.get(), ifmax + 0.5), dBminimum, dBmaximum); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, true, U"Time (s)"); Graphics_marksBottom (g, 2, true, true, false); Graphics_marksLeft (g, 2, true, true, false); Graphics_textLeft (g, true, U"Quefrency (s)"); } }
void Ltas_draw (Ltas me, Graphics g, double fmin, double fmax, double minimum, double maximum, int garnish, const wchar *method) { Vector_draw (me, g, & fmin, & fmax, & minimum, & maximum, 1.0, method); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, L"Frequency (Hz)"); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, L"Sound pressure level (dB/Hz)"); Graphics_marksLeft (g, 2, 1, 1, 0); } }
void BarkFilter_drawSekeyHansonFilterFunctions (BarkFilter me, Graphics g, int toFreqScale, int fromFilter, int toFilter, double zmin, double zmax, int dbScale, double ymin, double ymax, int garnish) { if (! checkLimits (me, FilterBank_BARK, toFreqScale, & fromFilter, & toFilter, & zmin, & zmax, dbScale, & ymin, & ymax)) { return; } long n = 1000; autoNUMvector<double> a (1, n); Graphics_setInner (g); Graphics_setWindow (g, zmin, zmax, ymin, ymax); for (long j = fromFilter; j <= toFilter; j++) { double df = (zmax - zmin) / (n - 1); double zMid = Matrix_rowToY (me, j); long ibegin, iend; for (long i = 1; i <= n; i++) { double f = zmin + (i - 1) * df; double z = scaleFrequency (f, toFreqScale, FilterBank_BARK); if (z == NUMundefined) { a[i] = NUMundefined; } else { z -= zMid + 0.215; a[i] = 7 - 7.5 * z - 17.5 * sqrt (0.196 + z * z); if (! dbScale) { a[i] = pow (10, a[i]); } } } setDrawingLimits (a.peek(), n, ymin, ymax, &ibegin, &iend); if (ibegin <= iend) { double fmin = zmin + (ibegin - 1) * df; double fmax = zmax - (n - iend) * df; Graphics_function (g, a.peek(), ibegin, iend, fmin, fmax); } } Graphics_unsetInner (g); if (garnish) { double distance = dbScale ? 10 : 1; const char32 *ytext = dbScale ? U"Amplitude (dB)" : U"Amplitude"; Graphics_drawInnerBox (g); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeftEvery (g, 1, distance, 1, 1, 0); Graphics_textLeft (g, 1, ytext); Graphics_textBottom (g, 1, GetFreqScaleText (toFreqScale)); } }
void LogisticRegression_drawBoundary (LogisticRegression me, Graphics graphics, long colx, double xleft, double xright, long coly, double ybottom, double ytop, bool garnish) { RegressionParameter parmx = static_cast<RegressionParameter> (my parameters -> item [colx]); RegressionParameter parmy = static_cast<RegressionParameter> (my parameters -> item [coly]); if (xleft == xright) { xleft = parmx -> minimum; xright = parmx -> maximum; } if (ybottom == ytop) { ybottom = parmy -> minimum; ytop = parmy -> maximum; } double intercept = my intercept; for (long iparm = 1; iparm <= my parameters -> size; iparm ++) { if (iparm != colx && iparm != coly) { RegressionParameter parm = static_cast<RegressionParameter> (my parameters -> item [iparm]); intercept += parm -> value * (0.5 * (parm -> minimum + parm -> maximum)); } } Graphics_setInner (graphics); Graphics_setWindow (graphics, xleft, xright, ybottom, ytop); double xbottom = (intercept + parmy -> value * ybottom) / - parmx -> value; double xtop = (intercept + parmy -> value * ytop) / - parmx -> value; double yleft = (intercept + parmx -> value * xleft) / - parmy -> value; double yright = (intercept + parmx -> value * xright) / - parmy -> value; double xmin = NUMmin2 (xleft, xright), xmax = NUMmax2 (xleft, xright); double ymin = NUMmin2 (ybottom, ytop), ymax = NUMmax2 (ybottom, ytop); //Melder_casual ("LogisticRegression_drawBoundary: %f %f %f %f %f %f %f %f", // xmin, xmax, xbottom, xtop, ymin, ymax, yleft, yright); if (xbottom >= xmin && xbottom <= xmax) { // line goes through bottom? if (xtop >= xmin && xtop <= xmax) // line goes through top? Graphics_line (graphics, xbottom, ybottom, xtop, ytop); // draw from bottom to top else if (yleft >= ymin && yleft <= ymax) // line goes through left? Graphics_line (graphics, xbottom, ybottom, xleft, yleft); // draw from bottom to left else if (yright >= ymin && yright <= ymax) // line goes through right? Graphics_line (graphics, xbottom, ybottom, xright, yright); // draw from bottom to right } else if (yleft >= ymin && yleft <= ymax) { // line goes through left? if (yright >= ymin && yright <= ymax) // line goes through right? Graphics_line (graphics, xleft, yleft, xright, yright); // draw from left to right else if (xtop >= xmin && xtop <= xmax) // line goes through top? Graphics_line (graphics, xleft, yleft, xtop, ytop); // draw from left to top } else if (xtop >= xmin && xtop <= xmax) { // line goes through top? if (yright >= ymin && yright <= ymax) // line goes through right? Graphics_line (graphics, xtop, ytop, xright, yright); // draw from top to right } Graphics_unsetInner (graphics); if (garnish) { Graphics_drawInnerBox (graphics); Graphics_textBottom (graphics, true, parmx -> label); Graphics_marksBottom (graphics, 2, true, true, false); Graphics_textLeft (graphics, true, parmy -> label); Graphics_marksLeft (graphics, 2, true, true, false); } }
void BandFilterSpectrogram_drawSpectrumAtNearestTimeSlice (BandFilterSpectrogram me, Graphics g, double time, double fmin, double fmax, double dBmin, double dBmax, int garnish) { if (time < my xmin || time > my xmax) { return; } if (fmin == 0 && fmax == 0) { // autoscaling fmin = my ymin; fmax = my ymax; } if (fmax <= fmin) { fmin = my ymin; fmax = my ymax; } long icol = Matrix_xToNearestColumn (me, time); icol = icol < 1 ? 1 : (icol > my nx ? my nx : icol); autoNUMvector<double> spectrum (1, my ny); for (long i = 1; i <= my ny; i++) { spectrum[i] = my v_getValueAtSample (icol, i, 1); // dB's } long iymin, iymax; if (Matrix_getWindowSamplesY (me, fmin, fmax, &iymin, &iymax) < 2) { // too few values return; } if (dBmin == dBmax) { // autoscaling dBmin = spectrum[iymin]; dBmax = dBmin; for (long i = iymin + 1; i <= iymax; i++) { if (spectrum[i] < dBmin) { dBmin = spectrum[i]; } else if (spectrum[i] > dBmax) { dBmax = spectrum[i]; } } if (dBmin == dBmax) { dBmin -= 1; dBmax += 1; } } Graphics_setWindow (g, fmin, fmax, dBmin, dBmax); Graphics_setInner (g); double x1 = my y1 + (iymin -1) * my dy, y1 = spectrum[iymin]; for (long i = iymin + 1; i <= iymax - 1; i++) { double x2 = my y1 + (i -1) * my dy, y2 = spectrum[i]; double xo1, yo1, xo2, yo2; if (NUMclipLineWithinRectangle (x1, y1, x2, y2, fmin, dBmin, fmax, dBmax, &xo1, &yo1, &xo2, &yo2)) { Graphics_line (g, xo1, yo1, xo2, yo2); } x1 = x2; y1 = y2; } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeft (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, U"Power (dB)"); Graphics_textBottom (g, 1, Melder_cat (U"Frequency (", my v_getFrequencyUnit (), U")")); } }
void Spectrum_draw (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum, int garnish) { Graphics_setInner (g); Spectrum_drawInside (me, g, fmin, fmax, minimum, maximum); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, L"Frequency (Hz)"); Graphics_marksBottom (g, 2, true, true, false); Graphics_textLeft (g, 1, L"Sound pressure level (dB/Hz)"); Graphics_marksLeftEvery (g, 1.0, 20.0, true, true, false); } }
void CC_paint (CC me, Graphics g, double xmin, double xmax, long cmin, long cmax, double minimum, double maximum, int garnish) { autoMatrix thee = CC_to_Matrix (me); Matrix_paintCells (thee.get(), g, xmin, xmax, cmin, cmax, minimum, maximum); if (garnish) { Graphics_marksBottom (g, 2, true, true, false); Graphics_textBottom (g, true, U"Time (s)"); Graphics_marksLeft (g, 2, true, true, false); Graphics_textLeft (g, true, U"Coefficients"); } }
void FFNet_drawCostHistory (FFNet me, Graphics g, long iFrom, long iTo, double costMin, double costMax, int garnish) { if (my minimizer) { Minimizer_drawHistory (my minimizer.peek(), g, iFrom, iTo, costMin, costMax, 0); } if (garnish) { Graphics_drawInnerBox (g); Graphics_textLeft (g, true, my costFunctionType == FFNet_COST_MSE ? U"Minimum squared error" : U"Minimum cross entropy"); Graphics_marksLeft (g, 2, true, true, false); Graphics_textBottom (g, true, U"Number of epochs"); Graphics_marksBottom (g, 2, true, true, false); } }
void Formant_drawSpeckles (Formant me, Graphics g, double tmin, double tmax, double fmax, double suppress_dB, int garnish) { Graphics_setInner (g); Formant_drawSpeckles_inside (me, g, tmin, tmax, 0.0, fmax, suppress_dB); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, U"Time (s)"); Graphics_textLeft (g, 1, U"Formant frequency (Hz)"); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeftEvery (g, 1.0, 1000.0, 1, 1, 1); } }
/* This routine is deprecated since praat-4.2.4 20040422 and will be removed in the future. */ void FFNet_drawWeightsToLayer (FFNet me, Graphics g, int layer, int scaling, int garnish) { if (layer < 1 || layer > my nLayers) { Melder_throw (U"Layer must be in [1,", my nLayers, U"]."); } autoMatrix weights = FFNet_weightsToMatrix (me, layer, 0); Matrix_scale (weights.peek(), scaling); Matrix_drawAsSquares (weights.peek(), g, 0.0, 0.0, 0.0, 0.0, 0); if (garnish) { double x1WC, x2WC, y1WC, y2WC; Graphics_inqWindow (g, & x1WC, & x2WC, & y1WC, & y2WC); Graphics_textBottom (g, false, Melder_cat (U"Units in layer ", layer, U" ->")); if (layer == 1) { Graphics_textLeft (g, false, U"Input units ->"); } else { Graphics_textLeft (g, false, Melder_cat (U"Units in layer ", layer - 1, U" ->")); } /* how do I find out the current settings ??? */ Graphics_setTextAlignment (g, Graphics_RIGHT, Graphics_HALF); Graphics_setInner (g); Graphics_text (g, 0.5, weights->ny, U"bias"); Graphics_unsetInner (g); } }
void CC_paint (I, Graphics g, double xmin, double xmax, long cmin, long cmax, double minimum, double maximum, int garnish) { iam (CC); autoMatrix thee = CC_to_Matrix (me); Matrix_paintCells (thee.peek(), g, xmin, xmax, cmin, cmax, minimum, maximum); if (garnish) { Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_textBottom (g, 1, L"Time (s)"); Graphics_marksLeft (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, L"Coefficients"); } }
void Intensity_draw (Intensity me, Graphics g, double tmin, double tmax, double minimum, double maximum, int garnish) { Graphics_setInner (g); Intensity_drawInside (me, g, tmin, tmax, minimum, maximum); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, L"Time (s)"); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeft (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, L"Intensity (dB)"); } }
void Pitch_draw (Pitch me, Graphics g, double tmin, double tmax, double fmin, double fmax, bool garnish, bool speckle, int unit) { Graphics_setInner (g); Pitch_drawInside (me, g, tmin, tmax, fmin, fmax, speckle, unit); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, true, U"Time (s)"); Graphics_marksBottom (g, 2, true, true, false); Graphics_textLeft (g, true, Melder_cat (U"Pitch (", Function_getUnitText (me, Pitch_LEVEL_FREQUENCY, unit, Function_UNIT_TEXT_GRAPHICAL), U")")); if (Function_isUnitLogarithmic (me, Pitch_LEVEL_FREQUENCY, unit)) { Graphics_marksLeftLogarithmic (g, 6, true, true, false); } else { Graphics_marksLeft (g, 2, true, true, false); } } }
void Spectrogram_paint (Spectrogram me, Graphics g, double tmin, double tmax, double fmin, double fmax, double maximum, int autoscaling, double dynamic, double preemphasis, double dynamicCompression, int garnish) { Graphics_setInner (g); Spectrogram_paintInside (me, g, tmin, tmax, fmin, fmax, maximum, autoscaling, dynamic, preemphasis, dynamicCompression); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, U"Time (s)"); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeft (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, U"Frequency (Hz)"); } }
void Cepstrum_draw (Cepstrum me, Graphics g, double qmin, double qmax, double minimum, double maximum, int garnish) { int autoscaling = minimum >= maximum; Graphics_setInner (g); if (qmax <= qmin) { qmin = my xmin; qmax = my xmax; } long imin, imax; if (! Matrix_getWindowSamplesX (me, qmin, qmax, & imin, & imax)) { return; } autoNUMvector<double> y (imin, imax); double *z = my z[1]; for (long i = imin; i <= imax; i++) { y[i] = z[i]; } if (autoscaling) { NUMvector_extrema (y.peek(), imin, imax, & minimum, & maximum); } for (long i = imin; i <= imax; i ++) { if (y[i] > maximum) { y[i] = maximum; } else if (y[i] < minimum) { y[i] = minimum; } } Graphics_setWindow (g, qmin, qmax, minimum, maximum); Graphics_function (g, y.peek(), imin, imax, Matrix_columnToX (me, imin), Matrix_columnToX (me, imax)); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, L"Quefrency"); Graphics_marksBottom (g, 2, TRUE, TRUE, FALSE); Graphics_textLeft (g, 1, L"Amplitude"); } }
void LineSpectralFrequencies_drawFrequencies (LineSpectralFrequencies me, Graphics g, double tmin, double tmax, double fmin, double fmax, bool garnish) { if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; } long itmin, itmax; if (! Sampled_getWindowSamples (me, tmin, tmax, & itmin, & itmax)) { return; } if (fmax <= fmin) { double f1max, f2min; autoNUMvector<double> f1 (itmin, itmax), f2 (itmin, itmax); for (long iframe = itmin; iframe <= itmax; iframe++) { f1[iframe] = my d_frames[iframe].frequencies[1]; f2[iframe] = my d_frames[iframe].frequencies[my d_frames[iframe].numberOfFrequencies]; } NUMvector_extrema (f1.peek(), itmin, itmax, & fmin, & f1max); NUMvector_extrema (f2.peek(), itmin, itmax, & f2min, & fmax); } if (fmax == fmin) { fmin = 0; fmax += 0.5; } Graphics_setInner (g); Graphics_setWindow (g, tmin, tmax, fmin, fmax); for (long iframe = itmin; iframe <= itmax; iframe++) { LineSpectralFrequencies_Frame lsf = & my d_frames[iframe]; double x = Sampled_indexToX (me, iframe); for (long ifreq = 1; ifreq <= lsf -> numberOfFrequencies; ifreq++) { double y = lsf -> frequencies [ifreq]; if (y >= fmin && y <= fmax) { Graphics_speckle (g, x, y); } } } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, true, U"Time (seconds)"); Graphics_textLeft (g, true, U"Frequency (Hz)"); Graphics_marksBottom (g, 2, true, true, false); Graphics_marksLeft (g, 2, true, true, false); } }
void SPINET_spectralRepresentation (SPINET me, Graphics g, double fromTime, double toTime, double fromErb, double toErb, double minimum, double maximum, int enhanced, int garnish) { double **z = enhanced ? my s : my y; autoMatrix thee = Matrix_create (my xmin, my xmax, my nx, my dx, my x1, my ymin, my ymax, my ny, my dy, my y1); for (long j = 1; j <= my ny; j++) { for (long i = 1; i <= my nx; i++) { thy z[j][i] = z[j][i]; } } Matrix_paintCells (thee.peek(), g, fromTime, toTime, fromErb, toErb, minimum, maximum); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, true, U"Time (s)"); Graphics_marksBottom (g, 2, true, true, false); Graphics_textLeft (g, true, U"Frequency (ERB)"); Graphics_marksLeft (g, 2, true, true, false); Graphics_textTop (g, false, enhanced ? U"Cooperative interaction output" : U"Gammatone filterbank output"); } }
// xmin, xmax in hz versus bark/mel or lin void BandFilterSpectrogram_drawFrequencyScale (BandFilterSpectrogram me, Graphics g, double xmin, double xmax, double ymin, double ymax, int garnish) { if (xmin < 0 || xmax < 0 || ymin < 0 || ymax < 0) { Melder_warning (U"Frequencies must be >= 0."); return; } // scale is in hertz if (xmin >= xmax) { // autoscaling xmin = 0; xmax = my v_frequencyToHertz (my ymax); } if (ymin >= ymax) { // autoscaling ymin = my ymin; ymax = my ymax; } long n = 2000; Graphics_setInner (g); Graphics_setWindow (g, xmin, xmax, ymin, ymax); double dx = (xmax - xmin) / (n - 1); double x1 = xmin, y1 = my v_hertzToFrequency (x1); for (long i = 2; i <= n; i++) { double x2 = x1 + dx, y2 = my v_hertzToFrequency (x2); if (NUMdefined (y1) && NUMdefined (y2)) { double xo1, yo1, xo2, yo2; if (NUMclipLineWithinRectangle (x1, y1, x2, y2, xmin, ymin, xmax, ymax, &xo1, &yo1, &xo2, &yo2)) { Graphics_line (g, xo1, yo1, xo2, yo2); } } x1 = x2; y1 = y2; } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_marksLeft (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, Melder_cat (U"Frequency (", my v_getFrequencyUnit (), U")")); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_textBottom (g, 1, U"Frequency (Hz)"); } }
void Discriminant_drawConcentrationEllipses (Discriminant me, Graphics g, double scale, bool confidence, char32 *label, int discriminantDirections, long d1, long d2, double xmin, double xmax, double ymin, double ymax, int fontSize, int garnish) { long numberOfFunctions = Discriminant_getNumberOfFunctions (me); if (! discriminantDirections) { SSCPList_drawConcentrationEllipses (my groups.get(), g, scale, confidence, label, d1, d2, xmin, xmax, ymin, ymax, fontSize, garnish); return; } if (numberOfFunctions <= 1) { Melder_warning (U"Discriminant_drawConcentrationEllipses: Nothing drawn " U"because there is only one dimension in the discriminant space."); return; } // Project SSCPs on eigenvectors. if (d1 == 0 && d2 == 0) { d1 = 1; d2 = MIN (numberOfFunctions, d1 + 1); } else if (d1 < 0 || d2 > numberOfFunctions) { return; } double *v1 = my eigen -> eigenvectors [d1]; double *v2 = my eigen -> eigenvectors [d2]; autoSSCPList thee = SSCPList_toTwoDimensions (my groups.get(), v1, v2); SSCPList_drawConcentrationEllipses (thee.get(), g, scale, confidence, label, 1, 2, xmin, xmax, ymin, ymax, fontSize, 0); if (garnish) { char32 llabel[40]; Graphics_drawInnerBox (g); Graphics_marksLeft (g, 2, true, true, false); Melder_sprint (llabel,40, U"function ", d2); Graphics_textLeft (g, true, llabel); Graphics_marksBottom (g, 2, true, true, false); Melder_sprint (llabel,40, U"function ", d1); Graphics_textBottom (g, true, llabel); } }
void PitchTier_Pitch_draw (PitchTier me, Pitch uv, Graphics g, double tmin, double tmax, double fmin, double fmax, int nonPeriodicLineType, int garnish, const char32 *method) { long n = my points.size, imin, imax, i; if (nonPeriodicLineType == 0) { PitchTier_draw (me, g, tmin, tmax, fmin, fmax, garnish, method); return; } if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; } Graphics_setWindow (g, tmin, tmax, fmin, fmax); Graphics_setInner (g); imin = AnyTier_timeToHighIndex (me->asAnyTier(), tmin); imax = AnyTier_timeToLowIndex (me->asAnyTier(), tmax); if (n == 0) { } else if (imax < imin) { double fleft = RealTier_getValueAtTime (me, tmin); double fright = RealTier_getValueAtTime (me, tmax); Pitch_line (uv, g, tmin, fleft, tmax, fright, nonPeriodicLineType); } else for (i = imin; i <= imax; i ++) { RealPoint point = my points.at [i]; double t = point -> number, f = point -> value; Graphics_speckle (g, t, f); if (i == 1) Pitch_line (uv, g, tmin, f, t, f, nonPeriodicLineType); else if (i == imin) Pitch_line (uv, g, t, f, tmin, RealTier_getValueAtTime (me, tmin), nonPeriodicLineType); if (i == n) Pitch_line (uv, g, t, f, tmax, f, nonPeriodicLineType); else if (i == imax) Pitch_line (uv, g, t, f, tmax, RealTier_getValueAtTime (me, tmax), nonPeriodicLineType); else { RealPoint pointRight = my points.at [i + 1]; Pitch_line (uv, g, t, f, pointRight -> number, pointRight -> value, nonPeriodicLineType); } } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, true, U"Time (s)"); Graphics_marksBottom (g, 2, true, true, false); Graphics_marksLeft (g, 2, true, true, false); Graphics_textLeft (g, true, U"Frequency (Hz)"); } }
void RealTier_draw (RealTier me, Graphics g, double tmin, double tmax, double fmin, double fmax, int garnish, const char32 *method, const char32 *quantity) { bool drawLines = str32str (method, U"lines") || str32str (method, U"Lines"); bool drawSpeckles = str32str (method, U"speckles") || str32str (method, U"Speckles"); long n = my points.size, imin, imax, i; if (tmax <= tmin) { tmin = my xmin; tmax = my xmax; } Graphics_setWindow (g, tmin, tmax, fmin, fmax); Graphics_setInner (g); imin = AnyTier_timeToHighIndex (me->asAnyTier(), tmin); imax = AnyTier_timeToLowIndex (me->asAnyTier(), tmax); if (n == 0) { } else if (imax < imin) { double fleft = RealTier_getValueAtTime (me, tmin); double fright = RealTier_getValueAtTime (me, tmax); if (drawLines) Graphics_line (g, tmin, fleft, tmax, fright); } else for (i = imin; i <= imax; i ++) { RealPoint point = my points.at [i]; double t = point -> number, f = point -> value; if (drawSpeckles) Graphics_speckle (g, t, f); if (drawLines) { if (i == 1) Graphics_line (g, tmin, f, t, f); else if (i == imin) Graphics_line (g, t, f, tmin, RealTier_getValueAtTime (me, tmin)); if (i == n) Graphics_line (g, t, f, tmax, f); else if (i == imax) Graphics_line (g, t, f, tmax, RealTier_getValueAtTime (me, tmax)); else { RealPoint pointRight = my points.at [i + 1]; Graphics_line (g, t, f, pointRight -> number, pointRight -> value); } } } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, true, my v_getUnitText (0, 0, 0)); Graphics_marksBottom (g, 2, true, true, false); Graphics_marksLeft (g, 2, true, true, false); if (quantity) Graphics_textLeft (g, true, quantity); } }
void TextGrid_Pitch_drawSeparately (TextGrid grid, Pitch pitch, Graphics g, double tmin, double tmax, double fmin, double fmax, int showBoundaries, int useTextStyles, int garnish, int speckle, int unit) { int ntier = grid -> tiers -> size; if (tmax <= tmin) tmin = grid -> xmin, tmax = grid -> xmax; if (Function_isUnitLogarithmic (pitch, Pitch_LEVEL_FREQUENCY, unit)) { fmin = Function_convertStandardToSpecialUnit (pitch, fmin, Pitch_LEVEL_FREQUENCY, unit); fmax = Function_convertStandardToSpecialUnit (pitch, fmax, Pitch_LEVEL_FREQUENCY, unit); } if (unit == kPitch_unit_HERTZ_LOGARITHMIC) Pitch_draw (pitch, g, tmin, tmax, pow (10, fmin - 0.25 * (fmax - fmin) * ntier), pow (10, fmax), FALSE, speckle, unit); else Pitch_draw (pitch, g, tmin, tmax, fmin - 0.25 * (fmax - fmin) * ntier, fmax, FALSE, speckle, unit); TextGrid_Sound_draw (grid, NULL, g, tmin, tmax, showBoundaries, useTextStyles, FALSE); /* * Restore window for the sake of margin drawing. */ Graphics_setWindow (g, tmin, tmax, fmin - 0.25 * (fmax - fmin) * ntier, fmax); if (unit == kPitch_unit_HERTZ_LOGARITHMIC) fmin = pow (10, fmin), fmax = pow (10, fmax); if (garnish) { Graphics_drawInnerBox (g); if (unit == kPitch_unit_HERTZ_LOGARITHMIC) { Graphics_markLeftLogarithmic (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeftLogarithmic (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks_logarithmic (g, fmin, fmax, FALSE); } else if (unit == kPitch_unit_SEMITONES_100) { Graphics_markLeft (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeft (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks_semitones (g, fmin, fmax, FALSE); } else { Graphics_markLeft (g, fmin, TRUE, TRUE, FALSE, NULL); Graphics_markLeft (g, fmax, TRUE, TRUE, FALSE, NULL); autoMarks (g, fmin, fmax, FALSE); } static MelderString buffer = { 0 }; MelderString_empty (& buffer); MelderString_append (& buffer, L"Pitch (", Function_getUnitText (pitch, Pitch_LEVEL_FREQUENCY, unit, Function_UNIT_TEXT_GRAPHICAL), L")"); Graphics_textLeft (g, true, buffer.string); Graphics_textBottom (g, true, L"Time (s)"); Graphics_marksBottom (g, 2, true, true, true); } }
void SPINET_drawSpectrum (SPINET me, Graphics g, double time, double fromErb, double toErb, double minimum, double maximum, int enhanced, int garnish) { long ifmin, ifmax, icol = Sampled2_xToLowColumn (me, time); // ppgb: don't use Sampled2_xToColumn for integer rounding double **z = enhanced ? my s : my y; if (icol < 1 || icol > my nx) { return; } if (toErb <= fromErb) { fromErb = my ymin; toErb = my ymax; } Sampled2_getWindowSamplesY (me, fromErb, toErb, &ifmin, &ifmax); autoNUMvector<double> spec (1, my ny); for (long i = 1; i <= my ny; i++) { spec[i] = z[i][icol]; } if (maximum <= minimum) { NUMvector_extrema (spec.peek(), ifmin, ifmax, &minimum, &maximum); } if (maximum <= minimum) { minimum -= 1; maximum += 1; } for (long i = ifmin; i <= ifmax; i++) { if (spec[i] > maximum) { spec[i] = maximum; } else if (spec[i] < minimum) { spec[i] = minimum; } } Graphics_setInner (g); Graphics_setWindow (g, fromErb, toErb, minimum, maximum); Graphics_function (g, spec.peek(), ifmin, ifmax, Sampled2_rowToY (me, ifmin), Sampled2_rowToY (me, ifmax)); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, U"Frequency (ERB)"); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_textLeft (g, 1, U"strength"); Graphics_marksLeft (g, 2, 1, 1, 0); } }