Skip to content

Instantly share code, notes, and snippets.

@juanbono
Created May 5, 2016 07:36
Show Gist options
  • Save juanbono/327d5266903c3d81133593dbd3747097 to your computer and use it in GitHub Desktop.
Save juanbono/327d5266903c3d81133593dbd3747097 to your computer and use it in GitHub Desktop.
% Borrar todo de la consola %
clc;
clear all;
close all;
fm = input('Frecuencia mensaje = ');
fc = input('Frecuencia funcion sierra = ');
A = input('Amplitud funcion sierra = ');
tmax = input('Tiempo = ');
t = 0:0.001:tmax; % Rango del tiempo - entre 0 y un tiempo maximo %
c = A.*sawtooth(2*pi*fc*t); % Funcion sierra %
subplot(3,1,1);
plot(t,c);
xlabel('Tiempo');
ylabel('Amplitud');
title('Funcion Sierra');
grid on;
m = A.*sin(2*pi*fm*t); % Funcion mensaje %
subplot(3,1,2);
plot(t,m);
xlabel('Tiempo');
ylabel('Amplitud');
title('Funcion Mensaje');
grid on;
n = length(c);
for i = 1:n % Se comparan las amplitudes para armar la pwm %
if (m(i)>=c(i))
pwm(i)=1;
else
pwm(i)=0;
end
end
subplot(3,1,3);
plot(t,pwm);
xlabel('Tiempo');
ylabel('Amplitud');
title('PWM');
axis([0 tmax 0 2]); % Para variar los ejes del grafico de pwm %
grid on;
% Parte para ver ppm %
for i = 1:n
if (pwm(i)==0)
ppm(i)=1;
end
end
subplot(3,2,1)
plot(t,ppm);
xlabel('Tiempo');
ylabel('Amplitud');
title('PPM');
axis([0 tmax 0 2]); % Para variar los ejes del grafico de pwm %
grid on;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment