Square wave frequency modulation

ThemeCopy

% Define parameters

t = linspace(0, 1, 1000); % Time vector

fc = 5; % Fundamental frequency (Hz)

kf = 0.1; % Frequency deviation constant

Vc = 1; % Amplitude of the carrier signal

Vdc_values = [0, 5, 10]; % Values of Vdc for the DC signals

% Generate carrier signal

vc = Vc/2;

for k = 1:2:10000

vc = vc + (2*Vc/(pi*k)) * cos(2*pi*k*fc*t - 90*pi/180);

end

% Plot carrier signal

figure;

plot(t, vc, 'LineWidth', 2);

xlabel('Time');

ylabel('Amplitude');

title('Carrier Signal for Frequency Modulation');

ylim([0, 1]); % Adjust ylim as needed

grid on;

% Frequency domain parameters

fs = 1000; % Sampling frequency

f = linspace(0, fs, 1000); % Frequency vector

% Generate and plot frequency-modulated signals separately for each Vdc

for i = 1:length(Vdc_values)

Vdc = Vdc_values(i);

% Generate frequency-modulated signal

v_fm = Vc/2;

for k = 1:2:1000

v_fm = v_fm + (2*Vc/(pi*k)) * cos(2*pi*2*k*fc*t - 90*pi/180 + 2*pi*kf*Vdc*t);

end

% Compute Fourier transform of frequency-modulated signal

V_fm = abs(fft(v_fm));

% Plot frequency-modulated signal in the time domain

figure;

subplot(2, 1, 1);

plot(t, v_fm, 'LineWidth', 2);

xlabel('Time');

ylabel('Amplitude');

title(['Frequency-Modulated Signal with Vdc = ', num2str(Vdc), ' (Time Domain)']);

ylim([0, 1]); % Adjust ylim as needed

grid on;

% Plot frequency-modulated signal in the frequency domain

subplot(2, 1, 2);

plot(f, V_fm, 'LineWidth', 2);

xlabel('Frequency (Hz)');

ylabel('Magnitude');

title(['Frequency-Modulated Signal with Vdc = ', num2str(Vdc), ' (Frequency Domain)']);

xlim([0, 200]); % Adjust xlim as needed

grid on;

end

As you can see as Vdc increases the signal breaks down.