Time scaling matlab code

19 views (last 30 days)
ong jia eek
ong jia eek on 15 Oct 2019
Edited: Sk Group on 25 Oct 2021
%>>>>>>>>>>>>>>>>>>>> Tuterial on AM Modulation <<<<<<<<<<<<<<<<<<<<<<<<<<
clc;
close all;
clear all;
%XXXXXXXXXXXXXXXXXXXXXXXXXXX Define AM modulation Index XXXXXXXXXXXXXXXXXXX
disp(' example: m=1 means 100% modulation');
m=input(' Enter the value of modulation index (m) = ');
%m=1; % for 100% modulation
if (0>m||m>1)
error('m may be less than or equal to one and geter than to zero');
end
%XXXXXXXXXXXXXXXXX modulating signal generation XXXXXXXXXXXXXXXXXXXXXXXXXX
Am =input('Enter the value of amplitude modulation =');
%Am=5; % Amplitude of modulating signal
fa=2000; % Frequency of modulating signal
Ta=1/fa; % Time period of modulating signal
t=0:Ta/999:6*Ta; % Total time for simulation
ym=Am*sin(2*pi*fa*t); % Equation of modulating signal
figure(1)
subplot(3,1,1);
plot(t,ym), grid on;% Graphical representation of Modulating signal
%axis ([0 1 -5 5]);
title ( ' Modulating Signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
%XXXXXXXXXXXXXXXXXXXXX carrier signal generation XXXXXXXXXXXXXXXXXXXXXXXXXX
Ac=Am/m;% Amplitude of carrier signal [ where, modulation Index (m)=Am/Ac ]
fc=fa*10;% Frequency of carrier signal
Tc=1/fc;% Time period of carrier signal
yc=Ac*sin(2*pi*fc*t);% Eqation of carrier signal
subplot(3,1,2);
plot(t,yc), grid on;% Graphical representation of carrier signal
title ( ' Carrier Signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX AM Modulation XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
y=Ac*(1+m*sin(2*pi*fa*t)).*sin(2*pi*fc*t); % Equation of Amplitude
%modulated signal
subplot(3,1,3);
plot(t,y);% Graphical representation of AM signal
title ( ' Amplitude Modulated signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
grid on;
%>>>>>>>>>>>>>>>>>>>>>> end of program <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Question
How to do time scaling in the full AM modulation?
  3 Comments
ong jia eek
ong jia eek on 15 Oct 2019
I want to key in an value of frequency that no matter how much is the frequency, the graph only show 2 cycle
KALYAN ACHARJYA
KALYAN ACHARJYA on 15 Oct 2019
Edited: KALYAN ACHARJYA on 15 Oct 2019
example: m=1 means 100% modulation
Enter the value of modulation index (m) = 0.2
Enter the value of amplitude modulation =4
Where is 2 cycle?

Sign in to comment.

Accepted Answer

Neeraj Kaberpanthi
Neeraj Kaberpanthi on 16 Oct 2019
Edited: Neeraj Kaberpanthi on 16 Oct 2019
Hi,
please refer this corrected code
I have added a new variable 'n' for the number of cycles required @ line number 14 and used it @ line number 18.
%>>>>>>>>>>>>>>>>>>>> Tuterial on AM Modulation <<<<<<<<<<<<<<<<<<<<<<<<<<
clc;
close all;
clear all;
%XXXXXXXXXXXXXXXXXXXXXXXXXXX Define AM modulation Index XXXXXXXXXXXXXXXXXXX
disp(' example: m=1 means 100% modulation');
m=input(' Enter the value of modulation index (m) = ');
%m=1; % for 100% modulation
if (0>m||m>1)
error('m may be less than or equal to one and geter than to zero');
end
%XXXXXXXXXXXXXXXXX modulating signal generation XXXXXXXXXXXXXXXXXXXXXXXXXX
Am =input('Enter the value of amplitude modulation =');
n=input('Enter number of cycles = '); % input for number of modulationd signal cycles
%Am=5; % Amplitude of modulating signal
fa=2000; % Frequency of modulating signal
Ta=1/fa; % Time period of modulating signal
t=0:Ta/999:n*Ta; % Total time for simulation
ym=Am*sin(2*pi*fa*t); % Equation of modulating signal
figure(1)
subplot(3,1,1);
plot(t,ym), grid on;% Graphical representation of Modulating signal
%axis ([0 1 -5 5]);
title ( ' Modulating Signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
%XXXXXXXXXXXXXXXXXXXXX carrier signal generation XXXXXXXXXXXXXXXXXXXXXXXXXX
Ac=Am/m;% Amplitude of carrier signal [ where, modulation Index (m)=Am/Ac ]
fc=fa*10;% Frequency of carrier signal
Tc=1/fc;% Time period of carrier signal
yc=Ac*sin(2*pi*fc*t);% Eqation of carrier signal
subplot(3,1,2);
plot(t,yc), grid on;% Graphical representation of carrier signal
title ( ' Carrier Signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX AM Modulation XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
y=Ac*(1+m*sin(2*pi*fa*t)).*sin(2*pi*fc*t); % Equation of Amplitude
%modulated signal
subplot(3,1,3);
plot(t,y);% Graphical representation of AM signal
title ( ' Amplitude Modulated signal ');
xlabel ( ' time(sec) ');
ylabel (' Amplitud(volt) ');
grid on;
%>>>>>>>>>>>>>>>>>>>>>> end of program <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
--------------------------------------------- Output----------------------------------
example: m=1 means 100% modulation
Enter the value of modulation index (m) = 0.5
Enter the value of amplitude modulation =1
Enter number of cycles = 2
Hope it will help you
  2 Comments
Walter Roberson
Walter Roberson on 3 Feb 2021
That code does not do time scaling at all, and it contains several useless statements in it.

Sign in to comment.

More Answers (1)

Sk Group
Sk Group on 8 Feb 2021
Edited: Sk Group on 25 Oct 2021

Categories

Find more on MATLAB 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!