Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
36 views

DSP Lab Programs

The document contains code for analyzing and plotting various signals and filters including: 1) Plotting discrete sequences, magnitude and phase responses of filters, addition of sine waves, and convolution 2) Code for designing Butterworth and Chebyshev low pass, high pass, and band pass filters and plotting their magnitude and phase responses 3) Code that inputs sequences and computes their linear and circular convolution as well as cross correlation.

Uploaded by

Suresh Manthri
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

DSP Lab Programs

The document contains code for analyzing and plotting various signals and filters including: 1) Plotting discrete sequences, magnitude and phase responses of filters, addition of sine waves, and convolution 2) Code for designing Butterworth and Chebyshev low pass, high pass, and band pass filters and plotting their magnitude and phase responses 3) Code that inputs sequences and computes their linear and circular convolution as well as cross correlation.

Uploaded by

Suresh Manthri
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

4(a)

n=-6:1:6;
x=[zeros(1,5), 1 2 2 0.5 1.5 ,zeros(1,3)];
stem(n,x); %plots discrete sequence x[n]versus n
grid;
ylabel('Amplitude------->');%name the y-axis as Amplitude
of x[n]
xlabel('n--------->'); %name the x-axis as index n
title('Graphical representation of x[n]'); %Title as
Graphical representation of x[n]

4(b)
clc;
clear all;
b=(1);
a=[1,-0.6,0.08];
w=-pi:0.01:pi;
[h]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(w/pi,m);
grid;
ylabel('Magnitude in dB');
xlabel('Normalised frequency');
title('Magnitude Response');
subplot(2,1,2);
plot(w/pi,angle(h));
grid;
ylabel('Phase in radians');
xlabel('Normalised frequency');
title('Phase Response');

5(a)
x=-6:0.01:6;
y1=4*sin((2*pi*x)/5);
y2=2*sin((2*pi*x)/7);
y3=y1+y2;
subplot(3,1,1);plot(x,y1);title('sine with period 5');
ylabel('Amplitude -------->');
xlabel('time -------->');
grid;
subplot(3,1,2);plot(x,y2);title('sine with period 7');
ylabel('Amplitude -------->');
xlabel('time -------->');
grid;
subplot(3,1,3);plot(x,y3);title('Resultant signal');
ylabel('Amplitude -------->');
xlabel('time -------->');
grid

5(b)
clc;
clear all;
b=[0,1,2];
a=[1,1,-2];
w=-pi:0.01:pi;
[h]=freqz(b,a,w);
m=20*log10(abs(h));
subplot(2,1,1);
plot(w/pi,m);
grid;
ylabel('Magnitude in dB');
xlabel('Normalised frequency');
title('Magnitude Response');
subplot(2,1,2);
plot(w/pi,angle(h));
grid;
ylabel('Phase in radians');
xlabel('Normalised frequency');
title('Phase Response');

6.
clc;
clear all;
x=input('enter the 1st sequence:');
h=input('enter the 2nd sequence:');
y=conv(x,h);
disp('Linear convolution of x & h:');
disp(y);
subplot(2,2,1);
stem(x);
ylabel('Amplitude -------->');
xlabel('(a)n ------->');
title('input sequence x[n]:');
subplot(2,2,2);
stem(h);
ylabel('Amplitude -------->');
xlabel('(b)n ------->');
title('input sequence h[n]:');
n = 0:length(y)-1;
subplot(2,2,3);
stem(n,y);
ylabel('Amplitude -------->');
xlabel('(c)n ------->');
title('Linear convolution');
n = max(length(x),length(h));
x1 = fft(x,n);
h1 = fft(h,n);
y = x1.*h1;
yc = ifft(y,n);
disp('circular convolution:');
disp(yc);
N=0:1:n-1;
subplot(2,2,4);
stem(N,yc);
xlabel('(d)n ------->');
ylabel('Amplitude -------->');
title('Circular convolution');

7.
clc;
clear all;
x=input('enter the 1st sequence:');
h=input('enter the 2nd sequence:');
n = max(length(x),length(h));
%program for computing
circular convolution
x1 = fft(x,n);
h1 = fft(h,n);
y = x1.*h1;
yc = ifft(y,n);
disp('circular convolution:');
disp(yc);
subplot(2,2,1);
stem(x);
ylabel('Amplitude -------->');
xlabel('(a)n ------->');
title('input sequence x[n]:');
subplot(2,2,2);
stem(h);
ylabel('Amplitude -------->');
xlabel('(b)n ------->');
title('input sequence h[n]:');
N=0:1:n-1;
subplot(2,2,3);
stem(N,yc);
xlabel('(c)n ------->');
ylabel('Amplitude -------->');
title('Circular convolution');
y=xcorr(x,h);
%program for computing
cross correlation
disp('cross correlation:');
disp(y);
subplot(2,2,4);
stem(y);
xlabel('(d)n ------->');
ylabel('Amplitude -------->');
title('Cross correlation');

8(a)
clc;
n=-10:1:10;
h=[zeros(1,7),2,-0.5,0.5,-0.25, zeros(1,10)];
stem(n,h);
ylabel('Amplitude------>');
xlabel('index n------->');
title('Graphical Representation of h[n]=0.25delta[n]+0.5delta[n+1]-0.5delta[n+2]+2delta[n+3]');
grid;

9(a)
clc;
n=input('enter the N value');
t=0:1:n-1;
u=ones(1,n);
subplot(2,1,1);
stem(t,u);
grid;
ylabel('Amplitude------>');
xlabel('index------->');
title('unit step sequence');
X = pow2(u,(-t));
subplot(2,1,2);
stem(t,X);
grid;
ylabel('Amplitude------>');
xlabel('index------->');
title('Graphical Representation of x[n]=(2)^(-n)*u[n]');

9(b)
n=0:50;
x=cos((2*pi*500*n)/1000);
xk=fft(x);
xk_conj=conj(xk);
k=0:50;
psdk=(xk.*(xk_conj))./length(n);
stem(k,psdk);
xlabel('k ------>');
ylabel('magnitude ------->');
title('Power Spectral Density of sinusoidal signal');

10

clc;
clear all;
alphap=input('enter the passband ripple');
alphas=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
Fs=input('enter the sampling frequency');
omp=(2*fp)/Fs;
oms=(2*fs)/Fs;
[n,wn]=buttord((omp/pi),(oms/pi),alphap,alp
has);
[b,a]=butter(n,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot((om/pi),m);
grid;
title('Butterworth lpf');
xlabel('(a)normalized freq ------>');
ylabel('Magnitude in dB ------->');
title('Magnitude Response');
subplot(2,1,2);
plot((om/pi),an);
grid;
xlabel('(b)normalized freq ------>');
ylabel('phase in radians ------->');
title('Phase Response');

11.
clc;
clear all;
format long
alphap=input('enter the passband ripple');
alphas=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
Fs=input('enter the sampling frequency');
omp=(2*fp)/Fs;
oms=(2*fs)/Fs;
[n,wn]=cheb1ord((omp/pi),(oms/pi),alphap,alphas)
;
[b,a]=cheby1(n,alphap,wn);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot((om/pi),m);
grid;
title('Cheyyshev lpf');
xlabel('(a) normalized freq ------>');
ylabel('Magnitude in dB ------->');
title('Magnitude Response');
subplot(2,1,2);
plot((om/pi),an);
grid;
xlabel('(b) normalized freq ------>');
ylabel('phase in radians ------->');
title('Phase Response');

12.

clc;
clear all;
alphap=input('enter the passband ripple');
alphas=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
Fs=input('enter the sampling frequency');
omp=(2*fp)/Fs;
oms=(2*fs)/Fs;
[n,wn]=buttord((omp/pi),(oms/pi),alphap,alp
has);
[b,a]=butter(n,wn,high);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot((om/pi),m);
grid;
title('Butterworth lpf');
xlabel('(a)normalized freq ------>');
ylabel('Magnitude in dB ------->');
title('Magnitude Response');
subplot(2,1,2);
plot((om/pi),an);
grid;
xlabel('(b)normalized freq ------>');
ylabel('phase in radians ------->');
title('Phase Response');

13.
clc;
clear all;
format long
alphap=input('enter the passband ripple');
alphas=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
Fs=input('enter the sampling frequency');
omp=(2*fp)/Fs;
oms=(2*fs)/Fs;
[n,wn]=cheb1ord((omp/pi),(oms/pi),alphap,alphas)
;
[b,a]=cheby1(n,alphap,wn,high);
w=0:0.01:pi;
[h,om]=freqz(b,a,w,'whole');
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot((om/pi),m);
grid;
title('Cheyyshev lpf');
xlabel('(a) normalized freq ------>');
ylabel('Magnitude in dB ------->');
title('Magnitude Response');
subplot(2,1,2);
plot((om/pi),an);
grid;
xlabel('(b) normalized freq ------>');
ylabel('phase in radians ------->');
title('Phase Response');

You might also like