Amplitude modulation with a square wave as the message signal

11 views (last 30 days)
Dear all,
Hi,
I have written some codes which produce the output I want,as follow
{
clc;
clear all;
N = 1024; %N point FFT N>fc to avoid freq domain aliasing
fs = 4096; % sample frequency
t = (0:N-1)/fs;
fc = 280e6; %Carrier Frequency
fm = 100; %Three message signal frequencies
Ec = 20; %Carrier Amplitude
Em = 5;
A = Ec + Em*sin(2*pi*fm*t);
n=Ec*sin(2*pi*fc*t);
m=1+Em/2.*square(2*pi*fm*t)+(Em/2);
subplot(2,1,1);
plot(t,m);
xlabel('Time');
ylabel('Amplitude');
title('Message Signal');
grid on;
subplot(2,1,2);
plot(t,n);
xlabel('Time');
ylabel('Amplitude');
title('Carrier Signal');
grid on;
k=n.*m;
k( k<0 )=0;
Mf = 2/N*abs(fft(k,N));
f = fs * (0 : N/2) / N;
close all;
figure('Name','Time/Fequency domain representations of DSB-AM signals');
subplot(3,1,1); %Time domain plot
plot(t(1:N/2),k(1:N/2),t(1:N/2),k(1:N/2),'r',t(1:N/2),-k(1:N/2),'r');
title('Time Domain Representation');
xlabel('Time'); ylabel('Modulated signal');
subplot(3,1,2); %Time domain plot
plot(t(1:N/2),k(1:N/2),t(1:N/2),k(1:N/2),'r');
title('Time Domain Representation');
xlabel('Time'); ylabel('Modulated signal');
subplot(3,1,3); %Frequency Domain Plot
plot(f(1:256),Mf(1:256));
title('Frequency Domain Representation');
xlabel('Frequency (Hz)'); ylabel('Spectral Magnitude');
}
Now I want to replace 'm' signal with the following code,
{
t = 0:.1:20;
y = zeros(20,length(t));
x = zeros(size(t));
for k = 1:2:39
x = x + sin(k*t)/k;
y((k+1)/2,:) = x;
end
plot(t,y);
title('The building of a square wave')
}
But,cant squeeze it in correctly. I'm tired of looking at it now, would you please help me on that. I appreciate your help.
BW, S.

Accepted Answer

S
S on 19 Mar 2015
It's been done!

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!