0% found this document useful (0 votes)
10 views15 pages

Ac Lab Matlab Codes

The document contains MATLAB code for various signal processing techniques including SSB modulation and demodulation, time division multiplexing, PAM signal generation, PPM signal generation, AGC characteristics of radio receivers, and phase lock loop implementation. Each section includes code snippets along with plots to visualize the message, carrier, and modulated signals. The document serves as a comprehensive guide for implementing these techniques using MATLAB.

Uploaded by

20501a0404
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)
10 views15 pages

Ac Lab Matlab Codes

The document contains MATLAB code for various signal processing techniques including SSB modulation and demodulation, time division multiplexing, PAM signal generation, PPM signal generation, AGC characteristics of radio receivers, and phase lock loop implementation. Each section includes code snippets along with plots to visualize the message, carrier, and modulated signals. The document serves as a comprehensive guide for implementing these techniques using MATLAB.

Uploaded by

20501a0404
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/ 15

6.

SSB Modulation and Demodulation using MATLAB


MATLAB CODE:

fm=20;
fc=500;
vm=1;
vc=1;
mu=0.1;
t=0:0.00001:0.0999;
f=0:1:9999;

m=vm*cos(2*pi*fm*t); %% message
mp=vm*sin(2*pi*fm*t);
c=vc*cos(2*pi*fc*t); %% carrier
cp=vc*sin(2*pi*fc*t);

ss1=m.*c;
ss2=mp.*cp;
upper=ss1-ss2; %% upper sideband signal
lower=ss1+ss2; %% lower sideband signal
Vfupper=abs(fft(upper,10000))/10000; %% upper frequency spectrum
Vflower=abs(fft(lower,10000))/10000; %% lower frequency spectrum

%%% demodulator using Synchronous detector %%%%


%% upper demodulated
vudemod=c.*upper;
[b a] = butter(2,0.002);
upperdemod= filter(b,a,vudemod);

%% lower demodulated
vldemod=c.*lower;
[b a]=butter(2,0.002);
lowerdemod=filter(b,a,vldemod);

figure(1)
subplot(211);plot(t,m)
xlabel('Time') ;ylabel('Amplitude');
title('Message signal');grid;
subplot(212);plot(t,c)
xlabel('Time');ylabel('Amplitude');
title('Carrier signal');grid;

figure(2)
subplot(211);plot(t,upper)
xlabel('Time');ylabel('Amplitude');
title('SSB Upper Sideband signal');grid
subplot(212);plot(t,lower)
xlabel('Time');ylabel('Amplitude');
title('SSB Lower Sideband signal');grid

figure(3)
subplot(211);plot(f*10,Vfupper)
axis([(fc-20*fm) (fc+20*fm) 0 0.6]);
xlabel('Frequency');ylabel('Power');
title('SSB Upper Sidebsnd signal spectrum');grid
subplot(212);plot(f*10,Vflower)
axis([(fc-20*fm) (fc+20*fm) 0 0.6]);
xlabel('Frequency');ylabel('Power');
title('SSB Lower Sidebsnd signal spectrum');grid

figure(4)
subplot(211);plot(t,upperdemod)
xlabel('Time') ;ylabel('Amplitude');
title('Upper sideband Demodulated signal');grid;
subplot(212);plot(t,lowerdemod)
xlabel('Time') ;ylabel('Amplitude');
title('Lower sideband Demodulated signal');grid;
7. Time Division multiplexing and de-multiplexing using MATLAB

MATLAB CODE:

clc;
close all;
clear all;
% Signal generation
x=0:.5:4*pi; % siganal taken upto 4pi

sig1=8*sin(x); % generate 1st sinusoidal signal


l=length(sig1);
sig2=8*triang(l); % Generate 2nd traingular Sigal

% Display of Both Signal


subplot(2,2,1);
plot(sig1);
title('Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,2,2);
plot(sig2);
title('Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

% Display of Both Sampled Signal


subplot(2,2,3);
stem(sig1);
title('Sampled Sinusoidal Signal');
ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,2,4);
stem(sig2);
title('Sampled Triangular Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

l1=length(sig1);
l2=length(sig2);
for i=1:l1
sig(1,i)=sig1(i); % Making Both row vector to a matrix
sig(2,i)=sig2(i);
end

% TDM of both quantize signal


tdmsig=reshape(sig,1,2*l1);

% Display of TDM Signal figure


stem(tdmsig);
title('TDM Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

% Demultiplexing of TDM Signal


demux=reshape(tdmsig,2,l1);
for i=1:l1
sig3(i)=demux(1,i); % Converting The matrix into row vectors
sig4(i)=demux(2,i);
end

% display of demultiplexed signal


figure
subplot(2,1,1);
plot(sig3);
title('Recovered Sinusoidal Signal'); ylabel('Amplitude--->');
xlabel('Time--->');
subplot(2,1,2);
plot(sig4);
title('Recovered Triangular Signal'); ylabel('Amplitude--->');
xlabel('Time--->');
8. PAM Signal Generation and Demodulation using MATLAB

MATLAB CODE:

clc;
clear all;
close all;
fc=100;
fm=fc/10;
fs=100*fc;
t=0:1/fs:4/fm;

mt=cos(2*pi*fm*t);
ct=0.5*square(2*pi*fc*t)+0.5;
st=mt.*ct;
tt=[ ];

%single sided PAM


for i=1:length(st);
if st(i)==0;
tt=[tt,st(i)];
else
tt=[tt,st(i)+2];
end
end

figure(1)
subplot(4,1,1);
plot(t,mt); title('message signal'); xlabel('timeperiod'); ylabel('amplitude');
subplot(4,1,2);
plot(t,ct); title('carrier signal'); xlabel('timeperiod');ylabel('amplitude');
subplot(4,1,3); plot(t,st); title('BIPOLAR PAM');xlabel('timeperiod');
ylabel('amplitude');
subplot(4,1,4); plot(t,tt); title('PAM'); xlabel('timeperiod'); ylabel('amplitude');

%demodulation
dt=st.*ct;
dt_frequency=fftshift(abs(fft(dt)));
filter=fir1(200,fm/fs,'low');
original_t_signal=conv(filter,dt);
original_f_signal=fftshift(abs(fft(original_t_signal)));
t1=0:1/(length(original_t_signal)-1):1;
f=-fs/2:fs/(length(original_f_signal)-1):fs/2;
figure(2)
subplot(2,1,1); plot(t1,original_t_signal); title('time domain signal');
xlabel('timeperiod'); ylabel('amplitude');
subplot(2,1,2); plot(f,original_f_signal); title('frequency domain signal');
xlabel('frequency'); ylabel('amplitude');
axis([-50 50 0 2000]);
9 PPM Signal Generation and Demodulation using MATLAB
MATLAB CODE:

clc;
clear all;
close all;
fc=4000;
fs=40000;
fm=1000;
t=0:1/fs:(2/fm-1/fs);

mt=0.4*sin(2*pi*fm*t)+0.5;
st=modulate(mt,fc,fs,'PPM');
dt=demod(st,fc,fs,'PPM');

figure
subplot(3,1,1); plot(mt); title('message signal');
xlabel('timeperiod'); ylabel('amplitude'); axis([0 50 0 1])
subplot(3,1,2); plot(st); title(' PPM signal');
xlabel('timeperiod'); ylabel('amplitude'); axis([0 500 -0.2 1.2])
subplot(3,1,3); plot(dt); title(' PPM demodulated signal');
xlabel('timeperiod'); ylabel('amplitude');axis([0 50 0 1])
10 AGC Characteristics of Radio Receiver using MATLAB

MATLAB CODE:

clc
Fs = 100e3; %sampling freq
t = 0:1/Fs:.1-1/Fs; % time variable
Am=2;
fm = 200; %fm 200 Hz

m = cos(2*pi*fm*t); %message signal


Fc = 3e3;

% am modulation
Ac = 8;
c=Ac.*cos(2*pi*Fc*t); %carrier signal

figure;
% ploting message and carrier signals
subplot(2,1,1);
plot(c);
title('carrier'); xlabel('time'); ylabel('amplitude');
subplot(2,1,2); plot(m); title('message'); xlabel('time'); ylabel('amplitude');
figure;

% ploting AM modulated output


s = ammod(m,Fc,Fs,0,Ac);
subplot(2,1,1); plot(s);
title('am modulation '); xlabel('time'); ylabel('amplitude');
z = amdemod(s,Fc,Fs,0,Ac);
subplot(2,1,2);
plot(z);
title('am demodulation '); xlabel('time'); ylabel('amplitude');
11 Phase Lock Loop using MATLAB

f=1000;%Carrier frequency
fs=100000;%Sample frequency
N=5000;%Number of samples
Ts=1/fs;
t=(0:Ts:(N*Ts)- Ts);
%Create the message signal

f1=100;%Modulating frequency
msg=sin(2*pi*f1*t);
kf=.0628;%Modulation index

%Create the real and imaginary parts of a CW modulated carrier to be tracked.


Signal=exp(j*(2*pi*f*t+2*pi*kf*cumsum(msg)));%Modulated carrier
Signal1=exp(j*(2*pi*f*t));%Unmodulated carrier

%Initilize PLL Loop


phi_hat(1)=30; e(1)=0;
phd_output(1)=0; vco(1)=0;

%Define Loop Filter parameters(Sets damping)


kp=0.15; %Proportional constant
ki=0.1; %Integrator constant

%PLL implementation
for n=2:length(Signal)
vco(n)=conj(exp(j*(2*pi*n*f/fs+phi_hat(n-1))));%Compute VCO
phd_output(n)=imag(Signal(n)*vco(n));%Complex multiply VCO x Signal input
e(n)=e(n-1)+(kp+ki)*phd_output(n)-ki*phd_output(n-1);%Filter integrator
phi_hat(n)=phi_hat(n-1)+e(n);%Update VCO
end;

%Plot waveforms
startplot = 1;
endplot = 1000;

figure(1); subplot(3,2,1);
plot(t(startplot:endplot), msg(startplot:endplot)); title('100 Hz message signal');
xlabel('Time (seconds)'); ylabel('Amplitude'); grid;

figure(1); subplot(3,2,2);
plot(t(startplot:endplot), real(Signal(startplot:endplot))); title('FM (1KHz carrier
modulated with a 100 Hz message signal)');
xlabel('Time (seconds)'); ylabel('Amplitude'); grid;

figure(1);
subplot(3,2,3);
plot(t(startplot:endplot), e(startplot:endplot)); title('PLL Loop Filter/Integrator
Output');
xlabel('Time (seconds)'); ylabel('Amplitude'); grid;

subplot(3,2,4);
plot(t(startplot:endplot), real(vco(startplot:endplot))); title('VCO Output (PLL
tracking the input signal)');
%xlabel('Time (seconds)'); ylabel('Amplitude'); grid;

subplot(3,2,5);
plot(t(startplot:endplot), phd_output(startplot:endplot)); title('Phase Detecter
Output');
xlabel('Time (seconds)'); ylabel('Amplitude'); grid;

subplot(3,2,6);
plot(t(startplot:endplot), real(Signal1(startplot:endplot)));
title('Unmodulated Carrier');
xlabel('Time (seconds)'); ylabel('Amplitude'); grid;

You might also like