matlab DCS
unknown
plain_text
5 months ago
6.6 kB
6
Indexable
1 PCM clc clear all close all fm = input("Fr:"); n = input("No. of Bits:"); A=2; fs = 2*fm; t=0:0.01:1; x = A*cos(2*pi*fm*t); ts = 0:0.01:1; xs = A*cos(2*pi*fs*ts); x1 = xs/(2*A); L = (2^n - 1); x1 = L*x1; xq = round(x1); y = []; for i = 1:length(xq) d = dec2bin(xq(i),n); y = [y double(d)-48]; end figure stem(ts,xs); hold on plot(ts,xs); hold off figure stem(t,x); hold on plot(t,x); hold off figure stem(ts,xq-(L/2)); hold on plot(ts,xq-(L/2)); hold off figure stairs(y); 2 ASK clc clear all close all tb = 1; fc = 5; t = 0:tb/100:1; 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 = zeros(1,length(t)); end message(i,:) = m_s; ask_sig(i,:) = c.*m_s; subplot(2,3,2); axis([0 n -2 2]); plot(t,ask_sig(i,:)); hold on; subplot(2,3,1); axis([0 n -2 2]); plot(t,message(i,:)); hold on; t1 = t1+(tb+0.01); t2 = t2+(tb+0.01); end figure plot(t,c); figure stem(m); 3 FSK clc clear all close all tb = 1; fc1 = 2; fc2 = 5; t = 0:(tb/100):1; 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(i)=1; m_s = ones(1,length(t)); invm_s = zeros(1,length(t)); else m(i)=0; m_s=zeros(1,length(t)); invm_s=ones(1,length(i)); end mess(i,:) = m_s; fsk1(i,:)= c1.*m_s; fsk2(i,:)=c2.*invm_s; fsk = fsk1+fsk2; subplot(2,2,1); axis([0 n -2 2]); plot(t,fsk(i,:),LineWidth=1.5); grid on hold on subplot(2,2,2); axis([0 n -2 2]); plot(t,mess(i,:),LineWidth=1.5); hold on grid on t1=t1+(tb+0.01); t2=t2+(tb+0.01); end hold off subplot(2,2,3); stem(m); subplot(2,2,4); plot(c1); t1 = 0; t2 =tb; for i=1:n t = t1:0.01:t2; x1 = sum(c1.*fsk1(i,:)); x2 = sum(c2.*fsk2(i,:)); x =x1-x2; if x>0 demod(i) = 1; else demod(i) = 0; end t1=t1+(tb+0.01); t2=t2+(tb+0.01); end figure stem(demod); 4 PSK clc clear all close all tb = 1; t = 0:tb/100:1; fc = 2; c = sqrt(2/tb)*sin(2*pi*fc*t); t1 = 0; t2 = tb; n = 8; m = rand(1,n); for i=1:n t = t1:0.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 mess(i,:) = m_s; psk(i,:) = c.*m_s; subplot(2,1,1); axis([0 n -2 2]); plot(t,mess(i,:)); hold on subplot(2,1,2); axis([0 n -2 2]); plot(t,psk(i,:)); hold on t1 = t1+tb+.01; t2 = t2+tb+.01; end hold off figure stem(m); figure plot(t,c); t1 = 0; t2 = tb; for i=1:n t = t1:0.01:t2; x = sum(c.*psk(i,:)); if x>0 demod(i) = 1; else demod(i) = 0; end t1 = t1+tb+.01; t2 = t2+tb+.01; end figure stem(demod); 5 LINE ENCODING clc clear all close all d = rand(1,8); for i = 1:8 if d(i)>0.5 bits(i)= 1; else bits(i) = 0; end end bitrate = 1; t = length(bits)/bitrate; n =200; N = n*length(bits); dt = t/N; t = 0:dt:N; subplot(5,1,1); stem(bits); for i = 0:length(bits)-1 if bits(i+1) == 1 x(i*n+1:(i+0.5)*n)= 1; x((i+0.5)*n+1:(i+1)*n) = -1; else x(i*n+1:(i+0.5)*n)= -1; x((i+0.5)*n+1:(i+1)*n) = 1; end end subplot(5,1,2); plot(x); title("Manchester"); for i = 0:length(bits)-1 if bits(i+1) == 1 x1(i*n+1:(i+1)*n) = 1; else x1(i*n+1:(i+1)*n) = 0; end end subplot(5,1,1); plot(x1); title("IN"); subplot(5,1,3); plot(x1); title("Uni nrz"); for i = 0:length(bits)-1 if bits(i+1) == 1 x(i*n+1:(i+0.5)*n)= 1; x((i+0.5)*n+1:(i+1)*n) = 0; else x(i*n+1:(i+1)*n) = 0; end end subplot(5,1,4); plot(x); title("Uni Rz"); count = 0; for i = 0:length(bits)-1 cou = rem(count,2); if bits(i+1) == 1 if cou == 0 x(i*n+1:(i+1)*n) = 1; else x(i*n+1:(i+1)*n) = -1; end count=count+1; else x(i*n+1:(i+1)*n) = 0; end end subplot(5,1,5); plot(x); title("Bippolar nrz"); for i = 0:2:length(bits)-1 y = (bits(i+1)*10) + bits(i+2); if y == 0 x(i*n+1:(i+2)*n)= -1.5; elseif y ==1 x(i*n+1:(i+2)*n)= -.5; elseif y ==10 x(i*n+1:(i+2)*n)= .5; else x(i*n+1:(i+2)*n)= 1.5; end end figure plot(x); title("Quaternary"); 6 PSD clc clear all close all bitrate = 1; tb = 1/bitrate; a = 1; f = 0:bitrate/100:2*bitrate; x1 = f*tb; sx = (((a^2*tb)/2)*sinc(x1).^2)+(((a^2*tb)/4)*sin(x1).^2).*dirac(f); plot(sx); hold on sx = (((a^2*tb))*sinc(x1).^2); plot(sx); sx = (((a^2*tb))*sinc(x1).^2).*sin(3.14*x1).^2; plot(sx); sx = (((a^2*tb))*sinc(x1/2).^2).*sin(3.14*x1/2).^2; plot(sx); hold off 7 DUOBINARY clc clear all close all bk = [0 0 1 0 1 1 0]; x = 1; ak = [1 0 0 0 0 0 0 0]; disp(bk); polar = ones(1,length(bk)); duo = zeros(1,length(bk)); for i = 1:length(bk) ak(i+1) = xor(bk(i),ak(i)); if ak(i+1)==1 polar(i+1) = 1; else polar(i+1) = -1; end end disp(ak); disp(polar); for i = 1:length(polar)-1 duo(i) = polar(i)+polar(i+1); end for i=1:length(duo) y = abs(duo(i)); if y>1 binin(i) = 0; else binin(i) = 1; end end disp(duo); disp(binin); subplot(5,1,1); stem(bk,"LineWidth",2); subplot(5,1,2); stem(ak,"LineWidth",2); subplot(5,1,3); stem(polar,"LineWidth",2); subplot(5,1,4); stem(duo,"LineWidth",2); subplot(5,1,5); stem(binin,"LineWidth",2); 8 PN SEQUENCE clc clear all close all n = 4; bin = [1 0 0 0]; pn = zeros(1,2^length(bin)-1); for i = 1:1:15 y = xor(bin(1),bin(4)); pn(i) = bin(4); for j = 4:-1:2 bin(j) = bin(j-1); end bin(1) = y; end disp(pn); stem(pn,"LineWidth",2); 9 TDM clc clear all close all t = 0:0.1:5*pi; sig1 = sin(t); l =length(sig1); sig2 = 1*triangle(t); sig3 = square(t); subplot(3,1,1); plot(sig1); subplot(3,1,2); plot(sig2); subplot(3,1,3); plot(sig3); for i=1:l sig(1,i) = sig1(i); sig(2,i) = sig2(i); sig(3,i) = sig3(i); end dmrg = reshape(sig,1,3*l); figure plot(dmrg); function y = triangle(t) y = abs(mod((t+pi)/pi,2)-1); end
Editor is loading...
Leave a Comment