Академический Документы
Профессиональный Документы
Культура Документы
com/2015/03/
i=1;
while i<nx+1
t = i:0.001:i+1;
if x(i)==1
ask=sin(2*pi*f*t);
fsk=sin(2*pi*f*t);
psk=sin(2*pi*f*t);
else
ask=0;
fsk=sin(2*pi*f2*t);
psk=sin(2*pi*f*t+pi);
end
subplot(3,1,1);
plot(t,ask);
hold on;
grid on;
axis([1 10 -1 1]);
title('Amplitude Shift Key')
subplot(3,1,2);
plot(t,fsk);
hold on;
grid on;
axis([1 10 -1 1]);
title('Frequency Shift Key')
subplot(3,1,3);
plot(t,psk);
hold on;
grid on;
axis([1 10 -1 1]);
title('Phase Shift Key')
i=i+1;
end
The matlab program given here is for finding pulse width modulation(PWM)
and pulse position modulation (PPM).
% Program for Pulse Code modulation with input signal x = [.2 .5 .3 .6]
clc
disp('select your choice 1 - pulse width 2 - pulse position')
i = input('select your choice - : ')
if i == 1
[y,t ] = modulate(x,100,1000,'pwm','centered');
subplot(2,1,1)
plot(x)
title('Input signal')
subplot(2,1,2);
plot(t,y)
title('Pulse Width Modulation')
end
if i == 2
[y,t ]= modulate(x,100,1000,'ppm',0.2);
subplot(2,1,1)
plot(x)
title('Input signal')
subplot(2,1,2);
plot(t,y)
title('Pulse Position Modulation')
end
MATLAB coding for Fourier series of rectangular pulse
%%----------------------------------------------------
l=1;
time=10;
for t=-time:0.01:time
sum=0;
j=1;
for k=-N:1:N
sum=sum+c(j)*exp(i*k*w0*t); %synthesis equation
j=j+1;
end
s(l)=sum;
l=l+1;
end
t=-time:0.01:time
subplot(2,1,2);
plot(t,s); % plot rectangular pulse
grid on;
xlabel('time');
ylabel('rectangular pulse');
MATLAB Code For SAMPLING THEORM
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
%%% sampling theorm %%%%%%%%%%%%%5
%%% x= sin(2*pi*f1*n)+cos(2*pi*f2*n) %%%%
%%% with f1= 2/128 & f2 = 4/128 %%%%%
clc;
close all;
clear all;
f1=2/128;
f2=4/128;
n=0:255;
fc=50/128;
x=sin(2*pi*f1*n)+cos(2*pi*f2*n);
xa=cos(2*pi*fc*n);
xamp=x.*xa;
subplot(2,2,1);plot(n,x);title('x(n)');
xlabel('n -->');
ylabel('amplitude');
subplot(2,2,2);
plot(n,xa);
title('xa(n)');
xlabel('n -->');ylabel('amplitude');
subplot(2,2,3);plot(n,xamp);
xlabel('n -->');ylabel('amplitude');
%%%%%%%%%%%%%%%%%%%%%%%%
MATLAB Code For Frequency Modulation
In FM, frequency of the carrier signal having high frequency is varied in
accordance with the instantaneous amplitude of the
Frequency modulation
Amplitude Modulation
AM is a method of transmitting signals, such as sound or digital information, in
which the amplitude of carrier wave is changed
is very easy.
c=A*sin(2*pi*fc*t);%Carrier Signal
subplot(3,1,2);
plot(t,c);
xlabel('Time');
ylabel('Amplitude');
title('Carrier Signal');
grid on;
figure(1)
te=length(H);
plot(1:te,real(H),'ko-',1:te,real(hb),'k+-')
legend('Estimated','Accurate')
figure(2)
plot(1:te,imag(H),'ko-',1:te,imag(hb),'k+-')
legend('Estimated','Accurate')
figure(3)
semilogy(SNR1,'-*')
xlabel('SNR/dB');ylabel('NRMSE');grid on;
% OFDM Code
% No.of Carriers: 64
% coding used: Convolutional coding
% Single frame size: 96 bits
% Total no. of Frames: 100
% Modulation: 16-QAM
% No. of Pilots: 4
% Cylic Extension: 25%(16)
close all
clear all
clc
%%
% Generating and coding data
t_data=randint(9600,1)';
x=1;
si=1; %for BER rows
%%
for d=1:100
data=t_data(x:x+95);
x=x+96;
k=3;
n=6;
s1=size(data,2); % Size of input matrix
j=s1/k;
%%
% Convolutionally encoding data
constlen=7;
codegen = [171 133]; % Polynomial
trellis = poly2trellis(constlen, codegen);
codedata = convenc(data, trellis);
%%
%%BCH encoding of Data
h=fec.bchenc(7,4);
codedata1 = encode(h,data');
codedata1=codedata';
%%
%Interleaving coded data
s2=length(codedata);
j=s2/4;
matrix=reshape(codedata,j,4);
dec=bi2de(intlvddata','left-msb');
dec1=bi2de(intlvddata1','left-msb');
%%
%16-QAM Modulation
M=16;
y = qammod(dec,M);
y1 =qammod(dec1,M);
%%
% Pilot insertion
lendata=length(y);
lendata1=length(y1);
pilt=3+3j;
nofpits=4;
k=1;
for i=(1:13:52)
pilt_data1(i)=pilt;
for j=(i+1:i+12)
pilt_data1(j)=y(k);
pilt_data2(j)=y1(k);
k=k+1;
end
end
for i=1:52
pilt_data(i+6)=pilt_data1(i);
pilt_data3(i+6)=pilt_data2(i);
end
%%
% IFFT
ifft_sig=ifft(pilt_data',64);
ifft_sig1=ifft(pilt_data3',64);
%%
% Adding Cyclic Extension
cext_data=zeros(80,1);
cext_data(1:16)=ifft_sig(49:64);
cext_data1(1:16)=ifft_sig1(49:64);
for i=1:64
cext_data(i+16)=ifft_sig(i);
cext_data1(i+16)=ifft_sig1(i);
end
%%
% Channel
% SNR
o=1;
for snr=0:2:50
%%
% RECEIVER
%%
%Removing Cyclic Extension
for i=1:64
rxed_sig(i)=ofdm_sig(i+16);
rxed_sig1(i)=ofdm_sig1(i+16);
end
%%
% FFT
ff_sig=fft(rxed_sig,64);
ff_sig1=fft(rxed_sig1,64);
%%
% Pilot Synch%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:52
synched_sig1(i)=ff_sig(i+6);
synched_sig2(i)=ff_sig1(i+6);
end
k=1;
for i=(1:13:52)
for j=(i+1:i+12);
synched_sig(k)=synched_sig1(j);
synched_sig3(k)=synched_sig2(j);
k=k+1;
end
end
%%
% Demodulation
dem_data= qamdemod(synched_sig,16);
dem_data1=qamdemod(synched_sig3,16);
%%
% Decimal to binary conversion
bin=de2bi(dem_data','left-msb');
bin=bin';
bin1=de2bi(dem_data','left-msb');
bin1=bin1';
%%
% De-Interleaving
%%
%Decoding data
n=6;
k=3;
decodedata =vitdec(deintlvddata,trellis,5,'trunc','hard'); % decoding datausing
veterbi decoder
rxed_data=decodedata;
%%
%Decoding of bch data
h1= fec.bchdec(h);
decodedata1 = decode(h1,deintlvddata1(1:189)');
decodedata1 = decodedata1';
rxed_data1=decodedata1;
%%
% Calculating BER
rxed_data=rxed_data(:)';
errors=0;
rxed_data1=rxed_data1(:)';
errors1=0;
c=xor(data,rxed_data);
c1=xor(data,rxed_data1(1:length(data)));
errors=nnz(c);
errors1=nnz(c);
BER(si,o)=errors/length(data);
BER1(si,o)=errors1/length(data);
papr(o)= max(abs(ofdm_sig).^2)/mean(abs(ofdm_sig).^2);
papr1(o)= max(abs(ofdm_sig1).^2)/mean(abs(ofdm_sig1).^2);
o=o+1;
%%
% Time averaging for optimum results
for col=1:25; %%%change if SNR loop Changed
ber(1,col)=0;
for row=1:100;
ber(1,col)=ber(1,col)+BER(row,col);
end
end
ber=ber./100;
for col=1:25; %%%change if SNR loop Changed
ber1(1,col)=0;
for row=1:100;
ber1(1,col)=ber1(1,col)+BER1(row,col);
end
end
ber1=ber1./100;
%%
figure(1);
index=1:80;
pause(2)
plot(index,cext_data,'b',index,ofdm_sig,'r'); %plot both signals
legend('Original Signal to be Transmitted','Signal with AWGN');
title('In the Channel trilles encoded')
pause(2)
figure(2)
plot(index,cext_data1,'b',index,ofdm_sig1,'r'); %plot both signals
legend('Original Signal to be Transmitted','Signal with AWGN');
title('In the Channel BCH encoded')
pause(2)
figure(3)
i=0:2:48;
semilogy(i,ber);
title('BER vs SNR of trilles encoded signal');
ylabel('BER');
xlabel('SNR (dB)');
grid on
figure(4)
i=0:2:48;
semilogy(i,ber1);
title('BER vs SNR of bch encoded signal');
ylabel('BER');
xlabel('SNR (dB)');
grid on
%%%%%%%%%%%%%%%%%%%%%% END
%%%%%%%%%%%%%%%%%%%%%%%