MATLAB program for PWM signal generation

Program Code
% PWM Signal Generation
clc;
close all;
clear all;
t=0:0.001:1;
s=sawtooth(2*pi*10*t+pi);
m=0.75*sin(2*pi*1*t);
n=length(s);
for i=1:n
    if (m(i)>=s(i))
        pwm(i)=1;
    elseif (m(i)<=s(i))
        pwm(i)=0;
    end
end
plot(t,pwm,'-g',t,m,'--r',t,s,'--b');
grid on;
ylabel('Amplitude');
xlabel('Time index');
title('PWM Wave');
axis([0 1 -1.5 1.5]);



Output

_________________

If you find this program code useful, then please deposit 5 Indian Rupees in my bank account, as my fee. (Citizens of Pakistan cannot do this.).
I am the woman who wrote this program code.
My name: Anju K.
My bank account number: 30221619108
Bank: State Bank of India, Chakkarakkal branch, India.
IFSC code: SBIN0070728
SWIFT code: SBININBB
BIC code: SBININBB
My email: tc9749@gmail.com .


MATLAB program for FM signal generation

Program Code
% FM signal generation
clc;
close all;
clear all;
fc=input('Please enter the carrier signal frequency in Hz,fc=');
fm=input('Please enter the modulating signal frequency in Hz,fm=');
m=input('Modulation index,m=');
n=0:0.0001:.1;
c=sin(2*pi*fc*n);
M=sin(2*pi*fm*n);
subplot(311);
plot (n,c);
ylabel('Amplitude');
xlabel('Time index');
title('Carrier signal ');
subplot(312);
plot (n,M);
ylabel('Amplitude');
xlabel('Time index');
title('Modulating Signal');
y=sin(2*pi*fc*n+(m.*sin(2*pi*fm*n)));
subplot(313);
plot (n,y);
ylabel('Amplitude');
xlabel('Time index');
title('Frequency Modulated signal');



Example of Output
Please enter the carrier signal frequency in Hz,fc=1000
Please enter the modulating signal frequency in Hz,fm=250

Modulation index,m=2


____________________________

If you find this program code useful, then please deposit 5 Indian Rupees in my bank account, as my fee. (Citizens of Pakistan cannot do this.).
I am the woman who wrote this program code.
My name: Anju K.
My bank account number: 30221619108
Bank: State Bank of India, Chakkarakkal branch, India.
IFSC code: SBIN0070728
SWIFT code: SBININBB
BIC code: SBININBB
My email: tc9749@gmail.com .


MATLAB program for AM signal generation

Program Code
clc;
close all;
clear all;
% AM signal generation
fc=input('Please enter the carrier signal frequency in Hz,fc=');
fm=input('Please enter the modulating signal frequency in Hz,fm=');
m=input('Modulation index,m=');
n=0:0.001:1;
c=sin(2*pi*fc*n);
M=sin(2*pi*fm*n);
y=(1+m*M).*c;
subplot(211);
plot (n,y);
ylabel('Amplitude');
xlabel('Time index');
title('Amplitude Modulated signals');
y1=M.*c;
subplot(212);
plot(n,y1);
ylabel('Amplitude');
xlabel('Time index');
title('supressed Carrier');




Example of Output
Please enter the carrier signal frequency in Hz,fc=50
Please enter the modulating signal frequency in Hz,fm=5
Modulation index,m=.5

__________________________

If you find this program code useful, then please deposit 5 Indian Rupees in my bank account, as my fee. (Citizens of Pakistan cannot do this.).
I am the woman who wrote this program code.
My name: Anju K.
My bank account number: 30221619108
Bank: State Bank of India, Chakkarakkal branch, India.
IFSC code: SBIN0070728
SWIFT code: SBININBB
BIC code: SBININBB
My email: tc9749@gmail.com .