clear all; close all, clc;
% this clears your workspace, closes all figures, and clears command window
% This script demonstrates how to use MATLAB to generate
% a simple signal plot. In this example, we construct
% and plot a signal x(t)=exp(-t)sin(6*pi*t)u(t+1)
% To graph a signal, the first step is to determine
% the t-axis and the x-axis to plot
% We can first decide the length of t-axis to plot
t=[-2:0.01:3]; % "t" is from -2 to 3 in 0.01 increment
% Then evalute the signal over the range of "t" to plot
%x = exp(-t).*sin(6*pi*t).*ustep(t+1);
%%1
%x = triangle(t).*sin(6*pi*t);
%%2
x = exp(-t/2).*rect(t+1).*sin(12*pi*(t+1))+triangle(t-1).*sin(6*pi*(t-1));
%%3
figure(1); fig1=plot(t,x); % plot t vs x in figure 1
set(fig1,'Linewidth',2); % choose a wider line-width
xlabel('\it t'); % use italic 't' to label t-axis
ylabel('{\bf x}({\it t })'); % use boldface 'x' to label x-axis
title('{\bf x}_{\rm time domain}');
% ustep.m implements the unit step function u(t)
% rect.m implements the standard rectangular function rect(t)
% triangle.m implements standard triangle function triangle(t)
% Quadrature Amplitude Modulation
clc; clear all; close all;
fc = 40; % Carrier frequency in Hz
fm1 = 2; % Modulating frequency in Hz
fm2 = 5 % Modulating frequency in Hz
Fs = 1000; % Sampling frequency in Hz
t=0:1/Fs:1;
m1=cos(2*pi*fm1*t)+2*cos(3*pi*fm1*t); % Message signal 1
m2=cos(2*pi*fm2*t)+2*cos(5*pi*fm2*t); % Message signal 2
c1=cos(2*pi*fc*t); % In-phase carrier signal
c2=sin(2*pi*fc*t); % Quadrature-phase carrier signal
% Modulation
x1=m1.*c1; % Modulated signal 1
x2=m2.*c2; % Modulated signal 2
x=x1+x2;
%Demodulation
y = x.*cos(2*pi*fc*t);
[num,den] = butter(5,2*fc/Fs); % IIR lowpass filter
y = filtfilt(num,den,y)*2; % Demodulated signal
z = x.*sin(2*pi*fc*t);
[num,den] = butter(5,2*fc/Fs); % IIR lowpass filter
z = filtfilt(num,den,z)*2; % Demodulated signal
% plots
figure(1),
subplot(321); plot (t,m1)
ylabel('Amplitude'); xlabel('Time');
title('Message signal 1');
%
subplot(322); plot (t,m2)
ylabel('Amplitude'); xlabel('Time');
title('Message signal 2');
%
subplot(323); plot (t,c1)
ylabel('Amplitude'); xlabel('Time');
title('Carrier signal');
%
subplot(324); plot (t,x)
ylabel('Amplitude'); xlabel('Time');
title('QAM signal');
subplot(325); plot (t,y)
ylabel('Amplitude'); xlabel('Time');
title('QAM demodulated signal 1');
subplot(326); plot (t,z)
ylabel('Amplitude'); xlabel('Time');
title('QAM demodulated signal 2');