A sharp weighted Wirtinger inequality and some related functional spaces