Wednesday, April 3, 2013

Sine Wave to Square Wave conversion using MATLAB


%60Hz sine wave to 20Hz square wave conversion
clear all;
close all;
clc;
fm=input('enter msg frequency fm=');
fr=input('enter mult frequency fr=');
fs=2000;
t=0:1/fs:0.2;
x=5*sin(2*pi*fm*t);
f=(fm-fr);
y=5*sin(2*pi*t*f);
for i=1:401
if(y(i)>=0)
    s(i)=+5
else
    s(i)=-5
end
end

subplot(311);
plot(x,'-','linewidth',1);

title('60Hz sine wave','fontsize',12);
xlabel('--->time in 0.5ms');
ylabel('--->Volts');
subplot(312);
plot(y,'g','linewidth',1.5);

title('20Hz sine wave','fontsize',12);
xlabel('--->time in 0.5ms');
ylabel('--->Volts');
subplot(313);
plot(s,'r','linewidth',1.5);

title('20Hz square wave','fontsize',12);
xlabel('--->time in 0.5ms');
ylabel('--->Volts');




RESULT:

No comments:

Post a Comment

comment here