BPSK Merged (1) Removed
BPSK Merged (1) Removed
disp('ENROLL :- 23103198');
clc;
close all;
clear all;
amp = 4;
fs = 3200;
nbits = 4;
T = 1/fs;
t = 0:T:0.02;
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;
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;
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;
t2 =
t =
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Columns 22 through 28
Columns 29 through 35
Columns 36 through 42
Columns 43 through 49
2
7.9100 7.9200 7.9300 7.9400 7.9500 7.9600 7.9700
Columns 92 through 98
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;
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]')
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]}')
1
Published with MATLAB® R2024b