Square wave frequency modulation

10 次查看(过去 30 天)
I am trying to modulate a square wave with a DC value. Simple stuff at least i thought. Basically as the DC value increases so should the frequency of the square wave and it should be represented on graphs. It's not working as intended as the DC value increases. It envolves the use of Fourier. The code follows:
Square wave frequency modulation
% 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. I'm not used to the

采纳的回答

Manikanta Aditya
Manikanta Aditya 2024-4-3
移动:Mathieu NOE 2024-4-3
Hi,
The issue with your code is that you are not actually modulating the frequency of the square wave correctly. The way you are implementing it, you are adding a phase shift to the cosine terms, which does not directly modulate the frequency.
To modulate the frequency of a square wave correctly using a DC value, you need to generate the square wave first, and then modulate its frequency based on the DC value.
% 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 (square wave)
vc = square(2*pi*fc*t);
% Plot carrier signal
figure;
plot(t, vc, 'LineWidth', 2);
xlabel('Time');
ylabel('Amplitude');
title('Carrier Signal (Square Wave)');
ylim([-1.2, 1.2]); % 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
fm_freq = fc + kf * Vdc; % Modulated frequency
v_fm = square(2*pi*fm_freq*t); % Frequency-modulated square wave
% 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([-1.2, 1.2]); % 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
Thanks, hope this helps.
  1 个评论
ashanni sonny
ashanni sonny 2024-4-3
It did I was able to adjust what I did thanks to you. I also gained a better understanding of frequency modulation.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modulation 的更多信息

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by