www.pudn.com > ica_C.rar > ica_f.c
#include#include #include #include "bss.h" #include "spec.h" #ifndef ARRAY #define ARRAY 1 #include "array.h" #endif #ifndef WAV #define WAV 1 #include "wav_io.h" #endif #ifndef MATRIX #define MATRIX 1 #include "matrix.h" #endif #ifndef PERMUTATION #define PERMUTATION 1 #include "permutation.h" #endif #define DIM 2 void usage(char *s) { printf("%s -{options} {-o1 } {-o2 }\n",s); printf(" must be *.wav\n\n"); printf(" options\n"); printf(" -N : NFFT, number for FFT,\n"); printf(" default=64, This must be power of 2.\n"); printf(" -T : TAU, number for making filter,\n"); printf(" default=NFFT/2,0 < TAU < NFFT.\n"); printf(" -S : Time shift for spectrogram,\n"); printf(" default=20, 0 < SHIFT< NFFT.\n"); printf(" -M : Time for Moving Average,\n"); printf(" default=0.04[s].\n"); printf(" -m : Number of matrixes to be diagonalized.\n"); printf(" default=40.\n"); printf(" -P : Time for Solving Permutation,\n"); printf(" default=1.0[s].\n"); printf(" -h : print this message.\n\n"); printf(" -o : Head part of the output file,\n"); printf(" default= , _sep{1,2}.wav\n"); exit(1); } int main(int argc, char *argv[]) { char infile[1024], outfile[2][1024], append1[] = "_sep1.wav", append2[] = "_sep2.wav"; int len,slen,i,j,k,l,f,t,FS,data4perm,ma,NFFT=512,TAU=NULL, SHIFT=20,MNUM=40; short sep_x[2]; SCALAR MA=0.04,T4PERM=1.0,tmp,tmp_x; wavfmt fmt; vector window,xf_r,xf_i; matrix x; array3 Wsep_r,Wsep_i,Winv_r,Winv_i,sph_r,sph_i,rot_r,rot_i; array4 sp_r,sp_i,fil_t,Corr_r, Corr_i; FILE *fp; /* options */ if(argc<2) usage(argv[0]); i=1; while(i NFFT || TAU < 0) usage(argv[0]); if(SHIFT > NFFT || SHIFT < 0) usage(argv[0]); if(TAU==NULL)TAU=NFFT/2; if(i==argc)usage(argv[0]); else if(argc==(i+1)){ strcpy(infile, argv[i]); strncpy(outfile[0], infile, strlen(infile)-4); strncpy(outfile[1], infile, strlen(infile)-4); outfile[0][strlen(infile)-4]=NULL; outfile[1][strlen(infile)-4]=NULL; strcat(outfile[0], append1); strcat(outfile[1], append2); } else if(argc>(i+1)){ strcpy(infile, argv[i]); if(strcmp(argv[i+1],"-o")==0){ strcpy(outfile[0], argv[i+2]); strcpy(outfile[1], argv[i+2]); outfile[0][strlen(argv[i+2])]=NULL; outfile[1][strlen(argv[i+2])]=NULL; strcat(outfile[0], append1); strcat(outfile[1], append2); } else usage(argv[0]); } /* options */ len=read_wav(infile, &fmt); x = new_matrix(DIM,(int)len+NFFT-1); WaveData_2_DoubleMat(fmt, x); for(t=0;t len)data4perm=len-(len-NFFT)%((int)SHIFT); slen=spl(data4perm, NFFT, SHIFT); ma=(int)floor((MA*FS)/((double)SHIFT)); window = new_vector(NFFT); hamming(NFFT, window); xf_r = new_vector(NFFT); xf_i = new_vector(NFFT); Wsep_r = new_array3(NFFT/2+1,DIM,DIM); Wsep_i = new_array3(NFFT/2+1,DIM,DIM); Winv_r = new_array3(NFFT/2+1,DIM,DIM); Winv_i = new_array3(NFFT/2+1,DIM,DIM); for(f=0;f =1){ printf("data is too large and be clipped\n"); sep_x[i]=MAX-1; } else if(tmp<-1){ printf("data is too large and be clipped\n"); sep_x[i]=-MAX; } else sep_x[i]=(short)(MAX*tmp); } fwrite(sep_x,2,2,fp); } fclose(fp); printf("Done\n"); } return(1); }