function[peter] = GaussQuad(fhandle,n,type)
%n2w=[0.853553390593 0.146446609407]';
%n2x=[0.585786437627 3.41421356237]';
%n4w=[0.603154104342 0.357418692438 0.038887908515 0.000539294705561]';
%n4x=[0.322547689619 1.74576110116 4.53662029692 9.3950709123]';
%n8w=[0.369188589342 0.418786780814 0.175794986637 0.0333434922612 0.00279453623523 9.07650877338E-005 8.48574671626E-007 1.04800117487E-009]';
%n8x=[0.170279632305 0.903701776799 2.25108662987 4.26670017029 7.04590540239 10.7585160102 15.7406786413 22.8631317369]';
%n16w=[0.206151714958 0.331057854951 0.265795777644 0.136296934296 0.0473289286947 0.0112999000801 0.00184907094333 0.000204271915245 1.48445868632E-005 6.8283193539E-007 1.88102485005E-008 2.8623502399E-010 2.12707902829E-012 6.29796700755E-015 5.050473696E-018 4.16146236924E-022]';
%n16x=[0.0876494104789 0.462696328915 1.14105777483 2.1292836451 3.43708663389 5.07801861456 7.07033853501 9.43831433649 12.2142233686 15.4415273694 19.1801568554 23.5159056959 28.5787297412 34.5833987032 41.9404526474 51.7011603396]';

[n2x,n2w]=GLagNodeWt(2);
[n4x,n4w]=GLagNodeWt(4);
[n8x,n8w]=GLagNodeWt(8);
[n16x,n16w]=GLagNodeWt(16);

if type == 1
    ludwig = 1:1:n;
    harald=sum(fhandle(cos((2*ludwig-1)*pi/(2*n))));
    peter=pi/n*harald;
else if type == 2
        if n == 2
            peter = n2w(1)*fhandle(n2x(1))+n2w(2)*fhandle(n2x(2));
        end
        if n == 4
            peter = n4w(1)*fhandle(n4x(1))+n4w(2)*fhandle(n4x(2))+n4w(3)*fhandle(n4x(3))+n4w(4)*fhandle(n4x(4));
        end
        if n == 8
            peter = n8w(1)*fhandle(n8x(1))+n8w(2)*fhandle(n8x(2))+n8w(3)*fhandle(n8x(3))+n8w(4)*fhandle(n8x(4))+n8w(5)*fhandle(n8x(5))+n8w(6)*fhandle(n8x(6))+n8w(7)*fhandle(n8x(7))+n8w(8)*fhandle(n8x(8));
        end
        if n == 16
            peter = n16w(1)*fhandle(n16x(1))+n16w(2)*fhandle(n16x(2))+n16w(3)*fhandle(n16x(3))+n16w(4)*fhandle(n16x(4))+n16w(5)*fhandle(n16x(5))+n16w(6)*fhandle(n16x(6))+n16w(7)*fhandle(n16x(7))+n16w(8)*fhandle(n16x(8))+n16w(9)*fhandle(n16x(9))+n16w(10)*fhandle(n16x(10))+n16w(11)*fhandle(n16x(11))+n16w(12)*fhandle(n16x(12))+n16w(13)*fhandle(n16x(13))+n16w(14)*fhandle(n16x(14))+n16w(15)*fhandle(n16x(15))+n16w(16)*fhandle(n16x(16));
        end
    end
end
load handel;
sound(y,Fs);

















































%copyright phx ltd
