FSK modulation matlab code is not working as expected

389 Views Asked by At

This is my code for generating a TTL wave with frequency 30 Hz and modulate it with FSK and carrier frequency 400

f=30;
T = 1/f; 
t = linspace(0, T*10, 1000);
y = (1/2)*square(t/T*2*pi)+(1/2);
plot(t, y);
hold on;
fc=400;
df=20;
y_m = cos(2.*pi.*(fc+(2.*y).*df).*t);
plot(t,y_m);
hold off;

and this is the result: Result

First of all, I have phase discontinuity when TTL changes from 0 to 1 or viser versa, and the second problem is that the domain of modulated signal is not the same every where and it changes...

How Can I solve these problems?

1

There are 1 best solutions below

5
AboAmmar On

For solving the problem of discontinuities, you should make sure the condition for Continuous-Phase FSK (CPFSK) is met; that's the frequency deviation in rad/s should be an integral multiple of pi/T, which translates into 1/2T in Hz. If you choose arbitrary values for Δf, you should expect discontinuities.

For the second problem of non-constant amplitude, you should increase the number of points for the cosine calculation to be smooth enough.

clear, close
f = 30;
T = 1/f; 
t = linspace(0, T*5, 10000);
y = 1/2 * square(t/T*2*pi) + 1/2;
plot(t, y, "LineWidth", 1);
hold on;
fc = 400;
df = 20;
y_m = cos(2*pi*(fc+y*df/T) .* t);
plot(t, y_m, "LineWidth", 1);
axis tight
ylim([-1.2 1.2])
hold off

enter image description here