0% found this document useful (0 votes)
9 views16 pages

BPSK Merged (1) Removed

The document contains MATLAB code for generating and analyzing signals, including a 100 Hz sine wave, BPSK, and FSK signals, as well as performing FFT and IFFT operations. It includes visualizations of original, quantized signals, quantization errors, and demodulated data. The author is Ritik Chaudhary, with enrollment number 23103198.

Uploaded by

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

BPSK Merged (1) Removed

The document contains MATLAB code for generating and analyzing signals, including a 100 Hz sine wave, BPSK, and FSK signals, as well as performing FFT and IFFT operations. It includes visualizations of original, quantized signals, quantization errors, and demodulated data. The author is Ritik Chaudhary, with enrollment number 23103198.

Uploaded by

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

disp('NAME :- RITIK CHAUDHARY');

disp('ENROLL :- 23103198');

clc;
close all;
clear all;

disp('Generate 0.02-second sine wave of 100 Hz');

amp = 4;
fs = 3200;
nbits = 4;

T = 1/fs;
t = 0:T:0.02;

sig1 = amp * sin(2 * pi * 100 .* t);

min_sig = min(sig1);
max_sig = max(sig1);

sig = sig1;

quint_level = 2^nbits;
s = (max_sig - min_sig) / quint_level;

for jj = min_sig:s:max_sig
sig(sig <= jj + s & sig >= jj) = ((2 * jj) + s) / 2;
end

figure;

subplot(2,2,1);
h1 = stem(t, sig1);
set(h1, 'Marker', 'o', 'MarkerSize', 3, 'LineWidth', 1);
title('Original Sampled 100 Hz Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(2,2,2);
h2 = stem(t, sig);
set(h2, 'Marker', 'o', 'MarkerSize', 3, 'LineWidth', 1);
title('Quantized Signal (Mid-Rise, 4-bit)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

qun_error = sig1 - sig;

subplot(2,2,3);

1
plot(t, qun_error, 'LineWidth', 1.5);
title('Quantization Error');
xlabel('Time (s)');
ylabel('Error');
grid on;

subplot(2,2,4);
plot(sig1, qun_error, 'b.', 'MarkerSize', 20);
title('Quantization Error Plot');
xlabel('Input Signal');
ylabel('Quantization error');
grid on;

NAME :- RITIK CHAUDHARY


ENROLL :- 23103198
Generate 0.02-second sine wave of 100 Hz

Published with MATLAB® R2024b

2
disp('NAME :- RITIK CHAUDHARY');
disp('ENROLL :- 23103198');

clc;
clear all;
close all;
Tb=1;
t=0:Tb/100:Tb;
fc=2;
c=sqrt(2/Tb)*sin(2*pi*fc*t);
N=8;
m=rand(1,N);
t1=0;
t2=Tb
for i=1:N
t=[t1:.01:t2]
if m(i)>0.5
m(i)=1;
m_s=ones(1,length(t));
else
m(i)=0;
m_s=-1*ones(1,length(t));
end
message(i,:)=m_s;
bpsk_sig(i,:)=c.*m_s;
subplot(5,1,2);
axis([0 N -2 2]);
plot(t,message(i,:),'r');
title('message signal(POLAR form)');
xlabel('t--->');
ylabel('m(t)');
grid on;
hold on;
subplot(5,1,4);plot(t,bpsk_sig(i,:));
title('BPSK signal');
xlabel('t--->'); ylabel('s(t)');
grid on;
hold on;
t1 = t1+1.01;
t2 = t2+1.01;
end
hold off
subplot(5,1,1); stem(m);
title('binary data bits');
xlabel('n--->'); ylabel('b(n)');
grid on;
subplot(5,1,3); plot(t,c);
title('carrier signal'); xlabel('t--->'); ylabel('c(t)');
grid on;
t1=0;
t2=Tb
for i=1:N

1
t=[t1:.01:t2]
x=sum(c.*bpsk_sig(i,:));
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+1.01;
t2=t2+1.01;
end
subplot(5,1,5);
stem(demod);
title('demodulated data');
xlabel('n--->');
ylabel('b(n)');
grid on;

NAME :- RITIK CHAUDHARY


ENROLL :- 23103198

t2 =

t =

Columns 1 through 7

0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600

Columns 8 through 14

0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300

Columns 15 through 21

0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000

Columns 22 through 28

0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700

Columns 29 through 35

0.2800 0.2900 0.3000 0.3100 0.3200 0.3300 0.3400

Columns 36 through 42

0.3500 0.3600 0.3700 0.3800 0.3900 0.4000 0.4100

Columns 43 through 49

0.4200 0.4300 0.4400 0.4500 0.4600 0.4700 0.4800

2
7.9100 7.9200 7.9300 7.9400 7.9500 7.9600 7.9700

Columns 92 through 98

7.9800 7.9900 8.0000 8.0100 8.0200 8.0300 8.0400

Columns 99 through 101

8.0500 8.0600 8.0700

Published with MATLAB® R2024b

21
disp('NAME :- RITIK CHAUDHARY');
disp('ENROLL :- 23103198');

clc;
clear all;
close all;

Tb=1;
fc1=2;
fc2=5;
t=0:(Tb/100):Tb;
c1=sqrt(2/Tb)*sin(2*pi*fc1*t);
c2=sqrt(2/Tb)*sin(2*pi*fc2*t);

N=8;
m=rand(1,N);
t1=0;
t2=Tb;
for i=1:N
t=[t1:(Tb/100):t2];
if m(i)>0.5
m_s=ones(1,length(t));
m(i)=1;
invm_s=zeros(1,length(t));
else
m(i)=0;
m_s=zeros(1,length(t));
invm_s=ones(1,length(t));
end
message(i,:)=m_s;
fsk_sig1(i,:)=c1.*m_s;
fsk_sig2(i,:)=c2.*invm_s;
fsk=fsk_sig1+fsk_sig2;

subplot(3,2,2);
axis([0 N -2 2]);
plot(t,message(i,:));
title('message signal');
xlabel('t---->');
ylabel('m(t)');
grid on;
hold on;

subplot(3,2,5);
plot(t, fsk(i,:), 'Color', [0.3, 0.6, 0.9], 'LineWidth', 1.5);

title('FSK signal');
xlabel('t---->');
ylabel('s(t)');
grid on;
hold on;

1
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end
hold off

subplot(3,2,1);
stem(m);
title('binary data');
xlabel('n---->');
ylabel('b(n)');
grid on;

subplot(3,2,3);
plot(t,c1);
title('carrier signal-1');
xlabel('t---->');
ylabel('c1(t)');
grid on;

subplot(3,2,4);
plot(t,c2);
title('carrier signal-2');
xlabel('t---->');
ylabel('c2(t)');
grid on;

t1=0;
t2=Tb;
for i=1:N
t=[t1:(Tb/100):t2];
x1=sum(c1.*fsk_sig1(i,:));
x2=sum(c2.*fsk_sig2(i,:));
x=x1-x2;
if x>0
demod(i)=1;
else
demod(i)=0;
end
t1=t1+(Tb+.01);
t2=t2+(Tb+.01);
end

subplot(3,2,6);
stem(demod);
title(' demodulated data');
xlabel('n---->');
ylabel('b(n)');
grid on;

NAME :- RITIK CHAUDHARY


ENROLL :- 23103198

2
Published with MATLAB® R2024b

3
disp('NAME :- RITIK CHAUDHARY');
disp('ENROLL :- 23103198');

N1=4;
x1=[1,2,3,2];
L1=length(x1);
X1=(1./N1).*fft(x1,N1);
subplot(3,2,1),stem(0:L1-1,x1)
title('x[n]')
xlabel('n')
ylabel('x[n]')
subplot(3,2,3),stem(0:N1-1,abs(X1));
title('Magnitude Spectrum')
xlabel('k')
ylabel('|X[k]|')
subplot(3,2,5),stem(0:N1-1,phase(X1))
title('Phase Spectrum')
xlabel('k')
ylabel('\angle X[k]')

N2=8;
x2=[1,1,0,0,0,0,0,0];
L2=length(x2);
X2=(1./N2).*fft(x2,N2);
subplot(3,2,2),stem(0:L2-1,x2)
title('x[n]')
xlabel('n')
ylabel('x[n]')
subplot(3,2,4),stem(0:N2-1,abs(X2));
title('Magnitude Spectrum')
xlabel('k')
ylabel('|X[k]|')
subplot(3,2,6),stem(0:N2-1,phase(X2))
title('Phase Spectrum')
xlabel('k')
ylabel('\angle X[k]')

NAME :- RITIK CHAUDHARY


ENROLL :- 23103198

1
Published with MATLAB® R2024b

2
disp('NAME :- RITIK CHAUDHARY');
disp('ENROLL :- 23103198');

N=4;
X=[4,2,0,4];
x=(N).*ifft(X,N);
subplot(3,2,1),stem(0:length(X)-1,X)
title('X[k]')
xlabel('k')
ylabel('X[k]')
subplot(3,2,3),stem(0:N-1,real(x));
title('Real of x[n]')
xlabel('n')
ylabel('Re{x[n]}')
subplot(3,2,5),stem(0:N-1,imag(x))
title('Phase Spectrum')
xlabel('n')
ylabel('Imag{x[n]}')

N=4;
X=[1,0,1,0];
x=(N).*ifft(X,N);
subplot(3,2,2),stem(0:length(X)-1,X)
title('X[k]')
xlabel('k')
ylabel('X[k]')
subplot(3,2,4),stem(0:N-1,real(x));
title('Real of x[n]')
xlabel('n')
ylabel('Re{x[n]}')
subplot(3,2,6),stem(0:N-1,imag(x))
title('Phase Spectrum')
xlabel('n')
ylabel('Imag{x[n]}')

NAME :- RITIK CHAUDHARY


ENROLL :- 23103198

1
Published with MATLAB® R2024b

You might also like