0% found this document useful (0 votes)
33 views

DSP Using Matlab

The MatLab code simulates an experiment to determine the frequency response of a 3 tap lowpass filter. It calculates the frequency response hz of the filter with coefficients [0.1871 0.2 0.1871] across frequencies w. It plots the magnitude response in dB and the phase response in degrees versus frequency in radians. The magnitude response graph shows that it is a lowpass filter with attenuation at higher frequencies.

Uploaded by

Younus Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

DSP Using Matlab

The MatLab code simulates an experiment to determine the frequency response of a 3 tap lowpass filter. It calculates the frequency response hz of the filter with coefficients [0.1871 0.2 0.1871] across frequencies w. It plots the magnitude response in dB and the phase response in degrees versus frequency in radians. The magnitude response graph shows that it is a lowpass filter with attenuation at higher frequencies.

Uploaded by

Younus Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

MatLab Code: %% Experiment 1

%% varification of Sampling Theorem


close all;
clear all;
clc;
t=0:0.01:0.2;
f=input('Enter analog Signal Frequency=');
fu=input('Enter the frequncy fu<=2f is =');
fn=input('Enter the frequncy fn>=2f is =');
fo=input('Enter the frequncy fo>>2f is =');
%% Generation Signal
A= sin(2*pi*f*t);
subplot(3,3,2);
plot(t,A);
xlabel('Time');ylabel('Amplitude');
title('Analog Signal');
%% Under Sampling
tu=0:(1/fu):0.2;
u=sin(2*pi*f*tu);
subplot(3,3,4);
stem(tu,u);
xlabel('Time');ylabel('Amplitude');
title('UnderSampling Signal');
%% Nyquest Condition
tn=0:(1/fn):0.2;
n=sin(2*pi*f*tn);
subplot(3,3,5);
stem(tn,n);
xlabel('Time');ylabel('Amplitude');
title('Nyquest');
%% Over Sampling
to=0:(1/fo):0.2;
u=sin(2*pi*f*to);
subplot(3,3,6);
stem(to,u);
xlabel('Time');ylabel('Amplitude');
title('OverSampling Signal');
%% Reconstruction of Signal
n1=0:(1/fn):0.2;
r1=interp1(tn,n,n1);
subplot(3,3,8);
plot(n1,r1);
xlabel('Time');ylabel('Amplitude');
title('Reconstruction Signal');
Result: Enter analog Signal Frequency=5
Enter the frequncy fu<=2f is =9
Enter the frequncy fn>=2f is =100
Enter the frequncy fo>>2f is =500
Graph:
MatLab Code:-%% Experiment 2 Perform Linear Convolution Using
Associative Commutative, Distributive property
clear all;
close all;
clc;
x=input('Enter x[n]=');
nx=0:length(x)-1;
y=input('Enter y[n]=');
ny=0:length(y)-1;
z=input('Enter z[n]=');
nz=0:length(z)-1;
%% Perform Linear Convolution
disp('Commutative Property: x(n)*y(n)=y(n)*x(n)');
a=conv(x,y)
na=0:length(a)-1;
subplot(4,4,1);stem(nx,x)
xlabel('Time');ylabel('Amplitude');
title('Input Sequence x(n)');
subplot(4,4,5);stem(ny,y);
xlabel('Time');ylabel('Amplitude');
title('Impulse Response of the Systemy y(n)');
subplot(4,4,9)stem(na,a);
xlabel('Time');ylabel('Amplitude');
title('Linear Convolution x(n)*y(n)');
b=conv(y,x)
nb=0:length(b)-1;
subplot(4,4,2);stem(na,a);
xlabel('Time');ylabel('Amplitude');
title('x(n)*y(n)')
subplot(4,4,6); stem(nb,b);
xlabel('Time');ylabel('Amplitude');
title('Commutative Property x(n)*y(n)=y(n)*x(n)');
%% Perform Linear Convolution of Associative Property
disp('Associative property: [x(n)*y(n)]*z(n)=x(n)*[y(n)*z(n)]');
c=conv(a,z)
nc=0:length(c)-1;
d=conv(y,z);
nd=0:length(d)-1;
e=conv(x,d)
ne=0:length(e)-1;
subplot(4,4,3)stem(nc,c)
xlabel('Time');ylabel('Amplitude');
title('[x(n)*y(n)]*z(n)');
subplot(4,4,7);stem(ne,e);
xlabel('Time');ylabel('Amplitude');
title('Associative property:[x(n)*y(n)]*z(n)=x(n)*[y(n)*z(n)]');
%%Perform Distributive Property
disp('Distributive Property: x(n)*[y(n)+z(n)]=x(n)*y(n)+x(n)*z(n)');
f= y + z;
g=conv(x,f)
ng=0:length(g)-1;
h=conv(x,z);
i=a+h
ni=0:length(i)-1;
subplot(4,4,4);stem(ng,g);
xlabel('Time');ylabel('amplitude');
title('x(n)*[y(n)+z(n)]')
subplot(4,4,8)
stem(ni,i);
xlabel('Time');ylabel('amplitude');
title('Distributive Property:x(n)*y(n)+x(n)*z(n)]')

Result: Enter x[n]=[1 2 3 4 5]


Enter y[n]=[1 2 3 1 3]
Enter z[n]=[1 3 1 4 5]
Commutative Property: x(n)*y(n)=y(n)*x(n)

a = 1 4 10 17 27 31 28 17 15
b = 1 4 10 17 27 31 28 17 15

Associative property: [x(n)*y(n)]*z(n)=x(n)*[y(n)*z(n)]

c = 1 7 23 55 109 189 266 325 353 329 223 145 75


e = 1 7 23 55 109 189 266 325 353 329 223 145 75

Distributive Property: x(n)*[y(n)+z(n)]=x(n)*y(n)+x(n)*z(n)

g = 2 9 20 36 60 72 64 57 40
i = 2 9 20 36 60 72 64 57 40
MatLab Code:-%% Experiment:- 03
function M=myconv(xn,hn)
l1=length(xn);
l2=length(hn);
N=l1+l2-1;
x1=[xn,zeros(1,l2-1)];
h1=[hn,zeros(1,l1-1)];
M=zeros(1,N);
for i=1:N
for j=1:i
% xn*hn
M(i)=M(i)+x1(j)*h1(i-j+1);
end
end
end
%%Auto and Cross Correlation
close all;
clear all;
clc
x=input('Enter x[n]=');
y=input('Enter y[n]=');
auto_corr=myconv(x,fliplr(x))
cross_corr=myconv(x,fliplr(y))
%%Plot The signal and Correaltion Figure
subplot(2,2,1);
stem(x);title('Signal X');
subplot(2,2,2);
stem(y);title('Signal Y');
subplot(2,2,3);
stem(auto_corr);title('Auto Correlation of Signal X');
subplot(2,2,4);
stem(cross_corr);title('Cross- Correlation of Signal X and Y');

Result: Enter x[n]=[1 2 3 4 5 6 7 8]


Enter y[n]=[1 2 3 4 5 9]

auto_corr =

8 23 44 70 100 133 168 204 168 133 100 70 44 23 8

cross_corr =

9 23 41 62 85 109 133 157 100 70 44 23 8


MatLab Code:-%% Experiment No.4
%% solving a given difference equation
clear all;
close all;
clc;
disp(' Solving a Given Difference Equation');
b=input('Enter coeffients of x(n) in order of x(n), x(n-1),....=\n');
a=input('Enter coeffients of y(n) in order of y(n), y(n-1),....=\n');
N=input('Enter no. of samples to be calculated, N=\n');
x=[1,zeros(1,N-1)];
n=0:1:N-1;
disp('Natural Response is');
yn=filter(b,a,x);
subplot(2,1,1);
stem(n,x);
xlabel('n----->');ylabel('Amplitude----x>');title('Given input Resonse');
subplot(2,1,2);
stem(n,yn);
xlabel('n----->');ylabel('Amplitude----yn>');title('Impulse Resonse');

Result:- Solving a Given Difference Equation


Enter coeffients of x(n) in order of x(n), x(n-1),....= 1
Enter coeffients of y(n) in order of y(n), y(n-1),....= [1 -1 0.9]
Enter no. of samples to be calculated, N= 6
Natural Response is yn =
1.0000 1.0000 0.1000 -0.8000 -0.8900 -0.1700
MatLab Code:-%% EXPERIMENT NO. 5 COMPUTATION OF n POINT DFT
clear all
close all;
clc
x=input('Enter The sequence of Signal: ');
N=input('Enter the No. of Points DFT: ');
for k=0:N-1
xk(k+1)=0;
for n=0:N-1
xk(k+1)=xk(k+1)+x(n+1)*exp(-j*2*pi*n*k/N);
end
end
disp('The DFT sequence is');
xk
disp('The Magnitude sequence is');
MagXk= abs(xk)
disp('The Phase sequence is');
PhaXk= angle(xk)
n=0:1:N-1;
subplot(2,1,1);stem(n,MagXk);
xlabel('k');ylabel('MagXk')
title('MAgnitudge Of Sepectram')
subplot(2,1,2);stem(n,PhaXk);
xlabel('k');ylabel('PhaXk');
title('Phase Of Sepectram')

Result:- Enter The sequence of Signal: [1 2 3 5 7 2]


Enter the No. of Points DFT: 5
The DFT sequence is xk =
18.0000 + 0.0000i -2.6910 + 5.9309i -3.8090 + 1.0368i
-3.8090 - 1.0368i -2.6910 - 5.9309i
The Magnitude sequence is MagXk =
18.0000 6.5128 3.9476 3.9476 6.5128
The Phase sequence is PhaXk =
0 1.9967 2.8758 -2.8758 -1.9967
Graph:-
Matlab Code:-
%% Experiment- 06 Determine the frequency response of a 3 tap
lowpass Filter
clear all;
close all;
clc
[hz w]=freqz([0.1871 0.2 0.1871]);
phi=180*(angle(hz))/pi;
subplot(2,1,1)
plot(w,20*log10(abs(hz)));
grid on;
xlabel('frequncy(radians)');
ylabel('Magnitude Response (dB)');
subplot(2,1,2)
plot(w,phi);
grid on;
xlabel('frequency(radians)');
ylabel('Phase (degrees)');

Graph:-

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy