Construct normalized bases.

Parameters:

dim=10;

dimRef = dim/2;

osRate= 2.0;

numSamples = Round[osRate*dim];

Characteristic (or box) basis:

widthFactor = 1  / (2/dim);

BBasis= ConstantArray[0, dim];

dx = widthFactor - 1/2;

For[i=1,i≤dim,i++,
BBasis[[i]] = UnitBox[widthFactor * x +dx ];
n = Sqrt[ Integrate[ BBasis[[i]] * BBasis[[i]], {x, -1,1}]];
BBasis[[i]] /= n;
dx -= 1;
]

Legendre basis

LBasis=ConstantArray[0,dim];

For[i=1,i≤dim,i++,
LBasis[[i]] = LegendreP[i-1,x];
n = Sqrt[ Integrate[ LBasis[[i]] * LBasis[[i]], {x, -1,1}]];
LBasis[[i]] /= n;
]

Cosine basis.

CBasis = ConstantArray[0,dimRef];

For[i=1,i≤dimRef,i++,
CBasis[[i]]=  Cos[(i-1)*2π*x]+Sin[(i-1)*2π*x];
n = Sqrt[ Integrate[ CBasis[[i]] * CBasis[[i]], {x, -1,1}]];
CBasis[[i]] /= n;
]

Project chraracteristic and Legendre basis into reference cosine basis.

BProj = ConstantArray[0, {dim,dimRef}];

TBProj = ConstantArray[0,dim];

For[i=1,i≤dim,i++,
For[j=1,j<=dimRef,j++,
BProj[[i,j]]=Integrate[BBasis[[i]]* CBasis[[j]],{x,-1,1}];
];
TBProj[[i]]=(BProj[[i,Range[dimRef]]].BProj[[i,Range[dimRef]]]);
]

LProj = ConstantArray[0, {dim,dimRef}];

TLProj = ConstantArray[0, dim];

For[i=1,i≤dim,i++,
For[j=1,j<=dimRef,j++,
LProj[[i,j]]=Integrate[LBasis[[i]]* CBasis[[j]],{x,-1,1}];
];
TLProj[[i]]=(LProj[[i,Range[dimRef]]].LProj[[i,Range[dimRef]]]);
]

Consider total residual energy of projection

N[Total[TBProj]]

N[Total[TLProj]]

Construct quadrature rules.

Sampling locations (but ensure that there is at least one sampling point in each bin; hence a two step process).

dx= (Range[dim]-1)*(2/dim)-1;

locs = RandomReal[{0, 2/dim}, dim]+dx;

locs = Sort[Join[locs, RandomReal[{-1,1}, numSamples-dim]]]

Construct kernel matrices.

KB =ConstantArray[0,{numSamples,dim}];

For[i=1,i≤numSamples,i++,
For[j=1,j≤dim,j++,
KB[[i,j]]=BBasis[[j]] /. x->locs[[i]];
]
]

KL=ConstantArray[0,{numSamples,dim}];

For[i=1,i≤numSamples,i++,
For[j=1,j≤dim,j++,
KL[[i,j]]=LBasis[[j]]/.x->locs[[i]];
]
]

Sampling matrices.

SB = PseudoInverse[KB];

SL=PseudoInverse[KL];

Quadrature weights.

BWeights = ConstantArray[0,numSamples];

For[k=1,k≤numSamples,k++,
For[j=1,j≤dim,j++,
BWeights[[k]] += SB[[j,k]]*Integrate[BBasis[[j]],{x,-1,1}];
]
]

For the Legendre basis the first basis function is the constant function so that the quadrature rule is defined by the first row of the sampling matrix.

LWeights = SL[[1,Range[numSamples]]] * Integrate[LBasis[[1]], {x,-1,1}];

Construct test signal

coeffs = RandomReal[{-1,1}, dimRef];

sig = 0;

For[k=1,k<dimRef,k++,
sig += coeffs[[k]]*CBasis[[k]];
]

int = Integrate[sig,{x,-1,1}]

samples = sig /. x->locs

dq1 = samples . BWeights

dq2=samples.LWeights

int - dq1

int - dq2

Very simple check that the quadrature rules are at least in principle correct (the answer is 2).

ftest = ConstantArray[1,numSamples];

ftest.BWeights

ftest.LWeights