Square wave frequency modulation

조회 수: 15 (최근 30일)
ashanni sonny
ashanni sonny 2024년 4월 3일
댓글: ashanni sonny 2024년 4월 3일
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