plotspec.c
来自「speech signal process tools」· C语言 代码 · 共 826 行 · 第 1/2 页
C
826 行
freqmax = dfreqs[num_freqs] = -freqmin; for (j = 1; j < num_freqs; j++) dfreqs[j] = freqmin + j * delta_h; } else { freqmin = -0.5 * sf + 0.5 * delta_h; freqmax = -freqmin; } for (j = 0; j < num_freqs; j++) freqs[j] = -0.5 * sf + (j + 0.5) * delta_h; break; case SPFMT_ASYM_EDGE: delta_h = sf / (num_freqs - 1); if (dflag) { freqmin = dfreqs[0] = -0.5 * sf; freqmax = dfreqs[num_freqs] = -freqmin; for (j = 1; j < num_freqs; j++) dfreqs[j] = freqmin + (j - 0.5) * delta_h; } else { freqmin = -0.5 * sf; freqmax = -freqmin; } for (j = 0; j < num_freqs; j++) freqs[j] = -0.5 * sf + j * delta_h; break; case SPFMT_ARB_VAR: Fprintf(stderr, "%s: freq format ARB_VAR not yet supported.\n", ProgName); exit(1); break; case SPFMT_ARB_FIXED: Fprintf(stderr, "%s: freq format ARB_FIXED not yet supported.\n", ProgName); exit(1); break; default: Fprintf(stderr, "%s: unrecognized freq format %s.\n", ProgName, genhd_codes("freq_format", ih)[freq_format]); exit(1); break; } if (lflag) { switch (freq_format) { case SPFMT_SYM_CTR: xmin_def = dflag ? delta_h : 0.5*delta_h; break; case SPFMT_SYM_EDGE: xmin_def = dflag ? 0.5*delta_h : delta_h; break; default: xmin_def = ((dflag && num_freqs%2 == 0) || (!dflag && num_freqs%2 == 1)) ? delta_h : 0.5*delta_h; } xmin = xmin_def; xmax = freqmax; frange_switch(xrange, &xmin, &xmax); if (xmin == xmax) xmin = xmin_def; spsassert(xmin > 0.0, "frequency range not positive"); } else { xmin = freqmin; xmax = freqmax; frange_switch(xrange, &xmin, &xmax); if (xmin == xmax) switch (freq_format) { case SPFMT_SYM_CTR: case SPFMT_SYM_EDGE: xmin = 0; break; default: xmin = -xmax; break; } } if (freqmin < xmin || freqmax > xmax) Fprintf(stderr, "frequency out of range.\n"); if (dflag) { for ( start_plot = 0; start_plot <= num_freqs && dfreqs[start_plot] < xmin; start_plot++ ) {} for ( end_plot = num_freqs; end_plot >= 0 && dfreqs[end_plot] > xmax; end_plot-- ) {} } else { for ( start_plot = 0; start_plot < num_freqs && freqs[start_plot] < xmin; start_plot++ ) {} for ( end_plot = num_freqs - 1; end_plot >= 0 && freqs[end_plot] > xmax; end_plot-- ) {} } num_plot = end_plot - start_plot + 1; datamin = FLT_MAX; datamax = -FLT_MAX; fea_skiprec(specfile, firstrec - 1, ih); nrec = 0; while (nplots-- && (get_feaspec_rec(spec_rec, ih, specfile) != EOF)) { for (j = 0; j < num_freqs; j++) { if (Dflag && spec_type != SPTYP_DB) { double pwr; rsv = spec_rec->re_spec_val[j]; switch (spec_type) { case SPTYP_PWR: pwr = rsv; break; case SPTYP_REAL: pwr = rsv * rsv; break; case SPTYP_CPLX: isv = spec_rec->im_spec_val[j]; pwr = rsv*rsv + isv*isv; break; default: Fprintf(stderr, "%s: unknown spectral type\n", ProgName); exit(1); break; } spec_rec->re_spec_val[j] = (pwr != 0.0) ? 10 * log10(pwr) : - 10 * log10(FLT_MAX); } if (xmin <= freqs[j] && freqs[j] <= xmax) { if (datamin > spec_rec->re_spec_val[j]) datamin = spec_rec->re_spec_val[j]; if (datamax < spec_rec->re_spec_val[j]) datamax = spec_rec->re_spec_val[j]; if (spec_type == SPTYP_CPLX && !Dflag) { if (datamin > spec_rec->im_spec_val[j]) datamin = spec_rec->im_spec_val[j]; if (datamax < spec_rec->im_spec_val[j]) datamax = spec_rec->im_spec_val[j]; } } } put_feaspec_rec(spec_rec, temp_hd, tempfile); nrec++; } if (debug_level > 2) Fprintf(stderr, "%s: datamin = %g, datamax = %g\n", ProgName, datamin , datamax); if (nrec == 0) { Fprintf(stderr, "%s: no input records\n", ProgName); exit(1); } rewind(tempfile); temp_hd = read_header(tempfile); if (dflag) { ymin = 0.0; ymax = 1.0; ystep = 0.1; ydp = 1; } else if (Fflag) { ymin = -PI; ymax = PI; ystep = PI/2; ydp = 4; } else { ymin = datamin; ymax = datamax; frange_switch(yrange, &ymin, &ymax); if (datamin < ymin || datamax > ymax) Fprintf(stderr, "data out of range.\n"); if (yexact) plotexscale(ymin, ymax, 1.0, &ymin, &ymax, &ystep, &ydp); else plotscale(ymin, ymax, 1.0, &ymin, &ymax, &ystep, &ydp); } if (debug_level > 2) Fprintf(stderr, "%s: ymin = %g, ymax = %g, ystep = %g, ydp = %d\n", ProgName, ymin, ymax, ystep, ydp); if (lflag) { plotscale(log10(xmin), log10(xmax), 1.0, &xmink, &xmaxk, &xstepk, &xdp); for (j = start_plot; j <= end_plot; j++) if (dflag) dfreqs[j] = log10(dfreqs[j]); else freqs[j] = log10(freqs[j]); } else { plotscale(xmin/kHz, xmax/kHz, 1.0, &xmink, &xmaxk, &xstepk, &xdp); for (j = start_plot; j <= end_plot; j++) if (dflag) dfreqs[j] = dfreqs[j]/kHz; else freqs[j] = freqs[j]/kHz; } if (debug_level > 2) { Fprintf(stderr, "%s: xmin= %g, xmax = %g\n", ProgName, xmin, xmax); Fprintf(stderr, "%s: xmink = %g, xmaxk = %g, xstepk = %g, xdp = %d\n", ProgName, xmink, xmaxk, xstepk, xdp); } if (!sflag) draw_box(xmink, xmaxk, xstepk, xdp, ymin, ymax, ystep, ydp); while (nrec-- && (get_feaspec_rec(spec_rec, temp_hd, tempfile) != EOF)) { if (yflag && !dflag && !Fflag) for (k = 0; k < num_freqs; k++) { if (spec_rec->re_spec_val[k] < ymin) spec_rec->re_spec_val[k] = ymin; if (spec_rec->re_spec_val[k] > ymax) spec_rec->re_spec_val[k] = ymax; if (spec_type == SPTYP_CPLX && !Dflag) { if (spec_rec->im_spec_val[k] < ymin) spec_rec->im_spec_val[k] = ymin; if (spec_rec->im_spec_val[k] > ymax) spec_rec->im_spec_val[k] = ymax; } } if (dflag) { tot_power = *spec_rec->tot_power; R0 = 0.0; dist_func[0] = R0; for (j = 0; j < num_freqs; j++) { rsv = spec_rec->re_spec_val[j]; switch (spec_type) { case SPTYP_PWR: delta_R = rsv; break; case SPTYP_DB: delta_R = pow(10.0, rsv/10.0); break; case SPTYP_REAL: delta_R = rsv * rsv; break; case SPTYP_CPLX: isv = spec_rec->im_spec_val[j]; delta_R = rsv*rsv + isv*isv; break; default: Fprintf(stderr, "%s: unknown spectral type\n", ProgName); exit(1); break; } switch (freq_format) { case SPFMT_SYM_CTR: case SPFMT_ASYM_CTR: delta_R *= delta_h; break; case SPFMT_SYM_EDGE: case SPFMT_ASYM_EDGE: if (j == 0 || j == num_freqs - 1) delta_R *= 0.5 * delta_h; else delta_R *= delta_h; break; case SPFMT_ARB_VAR: case SPFMT_ARB_FIXED: default: exit(1); break; } R0 += delta_R; dist_func[j+1] = R0; } if (debug_level > 2) Fprintf(stderr, "%s: R0 = %g, tot_power = %g, delta_h = %g\n", ProgName, R0, tot_power, delta_h); for (j = 0; j <= num_freqs; j++) { if (tot_power != 0.0) dist_func[j] /= tot_power; else dist_func[j] /= R0; if (debug_level > 4) Fprintf(stderr, "%s: dist_func[%d] = %g\n", ProgName, j, dist_func[j]); } plot2data(dfreqs + start_plot, dist_func + start_plot, num_plot, clr + 2, xmink, xmaxk, 0.0, 1.0); } else if (Fflag) { for (j = 0; j < num_freqs; j++){ if(spec_rec->re_spec_val[j] == 0 && spec_rec->re_spec_val[j] ==0 ) spec_rec->im_spec_val[j] = 0; else spec_rec->im_spec_val[j] = atan2(spec_rec->im_spec_val[j], spec_rec->re_spec_val[j]); } plotphdata(freqs + start_plot, spec_rec->im_spec_val + start_plot, num_plot, clr + 2, xmink, xmaxk, ymin, ymax); } else { plot2data(freqs + start_plot, spec_rec->re_spec_val + start_plot, num_plot, clr + 2, xmink, xmaxk, ymin, ymax); if (spec_type == SPTYP_CPLX && !Dflag) plot2data(freqs + start_plot, spec_rec->im_spec_val + start_plot, num_plot, clr + 2, xmink, xmaxk, ymin, ymax); } if (sflag) { draw_box(xmink, xmaxk, xstepk, xdp, ymin, ymax, ystep, ydp); Printf("c 5\nm 3400 500\nt 5 1\nFile: %s, Record %d\n", specname, firstrec++); iy = 3600; for (j = 0; j < ntext; j++) { Printf("c 5\nm %d 500\nt 5 1\n%s\n", iy, text[j]); iy += 200; } print_time(200, 4400); if (!Eflag) erase(); } } (void) fclose(tempfile); if (!sflag) { if (lflag) Printf("c 5\nm 3400 2760\nt 5 1\nDecades\n"); else Printf("c 5\nm 3400 2920\nt 5 1\nkHz\n"); Printf("c 5\nm 3600 500\nt 5 1\nFile: %s\n", specname); if (!dflag && !Fflag && spec_type == SPTYP_DB || Dflag) Printf("c 5\nm 1600 35\nt 5 1\ndB\n"); iy = 3800; for (i = 0; i < ntext; i++) { Printf("c 5\nm %d 500\nt 5 1\n%s\n", iy, text[i]); iy += 200; } print_time(200, 4400); } exit(0); /*NOTREACHED*/}voiderase(){ Printf("e\n");}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?