Probably the best approach is to buy an AD9580 module
e.g.
and inject its output into where the crystal on the HC-SR04 is currently provides the frequency
You'd need to figure out what frequency the crystal is and how to inject the signal i.e remove the crystal and inject via a suitable capacitor, I it would probably work.
There is code on the web to control the AD9850 and it has a 0Hz to 40Mhz output range in less than 1Hz steps, so I can't see how that would not be able to give you the sorts of frequencies that would be required for something that operates at 40kHz
BTW. If you don't have an oscilloscope, you may need to borrow one, it may be hard to do it without being able to measure the frequencies and voltages around the crystal