[go: up one dir, main page]

0% found this document useful (0 votes)
57 views1 page

Code For PWM: %message Amplitude Must Be Less Than Sawtooth

This code generates a pulse width modulated (PWM) waveform by comparing a message signal to a carrier sawtooth wave. It defines the message and carrier frequencies and amplitudes, generates the message and carrier signals, and uses a for loop to set the PWM waveform to 1 when the message exceeds the carrier and 0 otherwise, effectively encoding the message amplitude into the pulse width of the PWM signal.

Uploaded by

Rohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views1 page

Code For PWM: %message Amplitude Must Be Less Than Sawtooth

This code generates a pulse width modulated (PWM) waveform by comparing a message signal to a carrier sawtooth wave. It defines the message and carrier frequencies and amplitudes, generates the message and carrier signals, and uses a for loop to set the PWM waveform to 1 when the message exceeds the carrier and 0 otherwise, effectively encoding the message amplitude into the pulse width of the PWM signal.

Uploaded by

Rohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Code for PWM

fm=1;
fc=10;
A=5;
t=0:0.001:1;
msg=0.75*A.*sin(2*pi*fm*t);%Message amplitude must be less than Sawtooth
subplot(3,1,1);
plot(t,msg,'Linewidth',4);
xlabel('Time');
ylabel('Amplitude');
title('Message Signal');
carrier=A.*sawtooth(2*pi*fc*t);%Carrier sawtooth
subplot(3,1,2);
plot(t,carrier,':','Linewidth',3);
xlabel('time');
ylabel('Amplitude');
title('Carrier Sawtooth');
n=length(carrier);
for i=1:n%Comparing Message and Sawtooth amplitudes
if (msg(i)>=carrier(i))
pwm(i)=1;
else
pwm(i)=0;
end
end
subplot(3,1,3);
plot(t,pwm,'--','Linewidth',2);
xlabel('time');
ylabel('Amplitude');
title('Pulse Width Modulated Wave');

Waveforms

You might also like