📄 fltresp.c
字号:
/* ---------------------------------------------------------------------- FLTRESP.C ~~~~~~~~~ Description: ~~~~~~~~~~~~ Test program to evaluate the frequence response of filters. Depending on the function called, the program will be able to evaluate the frequence response for the range of frequencies specified. The algorithm here is to calculate the long-term energy of a sinewave before and after the filtering, converting the ratio to dB. -------------------------------------------------------------- NOTE! the output dB values are ALWAYS relative to the given sampling frequency, not to the output one, whatever it is !!! -------------------------------------------------------------- Compilation: ~~~~~~~~~~~~ * VMS: $ cc fltresp.C $ link fltresp ! it is necessary to $ fltresp:==$disk:[dir]fltresp.EXE ! define as foreign command * MSDOS: $ tcc fltresp.C * Unix: # cc -o fltresp fltresp.c -lm Usage: ~~~~~~ $ fltresp Flt_type f0 ff fstep [fs] where: flt_type: is the filter type: IRS, DSM, PSO, HQ2, HQ3, PCM, PCM1 f0 is the starting frequency [Hz] ff is the final frequency [Hz] fstep is the step in frequency from f0 to ff [Hz] [fs] is the sampling frequency [Hz]; default is 8000 Hz. (*) may be the regular or the modified IRS! Options: -mod .......... uses the modified IRS characteristic instead of the "regular" one. -fs ........... set the sampling frequency, in Hz [def: 8000] Valid combinations of filter and sampling rate: Flt_type fs Description IRS 8000 (regular) IRS weighting with factor 1:1. 16000 (regular or modified) IRS weighting with factor 1:1. 48000 (modified) IRS weighting with factor 1:1. DSM 16000 Delta-SM filtering characteristic, 1:1 PSO 8000 Psophometric wheighting filter, 1:1 HQ2 8000 High quality with factor 1:2 16000 High quality with factor 2:1 HQ3 8000 High quality with factor 1:3 16000 High quality with factor 3:1 FLAT 8000 Linear-phase pass-band with factor 1:2 16000 Linear-phase pass-band with factor 2:1 PCM 8000 Standard PCM quality factor 1:2 16000 Standard PCM quality factor 2:1 PCM1 8000 unimplemented! 16000 Standard PCM quality with factor 1:1 at 16 kHz Original author: ~~~~~~~~~~~~~~~~ Simao Ferraz de Campos Neto CPqD - Telebras Tel: +55-192-39-6637 Rod. Mogi Mirim - Campinas Km. 118,5 Fax: +55-192-39-2179 13.088-061 - Campinas - SP - Brazil E-mail: simao@cpqd.ansp.br History: ~~~~~~~~ 30.Apr.92 1.0 Release of 1st version <tdsimao@venus.cpqd.ansp.br> 20.May.92 2.0 Corrected bug in calculation of output level; skipping start/stop of filtered sample buffer. <tdsimao@venus.cpqd.ansp.br>* ----------------------------------------------------------------------*/#include <stdio.h>#include <stdlib.h>#include <string.h> /* for memset() */#include <math.h>#if defined(VMS)#include <stat.h>#else /* Unix, DOS, etc */#include <sys/stat.h>#endif/* UGST MODULES */#include "ugstdemo.h"#include "iirflt.h"#include "firflt.h"/* Other stufs */#define TWO_PI (8*atan(1.0))/* * Check if the specified filter is a valid one! * (potentially: does not check consistency of fs and F_type * By: Simao in 30.Apr.92 * Return: 1 -> OK * 0 -> invalid choice! */int valid_filter(F_type) char *F_type;{ if (strncmp(F_type, "irs", 3) == 0 || strncmp(F_type, "IRS", 3) == 0 || strncmp(F_type, "dsm", 3) == 0 || strncmp(F_type, "DSM", 3) == 0 || strncmp(F_type, "pso", 3) == 0 || strncmp(F_type, "PSO", 3) == 0 || strncmp(F_type, "hq", 2) == 0 || strncmp(F_type, "HQ", 2) == 0 || strncmp(F_type, "flat", 4) == 0 || strncmp(F_type, "FLAT",4) == 0 || strncmp(F_type, "pcm", 3) == 0 || strncmp(F_type, "PCM",3) == 0) return 1; else return 0;}/* * Function to display usage * By: Simao in 20.Apr.94 */void display_usage(){ printf("FLTRESP -- Version 3.0 of 20.Apr.94 --\n"); printf("%s%s", "Test program to evaluate the frequence ", "response of filters.\n"); printf("%s%s", "Depending on the function called, the program ", "will be able\n"); printf("to evaluate the frequence response for the range of\n"); printf("%s%s", "frequencies specified. The algorithm here is to ", "calculate the\n"); printf("%s%s", "long-term energy of a sinewave before and ", "after the filtering,\n"); printf("converting the ratio to dB.\n\n"); printf("%s%s", "---------------------------------", "-----------------------------\n"); printf("%s%s", "NOTE! the output dB values are ALWAYS relative ", "to the given\n"); printf("%s%s", "sampling frequency, not to the output one, ", "whichever it is !!!\n"); printf("%s%s", "---------------------------------", "-----------------------------\n\n"); printf("Usage:\n"); printf("~~~~~~\n"); printf("$ fltresp [-options] Flt_type f0 ff fstep [fs]\n\n"); printf("where:\n"); printf("flt_type: is the filter type:\n"); printf(" IRS, HQ2, HQ3, PCM, PCM1\n"); printf("f0 is the starting frequency [Hz]\n"); printf("ff is the final frequency [Hz]\n"); printf("fstep is the step in frequency from f0 to ff [Hz]\n"); printf("%s%s", "[fs]is the sampling frequency [Hz]; ", "default is 8000 Hz.\n\n"); printf("Options:\n"); printf("-fs: .... define sampling frequency, in Hz [def:8000Hz]\n"); printf("-mod: ... use modified IRS filters\n"); printf("-q: ..... quiet mode - don't print funny chars\n"); printf("Valid combinations of filter and sampling rate:\n\n"); printf("Flt_type fs Description \n"); printf(" IRS 8000 (regular) IRS weighting with factor 1:2. \n"); printf(" 16000 (regular|modified) IRS weighting with factor 2:1.\n"); printf(" 48000 (modified) IRS weighting with factor 2:1.\n"); printf(" DSM 16000 Delta-SM with factor 1:1\n"); printf(" PSO 8000 Psophometric filter with factor 1:1\n"); printf(" HQ2 8000 High quality with factor 1:2\n"); printf(" 16000 High quality with factor 2:1\n"); printf(" HQ3 8000 High quality with factor 1:3\n"); printf(" 16000 High quality with factor 3:1\n"); printf(" FLAT 8000 Linear-phase pass-band with factor 1:2\n"); printf(" 16000 Linear-phase pass-band with factor 2:1\n"); printf(" PCM 8000 Standard PCM quality factor 1:2\n"); printf(" 16000 Standard PCM quality factor 2:1\n"); printf(" PCM1 8000 unimplemented!\n"); printf("%s%s", " 16000 Standard PCM quality with ", "factor 1:1 at 16 kHz\n\n"); exit(-128);}/*============================== */int main(argc, argv) int argc; char *argv[];/*============================== */{ /* DECLARATIONS */ /* Algorithm variables */ SCD_FIR *fir_state; SCD_IIR *iir_state; float *BufInp, *BufOut; char F_type[20]; long j, k, N, N2; char modified_IRS = 0, quiet = 0; long inp_size, out_size; double f, f0, fstep, ff, fs=8000, inp_pwr; double H_k, cur_f; static char is_fir = 1; /* PREAMBLE */ N = 256; N2 = 20; inp_size = N * N2; /* ......... GET PARAMETERS ......... */ /* Check options */ if (argc < 2) display_usage(); else { while (argc > 1 && argv[1][0] == '-') if (strcmp(argv[1],"-mod")==0) { /* Get skip length */ modified_IRS = 1; /* Move arg{c,v} over the option to the next argument */ argc--; argv++; } else if (strcmp(argv[1], "-fs") == 0) { /* Change sampling frequency */ fs = atof(argv[2]); /* Move arg{c,v} over the option to the next argument */ argc -= 2; argv += 2; } else if (strcmp(argv[1], "-q") == 0) { /* Change sampling frequency */ quiet = 1; /* Move arg{c,v} over the option to the next argument */ argc --; argv ++; } else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-?") == 0) { /* Display help message */ display_usage();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -