Search This Blog

Thursday 29 October 2015

PWM

clc;
clear all;
close all;
F2=input('Message frequency=');
F1=input('Carrier Sawtooth frequency=');
A=5;
t=0:0.001:1;
c=A.*sawtooth(2*pi*F1*t);%Carrier sawtooth
subplot(3,1,1);
plot(t,c);
xlabel('time');
ylabel('Amplitude');
title('Carrier sawtooth wave');
grid on;
m=0.75*A.*sin(2*pi*F2*t);%Message amplitude must be less than Sawtooth
subplot(3,1,2);
plot(t,m);
xlabel('Time');
ylabel('Amplitude');
title('Message Signal');
grid on;
n=length(c);%Length of carrier sawtooth is stored to ‘n’
for i=1:n%Comparing Message and Sawtooth amplitudes
if (m(i)>=c(i))
    pwm(i)=1;
else
    pwm(i)=0;
end
end
subplot(3,1,3);
plot(t,pwm);
xlabel('Time');
ylabel('Amplitude');
title('plot of PWM');
axis([0 1 0 2]);%X-Axis varies from 0 to 1 & Y-Axis from 0 to 2
grid on;

BFSK


clc;
clear all;
close all;
fc1=input('Enter carrier frequency for binary 1: ');
fc2=input('Enter carrier frequency for binary 0: ');
fs=input('Enter sampling frequency: ');
bs=input('Enter bit sequence: ');
L1=length(bs);
I=[];
for i=1:L1
    I=[I bs(i)*ones(1,fs)];
end
L2=length(I);
t=(10/L2):(10/L2):10;
C1=sin(2*pi*fc1*t);
C2=sin(2*pi*fc2*t);
BFSK=[];
for i=1:L2
    if I(i)==1
        BFSK=[BFSK C1(i)];
    else
        BFSK=[BFSK C2(i)];
    end
end
R=[];
for l=1:length(BFSK)
    if BFSK(l)==C1(l)
        R=[R 0];
    elseif BFSK(l)==C2(l)
        R=[R 1];
    end
end
subplot(5,1,1); plot(t,I);
xlabel('Time'); ylabel('Levels'); title('Bit sequence');
subplot(5,1,2); plot(t,C1);
xlabel('Time'); ylabel('Amplitude'); title('Carrier wave for binary 1');
subplot(5,1,3); plot(t,C2);
xlabel('Time'); ylabel('Amplitude'); title('Carrier wave for binary 0');
subplot(5,1,4); plot(t,BFSK);
xlabel('Time'); ylabel('Amplitude'); title('BFSK signal');
subplot(5,1,5); plot(t,R);
xlabel('Time'); ylabel('Levels'); title('Demodulated signal'); 

BPSK


clc;
clear all;
close all;
fc=input('fc=');
fs=input('fs=');
bit=input('Bit sequence=');
L1=length(bit);
I=[];
for i=1:L1
    I=[I bit(i)*ones(1,fs)];
end
L2=length(I);
t=(10/L2):(10/L2):10;
subplot(5,1,1); plot(t,I);
xlabel('Time'); ylabel('Level'); title('Bit sequence');
I(I==0)=-1;
C=sin(2*pi*fc*t);
BPSK=I.*C;
DPSK=BPSK.*C;
L3=length(BPSK);
r=[];
for i=1:L3
    if DPSK(i)>0
        r=[r 1];
    else
        r=[r 0];
    end
end
subplot(5,1,2); plot(t,I);
xlabel('Time'); ylabel('Level'); title('Bit sequence');
subplot(5,1,3); plot(t,C);
xlabel('Time'); ylabel('Amplitude'); title('Carrier signal');
subplot(5,1,4); plot(t,BPSK);
xlabel('Time'); ylabel('Amplitude'); title('BPSK signal');
subplot(5,1,5); plot(t,r);
xlabel('Time'); ylabel('Level'); title('Original sequence');

BASK


clc;
clear all;
close all;
fs=input('fs=');
fc=input('fc=');
bs=input('Bit sequence=');
L=length(bs);
A=[];
for i=1:L
    A=[A bs(i)*ones(1,fs)];
end
L1=length(A);
t=(10/L1):(10/L1):10;
C=sin(2*pi*fc*t);
BASK=C.*A;
subplot(2,2,1); plot(t,A); xlabel('Time'); ylabel('Level');
title('Bit sequence');
subplot(2,2,2); plot(t,C); xlabel('Time'); ylabel('Amplitude');
title('Carrier signal');
subplot(2,2,3); plot(t,BASK); xlabel('Time'); ylabel('Amplitude');
title('BASK Signal');
L2=length(BASK);
r=[];
for i=1:(L2/fs)
    if sum(abs(BASK((i-1)*fs+1:i*fs)),2)
        r=[r ones(1,fs)];
    else
        r=[r zeros(1,fs)];
    end
end
subplot(2,2,4); plot(t,r); xlabel('Time'); ylabel('Level');
title('Demodulated bit sequence')

FREQUENCY MODULATION



fs=input('enter the value of sampling frequency'); fc=input('enter the value of carrier frequency'); fm=input('enter the value of modulating frequency'); t=0:(1/fs):2; m=10;
X=sin(2*pi*fm*t);
C=sin(2*pi*fc*t);

FM=sin((2*pi*fc*t)+m*sin(2*pi*fm*t)); subplot(3,1,1); plot(t,X); xlabel('time'); ylabel('frequency'); title('modulating signal'); subplot(3,1,2); plot(t,C); xlabel('time'); ylabel('frequency'); title('carrier signal'); subplot(3,1,3); plot(t,FM); xlabel('time'); ylabel('frequency'); title('frequency modulated signal'); 

AMPLITUDE MODULATION AND DEMODULATION



fs=input('enter the value of sampling frequency'); fc=input('enter the value of carrier frequency'); fm=input('enter the value of modulating frequency'); t=0:(1/fs):2;
A=cos(2*pi*fm*t); m1=1; opt=(-1)/m1;
AM=modulate(A,fc,fs,'amdsb-tc',opt); AM3=demod(AM,fc,fs,'amdsb-tc',opt); m2=0.9; opt=(-1)/m2;
AM1=modulate(A,fc,fs,'amdsb-tc',opt); AM4=demod(AM1,fc,fs,'amdsb-tc',opt); m3=1; opt=(-1)/m3;
AM2=modulate(A,fc,fs,'amdsb-tc',opt); AM5=demod(AM2,fc,fs,'amdsb-tc',opt);
subplot(3,3,1); plot(t,A); xlabel('time'); ylabel('amplitude'); title('modulating signal'); subplot(3,3,2); plot(t,AM); xlabel('time'); ylabel('amplitude'); title('AM for m=1 signal'); subplot(3,3,3); plot(t,AM1); xlabel('time'); ylabel('amplitude'); title('AM for m<1 signal'); subplot(3,3,4); plot(t,AM2); xlabel('time'); ylabel('amplitude'); title('AM for m>1 signal'); subplot(3,3,5); plot(t,AM3); xlabel('time'); ylabel('amplitude'); title('demodulating signal for m=1');
subplot(3,3,6); plot(t,AM4); xlabel('time'); ylabel('amplitude'); title('demodulating signal for m<1');

subplot(3,3,7); plot(t,AM5); xlabel('time'); ylabel('amplitude'); title('demodulating signal for m>1'); 

Wednesday 28 October 2015

PROGRAM TO CREATE HOUSE STRUCTURE WITH APPLET

import java.awt.*;
import java.applet.*; 
public class House extends Applet {
            public void paint(Graphics g) {
                        g.drawLine(100,10,10,90);
                        g.drawLine(100,10,400,10);
                        g.drawLine(400,10,490,90);
                        g.drawLine(10,90,490,90);
                        g.drawLine(60,90,60,270);
                        g.drawLine(435,90,435,270);
                        g.drawLine(130,150,130,270);
                        g.drawLine(200,150,200,270);
                        g.drawLine(130,150,200,150);
                        g.drawLine(280,150,280,210);
                        g.drawLine(350,150,350,210);
                        g.drawLine(280,150,350,150);
                        g.drawLine(280,210,350,210);
            }
}
/*<applet code=House.class width=500 height=500></applet>*/