This paper presents an optimal detector for spatial modulation (SM) that outperforms existing methods by achieving a significant bit error probability gain and reduced complexity. The proposed detection method, which involves joint optimization, shows improved performance compared to traditional MIMO techniques like V-BLAST and maximum ratio combining (MRC). The study includes simulation results confirming the advantages of the optimal SM detector for future wireless communication systems.