Sorry to hear about your train noise problem Kat.
I looked it up, and it turns out that there is something called Train Code, which is a Morse Code like form of communication and the reason for their long seemingly random sequences of blows.
Train whistle - Wikipedia, the free encyclopedia
When you're bored, you should try decoding the horn blows. You could also test it to see if they are really using Morse Code (which would be ridiculous because I mean... we've got cheap cell phones and radios everywhere in our modern age)
I live near tracks too, actually... I live near a junction where trains go to park and take turns entering and exiting. I suggest looking on a map to see if there is anything significant about your area... and when you move again, try to avoid this problem altogether. I suggest Google Maps or Google Earth... it's a really spectacular program. I even used it's street view feature to get a photo of my house before I went to look at and rent it!
Personally, I thought I'd be annoyed by trains when I moved here... but I'm really not. I ignore them pretty well, and if I'm trying to focus I got a pair of large ear-muff like headsets to blast comforting music (or alternatively, Disturbed depending on my mood or activity lol)...
It kinda makes me wonder... I'm very wary of riding my motorized bike at night. It's really loud, so I keep my journeys brief that night if I have to go somewhere. There is always a bright sunny day for recreational riding... no sense in being a menace.