void ofDrawRectOutline(const ofRectangle & rect, int thickness, ofDrawRectOutlineMode mode) { float b0, b1; if(mode == ofDrawRectOutlineModeOuter) { b0 = thickness; b1 = 0; } else if(mode == ofDrawRectOutlineModeInner) { b0 = 0; b1 = thickness; } else if(mode == ofDrawRectOutlineModeMiddle) { b0 = thickness * 0.5; b1 = thickness * 0.5; } ofVec2f po0(rect.x - b0, rect.y - b0); ofVec2f po1(rect.x + rect.width + b0, rect.y - b0); ofVec2f po2(rect.x + rect.width + b0, rect.y + rect.height + b0); ofVec2f po3(rect.x - b0, rect.y + rect.height + b0); ofVec2f pi0(rect.x + b1, rect.y + b1); ofVec2f pi1(rect.x + rect.width - b1, rect.y + b1); ofVec2f pi2(rect.x + rect.width - b1, rect.y + rect.height - b1); ofVec2f pi3(rect.x + b1, rect.y + rect.height - b1); ofBeginShape(); ofVertex(po0.x, po0.y); ofVertex(po1.x, po1.y); ofVertex(po2.x, po2.y); ofVertex(po3.x, po3.y); ofNextContour(); ofVertex(pi0.x, pi0.y); ofVertex(pi1.x, pi1.y); ofVertex(pi2.x, pi2.y); ofVertex(pi3.x, pi3.y); ofEndShape(true); }
void wv (type_signal Signal, type_TFR tfr) { int Nfft, column, row, time; int taumax, tau; double *lacf_real, *lacf_imag; /* local autocorrelation function */ /*--------------------------------------------------------------------*/ /* Test the input variables */ /*--------------------------------------------------------------------*/ if (tfr.is_complex == TRUE) { printf ("wv.c : The tfr matrix must be real valued\n"); exit(0); } if (tfr.N_freq <= 0) { printf ("wv.c : The field tfr.N_freq is not correctly set\n"); exit(0); } if (tfr.N_time <= 0) { printf ("wv.c : The field tfr.N_time is not correctly set\n"); exit(0); } /*--------------------------------------------------------------------*/ /* creation of the vector of frequency bins (output) */ /*--------------------------------------------------------------------*/ Nfft = po2 (tfr.N_freq); for (row = 0; row < tfr.N_freq; row++) { tfr.freq_bins[row] = (double) (0.5 * row) / tfr.N_freq; } /*--------------------------------------------------------------------*/ /* memory allocation for the local autocorrelation function */ /*--------------------------------------------------------------------*/ lacf_real = (double *) ALLOC (tfr.N_freq , sizeof (double)); lacf_imag = (double *) ALLOC (tfr.N_freq , sizeof (double)); /* initialization of these vectors */ for (row = 0; row < tfr.N_freq ; row++) { lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } /*--------------------------------------------------------------------*/ /* computation of the fft for the current windowed signal */ /*--------------------------------------------------------------------*/ for (column = 0; column < tfr.N_time; column++) { /* time instants of interest to compute the Wigner distrib. */ time = ((int) tfr.time_instants[column]) - 1; /* taumax enables the computation near the edges */ taumax = MIN (time, (Signal.length - time - 1)); taumax = MIN (taumax, (tfr.N_freq / 2 - 1)); /* for each delay value, the laf is computed and ffted */ /* in order to pass from the (t,tau) domain to the (t,f) */ /* domain */ for (tau = -taumax; tau <= taumax; tau++) { row = irem((tfr.N_freq+tau), tfr.N_freq ) ; /* when the signal is complex valued */ if (Signal.is_complex == TRUE) { lacf_real[row] = Signal.real_part[time + tau] * Signal.real_part[time - tau] + Signal.imag_part[time + tau] * Signal.imag_part[time - tau]; lacf_imag[row] = Signal.imag_part[time + tau] * Signal.real_part[time - tau] - Signal.real_part[time + tau] * Signal.imag_part[time - tau]; } /* when the signal is real valued */ else { lacf_real[row] = Signal.real_part[time + tau] * Signal.real_part[time - tau]; lacf_imag[row] = 0.0; } } tau=floor(tfr.N_freq/2); if ((time<=Signal.length-tau-1)&(time>=tau)) { if (Signal.is_complex == TRUE) { lacf_real[tau] = Signal.real_part[time+tau]*Signal.real_part[time-tau] +Signal.imag_part[time+tau]*Signal.imag_part[time-tau]; lacf_imag[tau] = 0; } else { lacf_real[tau] = Signal.real_part[time+tau]*Signal.real_part[time-tau]; lacf_imag[tau] = 0; } } /* fft of the local autocorrelation function lacf */ fft (tfr.N_freq, Nfft, lacf_real, lacf_imag); /* the fft is put in the wv matrix and reinitialized */ for (row = 0; row < tfr.N_freq; row++) { tfr.real_part[idx (row,column,tfr.N_freq)]= lacf_real[row]; lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } } /*--------------------------------------------------------------------*/ /* free the memory used in this program */ /*--------------------------------------------------------------------*/ FREE (lacf_real); FREE (lacf_imag); }
void mhs (type_signal Signal, double *WindowG, int WindowG_Length, double *WindowH, int WindowH_Length, type_TFR tfr ) { int Nfft, column, row, time; int taumin, taumax, tau; int half_WindowG_Length, half_WindowH_Length; double *windG_sig_real, *windG_sig_imag; /* windowed signal */ double *windH_sig_real, *windH_sig_imag; /* windowed signal */ double normH; int Lgh, points; double Kgh; /*--------------------------------------------------------------------*/ /* Test the input variables */ /*--------------------------------------------------------------------*/ if (tfr.is_complex == TRUE) { printf ("mhs.c : The tfr matrix must be real valued\n"); exit(0); } if (tfr.N_freq <= 0) { printf ("mhs.c : The field tfr.N_freq is not correctly set\n"); exit(0); } if (tfr.N_time <= 0) { printf ("mhs.c : The field tfr.N_time is not correctly set\n"); exit(0); } /*--------------------------------------------------------------------*/ /* checks that the window length is odd */ /*--------------------------------------------------------------------*/ if (ISODD(WindowG_Length) == 0) { printf ("mhs.c : The window G Length must be an ODD number\n"); exit(0); } if (ISODD(WindowH_Length) == 0) { printf ("mhs.c : The window H Length must be an ODD number\n"); exit(0); } half_WindowG_Length = (WindowG_Length - 1) / 2; half_WindowH_Length = (WindowH_Length - 1) / 2; normH=WindowH[half_WindowH_Length]; for(row = 0; row < WindowH_Length; row++) { WindowH[row] = WindowH[row]/normH; } Lgh = MIN( half_WindowG_Length , half_WindowH_Length ); Kgh = 0.0; for( points=-Lgh ; points<=Lgh ; points++) { Kgh = Kgh + WindowH[half_WindowH_Length+points] *WindowG[half_WindowG_Length+points]; } for(row = 0; row < WindowH_Length; row++) { WindowH[row] = WindowH[row]/Kgh; } /*--------------------------------------------------------------------*/ /* creation of the vector of frequency bins (output) */ /*--------------------------------------------------------------------*/ Nfft = po2 (tfr.N_freq); for (row = 0; row < tfr.N_freq; row++) { tfr.freq_bins[row] = (double) row / tfr.N_freq; } /*--------------------------------------------------------------------*/ /* memory allocation for the windowed signal */ /*--------------------------------------------------------------------*/ windG_sig_real = (double *) ALLOC (tfr.N_freq, sizeof (double)); windG_sig_imag = (double *) ALLOC (tfr.N_freq, sizeof (double)); windH_sig_real = (double *) ALLOC (tfr.N_freq, sizeof (double)); windH_sig_imag = (double *) ALLOC (tfr.N_freq, sizeof (double)); for (row = 0; row < tfr.N_freq; row++) { windG_sig_real[row] = 0.0; windG_sig_imag[row] = 0.0; windH_sig_real[row] = 0.0; windH_sig_imag[row] = 0.0; } /*--------------------------------------------------------------------*/ /* computation of the fft for the current windowed signal */ /*--------------------------------------------------------------------*/ for (column = 0; column < tfr.N_time; column++) { /* time instants of interest to compute the tfr */ time = ((int) tfr.time_instants[column]) - 1; taumin = MIN (tfr.N_freq / 2, half_WindowG_Length); taumin = MIN (taumin, time); taumax = MIN ((tfr.N_freq / 2 - 1), half_WindowG_Length); taumax = MIN (taumax, (Signal.length - time - 1)); /* The signal is windowed around the current time */ for (tau = -taumin; tau <= taumax; tau++) { row = irem( (tfr.N_freq+tau), tfr.N_freq ) ; windG_sig_real[row] = Signal.real_part[time + tau] * WindowG[half_WindowG_Length + tau]; if (Signal.is_complex == TRUE) { windG_sig_imag[row] = Signal.imag_part[time + tau] * WindowG[half_WindowG_Length + tau]; } } /* fft of the windowed signal */ fft (tfr.N_freq, Nfft, windG_sig_real, windG_sig_imag); taumin = MIN (tfr.N_freq / 2, half_WindowH_Length); taumin = MIN (taumin, time); taumax = MIN ((tfr.N_freq / 2 - 1), half_WindowH_Length); taumax = MIN (taumax, (Signal.length - time - 1)); /* The signal is windowed around the current time */ for (tau = -taumin; tau <= taumax; tau++) { row = irem( (tfr.N_freq+tau), tfr.N_freq ) ; windH_sig_real[row] = Signal.real_part[time + tau] * WindowH[half_WindowH_Length + tau]; if (Signal.is_complex == TRUE) { windH_sig_imag[row] = Signal.imag_part[time + tau] * WindowH[half_WindowH_Length + tau]; } } /* fft of the windowed signal */ fft (tfr.N_freq, Nfft, windH_sig_real, windH_sig_imag); /* the first half of the fft is put in the tfr matrix */ for (row = 0; row < tfr.N_freq; row++) { tfr.real_part[idx (row,column,tfr.N_freq)] = windG_sig_real[row]*windH_sig_real[row] + windG_sig_imag[row]*windH_sig_imag[row]; windG_sig_real[row] = 0.0; windG_sig_imag[row] = 0.0; windH_sig_real[row] = 0.0; windH_sig_imag[row] = 0.0; } } /*--------------------------------------------------------------------*/ /* free the memory used in this program */ /*--------------------------------------------------------------------*/ FREE (windG_sig_real); FREE (windG_sig_imag); FREE (windH_sig_real); FREE (windH_sig_imag); }
void ri (type_signal Signal, type_TFR tfr) { int Nfft, column, row, time; int taumin, taumax, tau; double *lacf_real, *lacf_imag; /* local autocorrelation function */ /*--------------------------------------------------------------------*/ /* Test the input variables */ /*--------------------------------------------------------------------*/ if (tfr.is_complex == FALSE) { printf ("ri.c : The tfr matrix must be complex valued\n"); exit(0); } if (tfr.N_freq <= 0) { printf ("ri.c : The field tfr.N_freq is not correctly set\n"); exit(0); } if (tfr.N_time <= 0) { printf ("ri.c : The field tfr.N_time is not correctly set\n"); exit(0); } /*--------------------------------------------------------------------*/ /* creation of the vector of frequency bins (output) */ /*--------------------------------------------------------------------*/ Nfft = po2 (tfr.N_freq); for (row = 0; row < tfr.N_freq; row++) { tfr.freq_bins[row] = (double) row / tfr.N_freq; } /*--------------------------------------------------------------------*/ /* memory allocation for the windowed signal */ /*--------------------------------------------------------------------*/ lacf_real = (double *) ALLOC (tfr.N_freq , sizeof (double)); lacf_imag = (double *) ALLOC (tfr.N_freq , sizeof (double)); /* initialization of the intermediary vectors */ for (row = 0; row < tfr.N_freq ; row++) { lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } /*--------------------------------------------------------------------*/ /* computation of the fft for the current windowed signal */ /*--------------------------------------------------------------------*/ for (column = 0; column < tfr.N_time; column++) { /* time instants of interest to compute the tfr */ time = ((int) tfr.time_instants[column]) - 1; /* taumax and taumin enable the computation near the edges */ taumin = MIN( (tfr.N_freq - time), (Signal.length - time - 1) ); taumax = time; /* The signal is windowed around the current time */ for (tau = -taumin; tau <= taumax; tau++) { row = irem( (tfr.N_freq+tau), tfr.N_freq ) ; if (Signal.is_complex == TRUE) /* when the signal is complex valued */ { lacf_real[row] = Signal.real_part[time] * Signal.real_part[time - tau] + Signal.imag_part[time] * Signal.imag_part[time - tau]; lacf_imag[row] = Signal.imag_part[time] * Signal.real_part[time - tau] - Signal.real_part[time] * Signal.imag_part[time - tau]; } else /* when the signal is real valued */ { lacf_real[row] = Signal.real_part[time] * Signal.real_part[time - tau]; lacf_imag[row] = 0.0; } } /* fft of the local autocorrelation function lacf */ fft (tfr.N_freq, Nfft, lacf_real, lacf_imag); /* the fft is put in the tfr matrix */ for (row = 0; row < tfr.N_freq; row++) { tfr.real_part[idx (row,column,tfr.N_freq)]= lacf_real[row]; tfr.imag_part[idx (row,column,tfr.N_freq)]= lacf_imag[row]; lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } } /*--------------------------------------------------------------------*/ /* free the memory used in this program */ /*--------------------------------------------------------------------*/ FREE (lacf_real); FREE (lacf_imag); }
void spwv (type_signal Signal, double *WindowT, int WindowT_Length, double *WindowF, int WindowF_Length, type_TFR tfr) { int Nfft, column, row, time; int half_WindowT_Length, half_WindowF_Length; int taumin, taumax, tau; int mumin, mumax, mu; double *lacf_real, *lacf_imag; /* local autocorrelation function */ double normT, normF; double R0_real, R0_imag, R1_real, R1_imag, R2_real, R2_imag; /*--------------------------------------------------------------------*/ /* Test the input variables */ /*--------------------------------------------------------------------*/ if (tfr.is_complex == TRUE) { printf ("spwv.c : The tfr matrix must be real valued\n"); exit(0); } if (tfr.N_freq <= 0) { printf ("spwv.c : The field tfr.N_freq is not correctly set\n"); exit(0); } if (tfr.N_time <= 0) { printf ("spwv.c : The field tfr.N_time is not correctly set\n"); exit(0); } if (ISODD(WindowT_Length) == 0) { printf ("spwv.c : The time-window Length must be an ODD number\n"); exit(0); } if (ISODD(WindowF_Length) == 0) { printf ("spwv.c : The frequency-window Length must be an ODD number\n"); exit(0); } /*--------------------------------------------------------------------*/ /* Determines some internal constants */ /*--------------------------------------------------------------------*/ half_WindowT_Length = (WindowT_Length - 1) / 2; half_WindowF_Length = (WindowF_Length - 1) / 2; normF=WindowF[half_WindowF_Length]; for(row = 0; row < WindowF_Length; row++) { WindowF[row] = WindowF[row]/normF; } /*--------------------------------------------------------------------*/ /* creation of the vector of frequency bins (output) */ /*--------------------------------------------------------------------*/ Nfft = po2 (tfr.N_freq); for (row = 0; row < tfr.N_freq; row++) { tfr.freq_bins[row] = (double) (0.5 * row) / tfr.N_freq; } /*--------------------------------------------------------------------*/ /* memory allocation and init. of the local autocorrelation fuction */ /*--------------------------------------------------------------------*/ lacf_real = (double *) ALLOC (tfr.N_freq , sizeof (double)); lacf_imag = (double *) ALLOC (tfr.N_freq , sizeof (double)); /* initialization of the intermediary vectors */ for (row = 0; row < tfr.N_freq ; row++) { lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } /*--------------------------------------------------------------------*/ /* computation of the fft for the current windowed signal */ /*--------------------------------------------------------------------*/ for (column = 0; column < tfr.N_time; column++) { /* time instants of interest to compute the tfr */ time = ((int) tfr.time_instants[column]) - 1; taumax = MIN((time+half_WindowT_Length),(Signal.length-time-1+half_WindowT_Length)); taumax = MIN(taumax,(tfr.N_freq / 2 - 1)); taumax = MIN(taumax, half_WindowF_Length); /* determination of the begin and end of mu */ mumin=MIN(half_WindowT_Length,(Signal.length-time-1)); mumax=MIN(half_WindowT_Length,time); /* Normalization of the time-smoothing window */ /* window norm */ normT=0; for(row = -mumin ; row <= mumax ; row++) { normT=normT+ WindowT[half_WindowT_Length+row]; } R0_real=0.0; R0_imag=0.0; for(mu=-mumin;mu<=mumax;mu++) { if (Signal.is_complex == TRUE) { R0_real=R0_real + (Signal.real_part[time-mu] * Signal.real_part[time-mu] + Signal.imag_part[time-mu] * Signal.imag_part[time-mu]) * WindowT[half_WindowT_Length+mu]/normT; } else { R0_real=R0_real + Signal.real_part[time-mu] * Signal.real_part[time-mu] * WindowT[half_WindowT_Length+mu]/normT; } } lacf_real[0]=R0_real; lacf_imag[0]=R0_imag; /* The signal is windowed around the current time */ for (tau = 1; tau <= taumax; tau++) { R1_real=0;R2_real=0; R1_imag=0;R2_imag=0; mumin=MIN(half_WindowT_Length,(Signal.length-time-1-tau)); mumax=MIN(half_WindowT_Length,time-tau); /* window norm */ normT=0; for(row = -mumin ; row <= mumax ; row++) { normT = normT + WindowT[half_WindowT_Length+row]; } for(mu=-mumin;mu<=mumax;mu++) { if (Signal.is_complex == TRUE) { R1_real = R1_real + (Signal.real_part[time+tau-mu] * Signal.real_part[time-tau-mu] + Signal.imag_part[time+tau-mu] * Signal.imag_part[time-tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R1_imag = R1_imag + (Signal.imag_part[time+tau-mu] * Signal.real_part[time-tau-mu] - Signal.real_part[time+tau-mu] * Signal.imag_part[time-tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R2_real = R2_real + (Signal.real_part[time-tau-mu] * Signal.real_part[time+tau-mu] + Signal.imag_part[time-tau-mu] * Signal.imag_part[time+tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R2_imag = R2_imag + (Signal.imag_part[time-tau-mu] * Signal.real_part[time+tau-mu] - Signal.real_part[time-tau-mu] * Signal.imag_part[time+tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; } else { R1_real = R1_real + (Signal.real_part[time+tau-mu] * Signal.real_part[time-tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R1_imag = 0.0; R2_real = R2_real + (Signal.real_part[time-tau-mu] * Signal.real_part[time+tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R2_imag = 0.0; } } lacf_real[tau] = R1_real * WindowF[half_WindowF_Length+tau]; lacf_imag[tau] = R1_imag * WindowF[half_WindowF_Length+tau]; lacf_real[tfr.N_freq-tau] = R2_real * WindowF[half_WindowF_Length-tau]; lacf_imag[tfr.N_freq-tau] = R2_imag * WindowF[half_WindowF_Length-tau]; } tau=floor(tfr.N_freq/2); if ((time<=Signal.length-tau-1)&(time>=tau)&(tau<=half_WindowF_Length)) { mumin=MIN(half_WindowT_Length,(Signal.length-time-1-tau)); mumax=MIN(half_WindowT_Length,time-tau); normT=0; for(row = -mumin ; row <= mumax ; row++) { normT = normT + WindowT[half_WindowT_Length+row]; } R1_real=0;R2_real=0; R1_imag=0;R2_imag=0; for(mu=-mumin;mu<=mumax;mu++) { if (Signal.is_complex == TRUE) { R1_real = R1_real + (Signal.real_part[time+tau-mu] * Signal.real_part[time-tau-mu] + Signal.imag_part[time+tau-mu] * Signal.imag_part[time-tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R1_imag = R1_imag + (Signal.imag_part[time+tau-mu] * Signal.real_part[time-tau-mu] - Signal.real_part[time+tau-mu] * Signal.imag_part[time-tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R2_real = R2_real + (Signal.real_part[time-tau-mu] * Signal.real_part[time+tau-mu] + Signal.imag_part[time-tau-mu] * Signal.imag_part[time+tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R2_imag = R2_imag + (Signal.imag_part[time-tau-mu] * Signal.real_part[time+tau-mu] - Signal.real_part[time-tau-mu] * Signal.imag_part[time+tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; } else { R1_real = R1_real + (Signal.real_part[time+tau-mu] * Signal.real_part[time-tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R1_imag = 0.0; R2_real = R2_real + (Signal.real_part[time-tau-mu] * Signal.real_part[time+tau-mu]) * WindowT[half_WindowT_Length+mu]/normT; R2_imag = 0.0; } } lacf_real[tau] = 0.5*(R1_real * WindowF[half_WindowF_Length+tau] + R2_real * WindowF[half_WindowF_Length-tau]); lacf_imag[tau] = 0.5*(R1_imag * WindowF[half_WindowF_Length+tau] + R2_imag * WindowF[half_WindowF_Length-tau]); } /* fft of the local autocorrelation function lacf */ fft (tfr.N_freq, Nfft, lacf_real, lacf_imag); /* the fft is put in the tfr matrix */ for (row = 0; row < tfr.N_freq; row++) { *(tfr.real_part +row +column*tfr.N_freq)= lacf_real[row]; lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } } /*--------------------------------------------------------------------*/ /* free the memory used in this program */ /*--------------------------------------------------------------------*/ FREE (lacf_real); FREE (lacf_imag); }