AM WAVE
GENERATION
aim
Write a MATLAB program to display AM wave.
PROGRAM
clc;
t=0:0.0001:0.01;
m=input('Enter the modulation index:');
fm=input('Enter the freq: of modulated wave:');
fc=input('Enter the freq: of carrier wave:');
x=sin(2*pi*fm*t);
y=sin(2*pi*fc*t);
e=(1+(m.*x).*y);
plot(e);
title('AM Wave');
xlabel('Time Index');
ylabel('Amplitude');
result
Enter the modulation index:.5
Enter the freq: of modulated wave:100
Enter the freq: of carrier wave:2000
WAVEFORM
AMPLITUDE MODULATION
AIM
Write aMATLAB program for Amplitude
Modulation
PROGRAM
clc;
clear all;
A=0.7; %amplitude
f=250;
fc=4e3;
fs=10*fc;
Ts=1/fs;
T=1/f;
Nc=3*T;
t=0:Ts:Nc;
x=A*sin(2*pi*f*t);
c=A*cos(2*pi*fc*t);
y=modulate(x,fc,fs,'amdsb-tc');
z=demod(y,fc,fs,'amdsb-tc');
figure(1);
subplot(4,1,1);
plot(t,x);
axis([0 Nc -A A]);
title('Message Signal');
title('Amplitude Modulation-DSB TC');
subplot(4,1,2);
plot(t,c);
axis([0 Nc -A A]);
title('Carrier Signal');
subplot(4,1,3);
plot(t,y);
axis([0 Nc -A A]);
title('Modulated Signal');
subplot(4,1,4);
plot(t,z);
xlabel('Time');
title('Demodulated Signal');
grid;
disp('Amplitude Modulation');
disp('---------------------');
disp('Message Signal');
disp('***************');
disp(['Amplitude= ' num2str(A) 'volts']);
disp(['Time period= ' num2str(T*1000) 'msec']);
disp(['Frequency= ' num2str(f) 'Hz']);
disp('**************');
RESULT
Amplitude Modulation
---------------------
Message Signal
***************
Amplitude= 0.7volts
Time period= 4msec
Frequency= 250Hz
**************
WAVEFORM
CIRCULAR CONVOLUTION OF SEQUENCE
AIM
Write a MATLAB program for circular convolution.
PROGRAM
clc;
clear all;
close all;
disp('Circular Convolution Program');
x=input('Enter i/p sequence x(n):');
m=length(x);
h=input('Enter i/p sequence h(n):');
n=length(h);
subplot(2,2,1), stem(x);
title('i/p sequencce x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
subplot(2,2,2), stem(h);
title('i/p sequencce h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('Circular convolution of x(n) & h(n) is y(n):');
if(m-n~=0)
if(m>n)
h=[h,zeros(1,m-n)];
n=m;
end
x=[x,zeros(1,n-m)];
m=n;
end
y=zeros(1,n);
y(1)=0;
a(1)=h(1);
for j=2:n
a(j)=h(n-j+2);
end
%ciruclar conv
for i=1:n
y(1)=y(1)+x(i)*a(i);
end
for k=2:n
y(k)=0;
% circular shift
for j=2:n
x2(j)=a(j-1);
end
x2(1)=a(n);
for i=1:n
if(i<n+1)a(i)=x2(i);
y(k)=y(k)+x(i)*a(i);
end
end
end
y
subplot(2,2,[3,4]),stem(y);
title('Convolution of x(n) & h(n) is:');
xlabel('---->n');
ylabel('---->y(n)');grid;
RESULT
Enter i/p sequence x(n):[1 2 3]
Enter i/p sequence h(n):[2 4 6]
Circular convolution of x(n)
& h(n) is y(n):
y = 26
26 20
WAVEFORM
CIRCULAR
CONVOLUTION
AIM
Write a MATLAB program for circular convolution
%solution for section(a)
clc;
close all;
clear all;
f1=1/128;
f2=5/128;
n=0:255;
fc=50/128;
x=cos(2*pi*f1*n)+cos(2*pi*f2*n);
xc=cos(2*pi*fc*n);
xamp=x.*xc;
subplot(2,2,1);
plot(n,x);
title('x(n)');
xlabel('n------>');
ylabel('amplitude');
subplot(2,2,2);
plot(n,xc);
title('xc(n)');
xlabel('n------>');
ylabel('amplitude');
subplot(2,2,3);
plot(n,xamp);
xlabel('n------>');
ylabel('amplitude');
%solution for section(b)
n=0:127;
figure;
n1=128;
f1=1/128;
f2=5/128;
fc=50/128;
x=cos(2*pi*f1*n)+cos(2*pi*f2*n);
xc=cos(2*pi*fc*n);
xa=cos(2*pi*fc*n);
xamp=x.*xa;
xam=fft(xamp,n1);
stem(n,xam);
title('xamp(n)');
xlabel('n------>');
ylabel('amplitude');
%solution for
section(c)
n=0:99;
figure;
n2=0:n1-1;
f1=1/128;
f2=5/128;
fc=50/128;
x=cos(2*pi*f1*n)+cos(2*pi*f2*n);
xc=cos(2*pi*fc*n);
xa=cos(2*pi*fc*n);
xamp=x.*xa;
for i=1:100,
xamp1(i)=xamp(i);
end;
xam=fft(xamp1,n1);
stem(n2,xam);
title('xamp(n)');
xlabel('n------->');
ylabel('amplitude');
RESULT
WAVEFORM
1
WAVEFORM 2
WAVEFORM 3
CONVOLUTION
OF TWO SEQUENCES
AIM
Write a MATLAB program for convolution of two sequences
PROGRAM
x=[1,0,1,2,-1,3,2];
N1=length(x);
n=0:1:N1-1;
subplot(2,2,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
h=[1 ,1, 2, 2,1,1];
N2=length(h);
n1=0:1:N2-1;
subplot(2,2,2);
stem(n1,h);
xlabel('n');
ylabel('h(n)');
y=conv(x,h);
n2=0:1:N1+N2-2;
subplot(2,2,3);
stem(n2,y);
xlabel('n');
ylabel('y(n);
OUTPUT WAVEFORM
SINEWAVE GENERATION
AIM
Write a MATLAB program to display
sinewaves of different frequencies
PROGRAM
clc;
%first plot
f=input('Enter frequency 1=');
t=0:0.001:1;
x=sin(2*pi*f*t);
subplot(221);
plot(x);
title('Sinewave1');
xlabel('Time Index');
ylabel('Amplitude');
%second plot
f=input('Enter frequency 2=');
t=0:0.001:1;
x=sin(2*pi*f*t);
subplot(222);
plot(x);
title('Sinewave2');
xlabel('Time Index');
ylabel('Amplitude');
%third plot
f=input('Enter frequency 3=');
t=0:0.001:1;
x=sin(2*pi*f*t);
subplot(223);
plot(x);
title('Sinewave3');
xlabel('Time Index');
ylabel('Amplitude');
%fourth plot
f=input('Enter freequency 4=');
t=0:0.001:1;
x=sin(2*pi*f*t);
subplot(224);
plot(x);
title('Sinewave4');
xlabel('Time Index');
ylabel('Amplitude');
RESULT
Enter frequency 1=2
Enter frequency 2=5
Enter frequency 3=10
Enter frequency 4=20
WAVEFORM
FFT SEQUENCE
AIM
Write a MATLAB program to display FFT sequence
PROGRAM
clc;
close all;
clear all;
x=input('Enter the sequence:');
n=input('Enter the length of FFT:');
k=1:n;
X(k)=fft(x,n);
stem(X(k),k);
ylabel('Imaginary axis---->');
xlabel('Real axis------>');
RESULT
Enter the sequence:[2 4 7]
Enter the length of FFT:4
WAVEFORM
FAST
FOURIER TRANSFORM
AIM
Write a MATLAB program for FFT
PROGRAM
clc;
clear all;
close all;
tic;
x=input('Enter the sequence:');
n=input('Enter the length of fft:');
%compute fft
disp('Fourier transformed signal');
X=fft(x,n)
subplot(1,2,1);
stem(x);
title('i/p signal');
xlabel('n --->');
ylabel('x(n) -->');grid;
subplot(1,2,2);stem(X);
title('FFT of i/p x(n) is:');
xlabel('Real axis --->');
ylabel('Imaginary axis -->');
grid;
RESULT
Enter the sequence:[1 3 5]
Enter the length of fft:4
Fourier transformed signal
X = 9.0000
-4.0000 - 3.0000i 3.0000 -4.0000 + 3.0000i
WAVEFORM
FIR
LOWPASS FILTER
AIM
Write a MATLAB program to design FIR lowpass filter
using hamming and blackmann windows
PROGRAM
clear all;
wc=.5*pi;%cutoff frequency
N=25;
b=fir1(N,wc/pi,hamming(N+1));
w=0:.01:pi;
h=freqz(b,1,w);
plot(w/pi,abs(h));
hold on
b=fir1(N,wc/pi,blackman(N+1))
w=0:.01:pi;
h=freqz(b,1,w);
plot(w/pi,abs(h),'-.');
ylabel('Magnitude');
xlabel('Normalised frequency');
hold off
RESULT
b =
Columns 1 through 10
-0.0000 -0.0001
-0.0005 0.0014 0.0031
-0.0060 -0.0107 0.0180
0.0291 -0.0465
Columns 11 through 20
-0.0764 0.1415
0.4472 0.4472 0.1415
-0.0764 -0.0465 0.0291
0.0180 -0.0107
Columns 21 through 26
-0.0060 0.0031
0.0014 -0.0005 -0.0001
-0.000
WAVEFORM
FREQUENCY
MODULATION
AIM
Write a MATLAB program for Frequency
Modulation
PROGRAM
clc;
clear all;
A=0.7; %amplitude
f=200;
fc=4e3;
fs=10*fc;
Ts=1/fs;
T=1/f;
Nc=3*T;
t=0:Ts:Nc;
x=A*sin(2*pi*f*t);
c=A*cos(2*pi*fc*t);
kf=0.6;
y=modulate(x,fc,fs,'fm',kf);
z=demod(y,fc,fs,'fm',kf);
figure(1);
subplot(4,1,1);
plot(t,x);
title('Message Signal');
grid;
subplot(4,1,2);
plot(t,c);
title('Carrier Signal');
grid;
subplot(4,1,3);
plot(t,y);
title('Modulated Signal');
grid;
subplot(4,1,4);
plot(t,z);
xlabel('Time');
title('Demodulated Signal');
grid;
disp('Frequency Modulation');
disp('---------------------');
disp('Message Signal');
disp('***************');
disp(['Amplitude= ' num2str(A) 'volts']);
disp(['Time period= ' num2str(T*1000) 'msec']);
disp('--------------------');
disp('Carrier Signal');
disp('***************');
disp(['Frequency= ' num2str(fc) 'Hz']);
disp('**************');
RESULT
Frequency Modulation
---------------------
Message Signal
***************
Amplitude= 0.7volts
Time period= 5msec
--------------------
Carrier Signal
***************
Frequency= 4000Hz
**************
WAVEFORM
IIR FILTER RESPONSES
AIM
Write a MATLAB programs of IIR filter responses for
LPF & HPF
PROGRAM
clc;
clear all;
close all;
warning off;
disp('Enter the IIR filter design specifications:');
rp=input('Enter the passband ripple:');
rs=input('Enter the stopband ripple:');
wp=input('Enter the passband freq:');
ws=input('Enter the stopband freq:');
fs=input('Enter the sampling freq:');
w1=2*wp/fs;w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
c=input('Enter choice of filter 1. LPF 2. HPF \n ');
if(c==1)
disp('Frequency response of IIR LPF is:');
[b,a]=butter(n,wn,'low','s');
end
if(c==2)
disp('Frequency response of IIR HPF is:');
[b,a]=butter(n,wn,'high','s');
end
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure,subplot(2,1,1);plot(om/pi,m);
title('Magnitude response of IIR filter is:');
xlabel('(a) Normalized freq. -->');
ylabel('Gain in dB-->');
subplot(2,1,2);plot(om/pi,an);
title('phase response of IIR filter is:');
xlabel('(b) Normalized freq. -->');
ylabel('Phase in radians-->');
RESULT
Enter the IIR filter design
specifications:
Enter the passband ripple:1
Enter the stopband ripple:2
Enter the passband freq:30
Enter the stopband freq:60
Enter the sampling freq:1
Enter choice of filter 1. LPF 2.
HPF
1
Frequency response of IIR LPF is:
WAVEFORM
LINEAR
CONVOLUTION
AIM
Write a MATLAB program for linear convolution
PROGRAM
clc;
clear all;
close all;
disp('Linear convolution program:');
x=input('Enter i/p x(n):');
m=length(x);
h=input('Enter i/p h(n):');
n=length(h);
x=[x,zeros(1,n)];
subplot(2,2,1), stem(x);
title('i/p sequence x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
h=[h,zeros(1,m)];
subplot(2,2,2), stem(h);
title('i/p sequence h(n)is:');
xlabel('---->n');
ylabel('---->h(n)');grid;
disp('Convolution of x(n) & h(n) is y(n):');
y=zeros(1,m+n-1);
for i=1:m+n-1
y(i)=0;
for j=1:m+n-1
if(j<i+1)
y(i)=y(i)+x(j)*h(i-j+1);
end
end
end
y
subplot(2,2,[3,4]),stem(y);
title('Convolution of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;
RESULT
Linear convolution program:
Enter i/p x(n):[1 2 3]
Enter i/p h(n):[2 4 6]
Convolution of x(n) & h(n) is
y(n):
y = 2
8 20 24
18
WAVEFORM
PAM
MODULATION AND DEMODULATION
AIM
Write a MATLAB program for Pulse Amplitude
Modulation and Demodulation
PROGRAM
clc;
clear all;
fm=5;
t=0:0.001:1;
vm=sin(2*pi*fm*t);
d=0:(1/56):2;
y=pulstran(t,d,'rectpuls',0.01);
s=y.*vm;
subplot(4,1,1);
plot(t,vm);
subplot(4,1,2);
plot(t,y);
subplot(4,1,3);
plot(t,s);
[b a]=butter(4,0.02,'low');
k=filter(b,a,s);
subplot(4,1,4);
plot(t,k);
OUTPUT WAVEFORM
PHASE
MODULATION
AIM
Write a MATLAB program for Phase Modulation
PROGRAM
clear all;
A=0.5; %amplitude
f=250;
fc=4e3;
fs=10*fc;
Ts=1/fs;
T=1/f;
Nc=2*T;
t=0:Ts:Nc;
x=A*sin(2*pi*f*t);
c=A*cos(2*pi*fc*t);
kp=5;
y=modulate(x,fc,fs,'pm',kp);
z=demod(y,fc,fs,'pm',kp);
subplot(4,1,1);
plot(t,x);
title('Message Signal');
axis([0 Nc -A A]);
zoom;
grid;
subplot(4,1,2);
plot(t,c);
title('Carrier Signal');
grid;
subplot(4,1,3);
plot(t,y);
title('Modulated Signal');
grid;
subplot(4,1,4);
plot(t,z);
title('Demodulated Signal');
grid;
xlabel('Time');
disp('Phase Modulation');
disp('----------------');
disp('Message Signal');
disp('****************');
disp(['Amplitude= ' num2str(A) 'volts']);
disp(['Frequency= ' num2str(f) 'Hz']);
disp(['Time period= ' num2str(T*1000) 'msec']);
disp('Carrier signal');
disp(['Frequency= ' num2str(fc) 'Hz']);
RESULT
Phase Modulation
----------------
Message Signal
****************
Amplitude= 0.5volts
Frequency= 250Hz
Time period= 4msec
Carrier signal
****************
Frequency= 4000Hz
WAVEFORM
PPM MODULATION AND
DEMODULATION
AIM
Write a MATLAB program for pulse position
modulation and demodulation
PROGRAM
clear all;
clc;
am=0.4;
fm=5;
fc=10;
fs=1000;
t=0:0.01:1;
vm=0.5+am*sin(2*pi*fm*t);
x=abs(vm);
subplot(3,1,1);
plot(t,x);
[s t]=modulate(vm,fc,fs,'ppm');
subplot(3,1,2);
plot(t,s);
z=demod(s,fc,fs,'ppm');
subplot(3,1,3);
plot(z);
OUTPUT WAVEFORM
PWM MODULATION AND
DEMODULATION
AIM
Write a MATLAB program for pulsewidth modulation and demodulation
PROGRAM
clear all;
clc;
am=0.4;
fm=5;
fc=5;
fs=1000;
t=0:0.01:1;
vm=0.5+am*sin(2*pi*fm*t);
x=abs(vm);
subplot(3,1,1);
plot(t,x);
[s t]=modulate(vm,fc,fs,'pwm','centered');
subplot(3,1,2);
plot(t,s);
z=demod(s,fc,fs,'pwm','centered');
subplot(3,1,3);
plot(z);
OUTPUT WAVEFORM
SUM OF SINE
SIGNALS
AIM
Write a MATLAB program to display
the sum of sinusoidal signals
PROGRAM
clc;
clear all;
close all;
tic;
%giving linear spaces
t=0:.01:pi;
% t=linspace(0,pi,20);
%generation of sine signals
y1=sin(t);
y2=sin(3*t)/3;
y3=sin(5*t)/5;
y4=sin(7*t)/7;
y5=sin(9*t)/9;
y = sin(t) + sin(3*t)/3 + sin(5*t)/5 + sin(7*t)/7 +
sin(9*t)/9;
plot(t,y,t,y1,t,y2,t,y3,t,y4,t,y5);
legend('y','y1','y2','y3','y4','y5');
title('Generation of sum of sinusoidal signals');grid;
ylabel('---> Amplitude');
xlabel('---> t');
OUTPUT WAVEFORM
No comments:
Post a Comment