Preheat the oven to 180°C (350°F) conventional or 170°C fan. Line a 20 cm (8 inch) or 23 to 25 cm square tin with baking paper.
For the base, beat the butter, caster sugar, vanilla and almond extract until pale and fluffy, about 3 minutes.
Add the flour and mix briefly until soft crumbs form. They should clump together when you press them between your fingers.
Tip the crumbs into the tin and press them down evenly. Smooth the surface gently with a spatula.
For the frangipane, use the same bowl. Beat the butter, caster sugar, vanilla and almond extract until creamy. Add the eggs and beat until the mixture is smooth, pale and fluffy.
Add the ground almonds and flour and mix briefly until just combined.
Spoon the frangipane over the base and spread it evenly with an offset spatula. Scatter over the flaked almonds.
Bake for 43 to 45 minutes until golden on top and cooked through. If the top browns too quickly, cover the tin loosely with foil.
Leave to cool completely in the tin. Dust with icing sugar and cut into squares.