shithub: libsamplerate

Download patch

ref: 3ab82169d817d566a9f295b2d388e583431fc2fe
parent: 9b8e61e5c3c009d1e9b4d55a7d060accf7cbc9fc
author: Erik de Castro Lopo <erikd@miles>
date: Mon Nov 1 07:10:46 EST 2004

Unwrap the phase response.

--- a/FIR-POLY/mag_spectrum.cc
+++ b/FIR-POLY/mag_spectrum.cc
@@ -32,7 +32,7 @@
 	static double *fft_data = NULL ;
 
 	double	maxval ;
-	int		k ;
+	int		k, pi_factor ;
 
 	if (input == NULL || magnitude == NULL || phase == NULL)
 	{	printf ("%s %d : input == NULL || magnitude == NULL || phase == NULL\n", __func__, __LINE__) ;
@@ -62,6 +62,15 @@
 	for (k = 0 ; k < len / 2 ; k++)
 	{	magnitude [k] = sqrt (fft_data [k] * fft_data [k] + fft_data [len - k - 1] * fft_data [len - k - 1]) ;
 		phase [k] = atan2 (fft_data [len - k - 1], fft_data [k]) ;
+		} ;
+
+	pi_factor = 0 ;
+	for (k = 1 ; k < len / 2 ; k++)
+	{	phase [k] -= pi_factor * M_PI ;
+		if (fabs (phase [k] - phase [k - 1]) > 3.0)
+		{	phase [k] -= 2 * M_PI ;
+			pi_factor += 2 ;
+			}
 		} ;
 
 	return ;