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 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 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 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 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); } }
void Spectrum_drawLogFreq (Spectrum me, Graphics g, double fmin, double fmax, double minimum, double maximum, int garnish) { int autoscaling = minimum >= maximum; if (fmax <= fmin) { fmin = my xmin; fmax = my xmax; } long ifmin, ifmax; if (! Matrix_getWindowSamplesX (me, fmin, fmax, & ifmin, & ifmax)) return; if(ifmin==1)ifmin=2; /* BUG */ autoNUMvector <double> xWC (ifmin, ifmax); autoNUMvector <double> yWC (ifmin, ifmax); /* * First pass: compute power density. */ if (autoscaling) maximum = -1e6; for (long ifreq = ifmin; ifreq <= ifmax; ifreq ++) { xWC [ifreq] = log10 (my x1 + (ifreq - 1) * my dx); yWC [ifreq] = my v_getValueAtSample (ifreq, 0, 2); if (autoscaling && yWC [ifreq] > maximum) maximum = yWC [ifreq]; } if (autoscaling) minimum = maximum - 60; /* Default dynamic range is 60 dB. */ /* * Second pass: clip. */ for (long ifreq = ifmin; ifreq <= ifmax; ifreq ++) { if (yWC [ifreq] < minimum) yWC [ifreq] = minimum; else if (yWC [ifreq] > maximum) yWC [ifreq] = maximum; } Graphics_setInner (g); Graphics_setWindow (g, log10 (fmin), log10 (fmax), minimum, maximum); Graphics_polyline (g, ifmax - ifmin + 1, & xWC [ifmin], & yWC [ifmin]); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, L"Frequency (Hz)"); Graphics_marksBottomLogarithmic (g, 3, TRUE, TRUE, FALSE); Graphics_textLeft (g, 1, L"Sound pressure level (dB/Hz)"); Graphics_marksLeftEvery (g, 1.0, 20.0, TRUE, TRUE, FALSE); } }
void Excitation_draw (Excitation me, Graphics g, double fmin, double fmax, double minimum, double maximum, int garnish) { if (fmax <= fmin) { fmin = my xmin; fmax = my xmax; } long ifmin, ifmax; Matrix_getWindowSamplesX (me, fmin, fmax, & ifmin, & ifmax); if (maximum <= minimum) Matrix_getWindowExtrema (me, ifmin, ifmax, 1, 1, & minimum, & maximum); if (maximum <= minimum) { minimum -= 20; maximum += 20; } Graphics_setInner (g); Graphics_setWindow (g, fmin, fmax, minimum, maximum); Graphics_function (g, my z [1], ifmin, ifmax, Matrix_columnToX (me, ifmin), Matrix_columnToX (me, ifmax)); Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_textBottom (g, 1, L"Frequency (Bark)"); Graphics_textLeft (g, 1, L"Excitation (phon)"); Graphics_marksBottomEvery (g, 1, 5, 1, 1, 0); Graphics_marksLeftEvery (g, 1, 20, 1, 1, 0); } }
void MelSpectrogram_drawTriangularFilterFunctions (MelSpectrogram me, Graphics g, bool xIsHertz, int fromFilter, int toFilter, double zmin, double zmax, bool yscale_dB, double ymin, double ymax, int garnish) { double xmin = zmin, xmax = zmax; if (zmin >= zmax) { zmin = my ymin; zmax = my ymax; // mel xmin = xIsHertz ? my v_frequencyToHertz (zmin) : zmin; xmax = xIsHertz ? my v_frequencyToHertz (zmax) : zmax; } if (xIsHertz) { zmin = my v_hertzToFrequency (xmin); zmax = my v_hertzToFrequency (xmax); } if (ymin >= ymax) { ymin = yscale_dB ? -60 : 0; ymax = yscale_dB ? 0 : 1; } fromFilter = fromFilter <= 0 ? 1 : fromFilter; toFilter = toFilter <= 0 || toFilter > my ny ? my ny : toFilter; if (fromFilter > toFilter) { fromFilter = 1; toFilter = my ny; } long n = xIsHertz ? 1000 : 500; autoNUMvector<double> xz (1, n), xhz (1,n), y (1, n); Graphics_setInner (g); Graphics_setWindow (g, xmin, xmax, ymin, ymax); double dz = (zmax - zmin) / (n - 1); for (long iz = 1; iz <= n; iz++) { double f = zmin + (iz - 1) * dz; xz[iz] = f; xhz[iz] = my v_frequencyToHertz (f); // just in case we need the linear scale } for (long ifilter = fromFilter; ifilter <= toFilter; ifilter++) { double zc = Matrix_rowToY (me, ifilter), zl = zc - my dy, zh = zc + my dy; double xo1, yo1, xo2, yo2; if (yscale_dB) { for (long iz = 1; iz <= n; iz++) { double z = xz[iz]; double amp = NUMtriangularfilter_amplitude (zl, zc, zh, z); y[iz] = yscale_dB ? (amp > 0 ? 20 * log10 (amp) : ymin - 10) : amp; } double x1 = xIsHertz ? xhz[1] : xz[1], y1 = y[1]; if (NUMdefined (y1)) { for (long iz = 1; iz <= n; iz++) { double x2 = xIsHertz ? xhz[iz] : xz[iz], y2 = y[iz]; if (NUMdefined (y2)) { 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; } } } else { double x1 = xIsHertz ? my v_frequencyToHertz (zl) : zl; double x2 = xIsHertz ? my v_frequencyToHertz (zc) : zc; if (NUMclipLineWithinRectangle (x1, 0, x2, 1, xmin, ymin, xmax, ymax, &xo1, &yo1, &xo2, &yo2)) { Graphics_line (g, xo1, yo1, xo2, yo2); } double x3 = xIsHertz ? my v_frequencyToHertz (zh) : zh; if (NUMclipLineWithinRectangle (x2, 1, x3, 0, xmin, ymin, xmax, ymax, &xo1, &yo1, &xo2, &yo2)) { Graphics_line (g, xo1, yo1, xo2, yo2); } } } Graphics_unsetInner (g); if (garnish) { Graphics_drawInnerBox (g); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeftEvery (g, 1, yscale_dB ? 10 : 0.5, 1, 1, 0); Graphics_textLeft (g, 1, yscale_dB ? U"Amplitude (dB)" : U"Amplitude"); Graphics_textBottom (g, 1, Melder_cat (U"Frequency (", ( xIsHertz ? U"Hz" : my v_getFrequencyUnit () ), U")")); } }
void BarkSpectrogram_drawSekeyHansonFilterFunctions (BarkSpectrogram me, Graphics g, bool xIsHertz, int fromFilter, int toFilter, double zmin, double zmax, bool yscale_dB, double ymin, double ymax, int garnish) { double xmin = zmin, xmax = zmax; if (zmin >= zmax) { zmin = my ymin; zmax = my ymax; xmin = xIsHertz ? my v_frequencyToHertz (zmin) : zmin; xmax = xIsHertz ? my v_frequencyToHertz (zmax) : zmax; } if (xIsHertz) { zmin = my v_hertzToFrequency (xmin); zmax = my v_hertzToFrequency (xmax); } if (ymin >= ymax) { ymin = yscale_dB ? -60 : 0; ymax = yscale_dB ? 0 : 1; } fromFilter = fromFilter <= 0 ? 1 : fromFilter; toFilter = toFilter <= 0 || toFilter > my ny ? my ny : toFilter; if (fromFilter > toFilter) { fromFilter = 1; toFilter = my ny; } long n = xIsHertz ? 1000 : 500; autoNUMvector<double> xz (1, n), xhz (1,n), y (1, n); Graphics_setInner (g); Graphics_setWindow (g, xmin, xmax, ymin, ymax); double dz = (zmax - zmin) / (n - 1); for (long iz = 1; iz <= n; iz++) { double f = zmin + (iz - 1) * dz; xz[iz] = f; xhz[iz] = my v_frequencyToHertz (f); // just in case we need the linear scale } for (long ifilter = fromFilter; ifilter <= toFilter; ifilter++) { double zMid = Matrix_rowToY (me, ifilter); for (long iz = 1; iz <= n; iz++) { double z = xz[iz] - (zMid - 0.215); double amp = 7 - 7.5 * z - 17.5 * sqrt (0.196 + z * z); y[iz] = yscale_dB ? amp : pow (10, amp / 10); } // the drawing double x1 = xIsHertz ? xhz[1] : xz[1], y1 = y[1]; for (long iz = 2; iz <= n; iz++) { double x2 = xIsHertz ? xhz[iz] : xz[iz], y2 = y[iz]; if (NUMdefined (x1) && NUMdefined (x2)) { 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) { double distance = yscale_dB ? 10 : 0.5; Graphics_drawInnerBox (g); Graphics_marksBottom (g, 2, 1, 1, 0); Graphics_marksLeftEvery (g, 1, distance, 1, 1, 0); Graphics_textLeft (g, 1, yscale_dB ? U"Amplitude (dB)" : U"Amplitude"); Graphics_textBottom (g, 1, Melder_cat (U"Frequency (", xIsHertz ? U"Hz" : my v_getFrequencyUnit (), U")")); } }