Forum Discussion
Altera_Forum
Honored Contributor
17 years agoHi all,
I have written the following Matlab code to model FM modulation/demodualtion (without upconversion) according to original method. I am sure the second method in the last post should work and be compared. The code should throw some light on the issue of scaling. It is clear that symbols are recovered but their range needs scaling. Hope it is going to help. ******************************* clear all; %generate random zeros and ones symb = round(rand(1,50)); %------------------------------------ %convert symbols to two frequencies(f1,f2) for i = 1:50 if symb(i) == 0 incr(i) = 10; else incr(i) = 20; end end %one cycle sine data lut = exp(2*pi*j*[0:255]*1/256); %modulate using f1,f2 generated with lut pointer from modulo adder k = 1; n = 0; for t = 1:length(incr) for i = 1:64 %upsample symbols by 64 n = n + 1; x(n) = lut(k); k = k + incr(t); if k>256 k=k-256; end;%modulo 256 addition end end %check FM signal spectrum f = linspace(0,1,length(x)); plot(f,20*log10(abs(fft(x)))); %---------------------------------- %---------------------------------- %demodulate I = real(x); I_diff = [diff(I) 0]; Q = imag(x); Q_diff = [diff(Q) 0]; m = (I.*Q_diff - Q.*I_diff)./(I.^2 + Q.^2) ; %m = decimate(m,64); ?? m = m(1:64:end); %decimate by 64 %compare Rx symbols with Tx symbols str = sprintf('%d ',symb); figure; plot(m) title(str) ***********************************