You are on page 1of 4

Lab-1

clear all;

clc;

N=10.^6;

snr_db=0:10;

for k=1:length(snr_db);

tx=round(rand(1,N));

txx=sign(tx-0.5);

snr(k)=10.^(snr_db(k).*0.1);

noise=(randn(1,length(txx)))*sqrt(1/(2*snr(k)));

rxx=txx+noise;

rx=sign(rxx);

rx=sign(rx+1);

error=sum(xor(tx,rx));

ber(k)=error/N;

ber_th(k)=qfunc(sqrt(2*10.^((k-1)/10)));

end

figure(1)

semilogy(snr_db,ber_th,'b-o')

hold on

semilogy(snr_db,ber,'r-x')

xlable('snr in db')

ylable('ber')

legend('theoretical','pratical')
Lab-2

close all; clc

%% Problem

Vm1=20; % Voltage magnitude for v1

Vm2=10; % Voltage magnitude for v2

m=27; % Date of birth

n=11; % Month for birth

f1=n*10; % Frequency for v1

f2=m*10; % Frequency for v2

w1=2*pi*f1; % Frequency for v1 (rad/sec)

w2=2*pi*f2; % Frequency for v2 (rad/sec)

t=0:0.00005:0.04; % Time for plotting signal

v1=Vm1*cos(w1*t); % v1

v2=Vm2*cos(w2*t); % v2

v=v1+v2; % Combination

figure(1)

subplot(3,1,1)

plot(t,v1)

hold on

plot(t,v2)

grid on

xlabel('Time (s)')

ylabel('v_1 and v_2')

title('Voltage waveforms')

legend('v_1','v_2')
subplot(3,1,2)

plot(t,v)

grid on

xlabel('Time (s)')

ylabel('v')

title('Combined waveform')

%% Defining sampling periods

fm=max(f1,f2); % Maximum frequency component

fs1=2*fm; Ts1=1/fs1; % Just same

fs2=3*fm; Ts2=1/fs2; % fs>2fm (satisfying sampling theorem)

fs3=1*fm; Ts3=1/fs3; % fs<2fm (not satisfying sampling theorem)

%% fs>2fm (satisfying sampling theorem)

ts2=0:Ts2:0.04;

v1s2=Vm1*sin(w1*ts2);

v2s2=Vm2*sin(w2*ts2);

vs2=v1s2+v2s2;

subplot(3,1,3)

stem(ts2,vs2)

xlabel('Time (s)')

ylabel('v')

title('Signal sampled with f_s>2f_m')


Lab-3

clear all

clc

fs=1000; %Sampling Frequency

fc=20; %Carrier Frequency

fm=2;%message Frequency

t=1;

n=[0:(1/fs):t];

n=n(1:end-1);

duty=20;

figure()

%%

s=square(2*pi*fc*n,duty)

subplot(2,1,1);plot(s)

s(find(s<0))=0;

%%

m=sin(2*pi*fm*n);

subplot(2,1,2);plot(m)

%% natural Sampling-Pulse Amplitude Modulation

X_S=m.*s;

subplot(2,2,3);plot(X_S)

You might also like