0

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 Answers1

1

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

AboAmmar
  • 5,439
  • 2
  • 13
  • 24
  • Thanks but I'm looking for FSK modulation not FM modulation, and I want to use my built-in function not ready functions. – Phillip A. Hendrick Jul 27 '22 at 18:07
  • OK, I'm on phone, will come back after a while. – AboAmmar Jul 27 '22 at 19:24
  • 1
    @PhillipA.Hendrick FM modulation with a square wave as modulator is essentially FSK, isn't it? – Luis Mendo Jul 27 '22 at 22:28
  • @AboAmmar But I want to use carrier frequency 400 and delta f as f/2 which is 15. your modulation doesn't have this frequencies. – Phillip A. Hendrick Jul 30 '22 at 15:17
  • You can choose whatever value for delta f, but that will allow for abrupt phase changes (discontinuities) in the modulated signal. As I said, their is a condition for Continuous-Phase FSK. Refer to the book "Digital Communications" by Bernard Sklar, e.g., for details. – AboAmmar Jul 30 '22 at 15:36