FM simulation in Python

Asked

Viewed 577 times

1

I study the third semester of electrical engineering, my teacher commented that it is possible to simulate modulations of signals programmatically, I had a brief introduction to programming logic in the course, but I can’t imagine how for example FM radio waves could be simulated within an algorithm, someone has experience with this kind of subject ?

1 answer

2

I can try to help, yes, I assume your teacher talked about simulating demodulation modulation.

such as FM radio waves could be simulated inside a algorithm

Let’s get things clear, the physical laws that govern the universe allow us to transport frequencies in the form of electromagnetic waves, the simplest way I can imagine to explain is that radio waves are just electromagnetic waves that propagate in a vacuum at the speed of light, these waves are created when an antenna disturbs free electrons to oscillate at a desired frequency (frequency of radio station for example), so the current produced by the antenna will create a magnetic field propagating around the antenna, so the induction of an electric field promotes the variation of the magnetic field forming the electromagnetism, I said all this to say that this process is physical and therefore has not much to simulate, but the thing changes of figure when we speak of the process of modulation and demodulation, when we speak of FM=Frequency Modulation we are using nature our favor to place information within a certain frequency range that will carry our data through the air, that is to transport information through a carrier wave (a cosine or sine), we can do this within a program, we can modulate a signal and then dump this signal into an antenna and it is also possible to make the inverse take the signal from an antenna and demodulate within an algorithm, we can also only modulate a signal within a carrier frequency and then demodulate to understand how the process works.

For radio transmission and reception FM commercial has been defined that frequencies should be used between 88 à 108 Mega Hertz, there are some rules, the band used should be 150K Hz (150 thousand hertz), so modulation will occur within this band, a radio transmitting at the frequency of 88Mhertz modulates its frequencies between (88-0.15)=87.85MHz à 88.15MHz=(88+0.15)

I can demonstrate these steps using Matlab:

[m, fs, bits]=wavread('C:\Users\GTI\Desktop\Eder\Python26\tech.wav');

m=m(:,1);


portadora=88*10^6 %FM radio 88Mhz
fsm=((108*10^6)*2);
desvio=75000;


l = length(m);
t = 0:1./fsm:(l-1)./fsm;
int_m = cumsum(m)./fsm;
s = cos((2*pi.*portadora.*t)' + 2*pi.*desvio.*int_m); 

The variable s contains its modulated signal within the carrier frequency, in this case 88MHz, now we can plot this modulated signal and check how the signal looks in the frequency domain:

lolu=fft(s);
Nyquist = fsm / 2;
MinFrequency=Nyquist / (length(lolu) / 2);
Frequency=((MinFrequency):MinFrequency:Nyquist);
plot(Frequency, abs(lolu(1:length(lolu)/2)))

inserir a descrição da imagem aqui

And every time I do this I find it incredible lol, OK the simulation is not perfect you can notice that the deviation overflowed the desired band 150Khz, but there is 88MHz with the modulations around it.

But now to catch the signal s and back to the original signal (demodulation process), we can simulate again:

ini_phase = 0;
len = size(s,1);
if(len==1)
    s = s(:);
end


t = (0:1/fsm:((size(s,1)-1)/fsm))';
t = t(:,ones(1,size(s,2)));

yq = hilbert(s).*exp(-sqrt(-1)*2*pi*portadora*t-ini_phase);
z = (1/(2*pi*desvio))*[zeros(1,size(yq,2)); diff(unwrap(angle(yq)))*fsm];

% --- restore the output signal to the original orientation --- %
if(len == 1)
    z = z';
end

plot(z)

If all went well you can give one play in the variable z and listen to your signal back...

This made me imagine that it would be possible to build a device that listens to the radio spectrum band and sweeps all available radios to its region in real time and is demonstrated in the lol frequency spectrum...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.