The Ran (at the end of Meseches Pesachim) quotes a Midrash, which states that Sefiras HaOmer commemorates the anticipation of our ancestors for maamad Har Sinai.
Hashem told Moshe Rabbeinu, “When you take out the Jewish people, you should service Almighty G-d on this mountain” (Shemos 3:12). Moshe related this message to the Jewish people and explained that they would receive the Torah. When they heard the news, says the Midrash, they asked Moshe, “When will this take place?” He said to them, “At the end of 50 days.”
Every Jew then started counting for himself the days left to receiving the Torah. Therefore, the Sages instituted Sefiras HaOmer to reflect our ancestors’ love and excitement in the days leading up to the giving of the Torah.
The Lubavitcher Rebbe notes that this explanation is also found in the Mateh Moshe (vol. 5, siman 685) and Avudraham (Hilchos Sefiras HaOmer). In these sources, an explanatory allegory is provided as well:
A person is sitting in a dungeon, rachmana litzlan, and doesn’t know when, or if, he will get out. Suddenly, he receives a message from the king himself that not only is the king going to take him out of jail, he will also give him his daughter as a wife. And he tells him in how many days both these events will take place.
You can imagine how great this person’s joy would be upon hearing this news and how he would count the days to his release from prison and his marriage to the princess.
This allegory helps us understand what Sefiras HaOmer is about:
The Jewish people were under harsh enslavement in Egypt. We couldn’t even begin to think about our redemption. All of a sudden, Almighty G-d says to Moshe Rabbeinu, “Go and take out the Jewish people. And not only will I release them from bondage in Egypt, I am going to give them my daughter, the Torah, my precious treasure!”
We were ecstatic when we heard the news. We were going to leave Egypt and receive the Torah and be together in happiness and in fulfillment for all of eternity.
This allegory fits the esoteric explanation that “sefirah” comes from the word “sapir” – a diamond. Every single day of the 49 days of Sefiras HaOmer, we polish and cause to shine another part of our evil inclination, the yetzer harah. We polish all seven of our emotional attributes – chessed, gevurah, tiferes (benevolence, strength, beauty), etc. – and also attend to them as they interact with each other in the form of 7×7, reaching the number of 49.
At that point, all our attributes belong in the category of “sapir” and shine and sparkle. And that, in turn, enables us to receive the Torah in the way expressed by the sixth Lubavitcher Rebbe: “kabalas haTorah besimcha uvipnimius” – receiving the Torah with happiness and inner meaning.