项目作者: Theerapong

项目描述 :
Modulations in Matlab
高级语言:
项目地址: git://github.com/Theerapong/Modulations-in-Matlab.git
创建时间: 2019-04-09T18:44:35Z
项目社区:https://github.com/Theerapong/Modulations-in-Matlab

开源协议:Apache License 2.0

下载


(This project was a part of studying at Kingston University, London)

Modulations on Matlab R2019a (here is source code as well)

%%% Modulations on Matlab …..

%% Made on March 2019 …..

%% The first section from Teacher, and then by me

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear

close all

  1. %-----------------------------------
  2. %-------- AM in class room ---------
  3. %-----------by Teacher--------------

samplingRate = 10000; % sampling-rate or sampling-frequency , Fs = 10000

%samplingRate = 1000; % sampling-rate or sampling-frequency , Fs = 10000

carrierFrequency = 1000;

%t = 0 : 1/samplingRate : 1;

x1 = zeros(1,21); % value 0

x2 = ones(1,20); % value 1

x3 = 2*x2; % value 2

x4 = 3*x2; % value 3

x5 = zeros(1,20); % value 0

x1(x1==0) = 0 ;

x2(x2==1) = 0.25 ;

x3(x3==2) = 0.5 ;

x4(x4==3) = 0.75 ;

x5(x5==0) = 0 ;

  1. %-----------------------------------
  2. %--------- New Application ---------
  3. %-----by Theerapong Kulawong--------

%newMessage = [“00”,”01”,”10”,”11”,”00”];

%newMessage = [“00”,”01”,”10”,”10”,”11”];

newMessage = [“00”,”01”,”11”,”10”,”01”];

if ( strcmp(newMessage(1),”00”) )
newSignal = x1; %0
elseif ( strcmp(newMessage(1),”01”) )
newSignal = x2; %1
elseif ( strcmp(newMessage(1),”10”) )
newSignal = x3; %2
else
newSignal = x4; %3
end

for i=2 : 5
if ( strcmp(newMessage(i),”00”) )
newSignal = cat(2,newSignal,x5); %0
elseif ( strcmp(newMessage(i),”01”) )
newSignal = cat(2,newSignal,x2); %1
elseif ( strcmp(newMessage(i),”10”) )
newSignal = cat(2,newSignal,x3); %2
else
newSignal = cat(2,newSignal,x4); %3
end
end

subplot(7,2,1); plot(newSignal,’g’); title(‘New Message’); ylabel(‘(Amplitude)’);

  1. %-----------------------------------
  2. %---------------- AM ---------------
  3. %-----------------------------------

newAM = modulate(newSignal,carrierFrequency,samplingRate,’AM’);

subplot(7,2,3); plot(newAM,’b’); title(‘AM’);

demodAM = demod(newAM,carrierFrequency,samplingRate,’AM’);

subplot(7,2,5); plot(demodAM,’b’); title(‘AM Demodulation’);

  1. %-----------------------------------
  2. %----------------- PM --------------
  3. %-----------------------------------

newPM = modulate(newSignal,carrierFrequency,samplingRate,’PM’);

subplot(7,2,4); plot(newPM,’b’); title(‘PM’);

demodPM = demod(newPM,carrierFrequency,samplingRate,’PM’);

subplot(7,2,6); plot(demodPM,’b’); title(‘PM Demodulation’);

  1. %-----------------------------------
  2. %--------------- PPM ---------------
  3. %-----Pulse-position modulation-----

modPPM = modulate(newSignal,carrierFrequency,samplingRate,’ppm’);

subplot(7,2,7); plot(modPPM,’r’);title(“PPM”);

demodPPM=demod(modPPM,carrierFrequency,samplingRate,’ppm’);

subplot(7,2,9); plot(demodPPM,’r’);title(“PPM Demodulation”);

  1. %-----------------------------------
  2. %---------- PWM Modulation----------
  3. %-------Pulse-width modulation------

modPWM = modulate(newSignal,carrierFrequency,samplingRate,’pwm’,’centered’) ;

subplot(7,2,8); plot(modPWM,’r’); title(‘PWM’);

demodPWM = demod(modPWM,carrierFrequency,samplingRate,’pwm’,’centered’) ;

subplot(7,2,10); plot(demodPWM,’r’); title(‘PWM Demodulation’);

  1. %-----------------------------------
  2. %---------- QAM Modulation ---------
  3. %-Quadrature amplitude modulation---

newQAM = modulate(newSignal,carrierFrequency,samplingRate,’qam’,newSignal);

subplot(7,2,11); plot(newQAM); title(‘QAM’);

demodQAM = demod(newQAM,carrierFrequency,samplingRate,’qam’,newSignal);

subplot(7,2,13); plot(demodQAM); title(‘QAM Demodulation’);

xlabel(‘(Time)’);