First, ensure that there are no physical obstructions blocking the Wi-Fi signal and that your iMac is within range of your router. Sometimes, simply repositioning the iMac or the router can improve connectivity.
Next, reset the Wi-Fi configuration on your iMac. You can do this by going to System Preferences > Network. From there, select Wi-Fi from the list on the left, then click the minus (-) button to remove Wi-Fi from the list. After that, click the plus (+) button and add Wi-Fi back to the list. This will reset the Wi-Fi configuration to its default settings.
If that doesn't work, try resetting the System Management Controller (SMC) on your iMac. To do this, shut down your iMac, then press and hold the power button for about 10 seconds. After that, release the power button, wait a few seconds, and then turn on your iMac again.
If the issue persists after trying these steps, it's possible that there may be a hardware problem with your iMac's Wi-Fi card. In that case, I recommend contacting Official Apple Support or visiting an Apple Authorized Service Provider for further assistance. They'll be able to diagnose the issue and provide you with the appropriate solution.