I have had this issue in the past, and still do under some conditions. My primary issue was a bad engine alignment. A little hard to check on the hard (as boats flex, and alignment may shift), but if you can put on goggles and inspect from the outside while the boat is in the water, you may be able to see that the shaft it not centred in the log. For my boat, I did that inspection on the hard (when replacing the stuffing box with a drip-less, and thus the shaft and log were well exposed for inspection.
For my boat, the shaft was significantly off centre in the log, and thus, when the engine was running a little rough, or while motor sailing with a little bit of heel, the shaft would bang on the log. If you throttle up hard and fast, I find my boat/engine/prop shakes a bit until it reaches speed, and that knocking would also happen. It seems the hull amplifies the sound and it can be quite disconcerting.
When re-aligning, I found that I had to adjust the motor on it mounts to the limits of the oblong holes in the mounts to come close to proper alignment. Makes me think the boat was never setup quite right from the factory (strut, log, engine where never quite lined up right) or something has shifted over time.
Note that when aligning/centring the shaft the log, you will have to re-align your engine and coupling using standard procedures. You may find that you have to alternate the two alignments until they are both good.
Doing the alignment(s) significantly reduced the problem for me.
Edit: My mounts are old and soft (or have sagged), and likely contribute to the issue. Under load/torque, I've sure the mounts defect more that new ones.
Chris