matlab fair-record-model

71
DIGITAL SIGNAL PROCESSING LAB RECORD Experiment: 1 AM, FM and PWM using MATLAB AIM To implement a program in MATLAB to generate Amplitude Modulated (AM), Frequency Modulated (FM) & Pulse Width Modulated (PWM) waveforms. PROGRAM Amplitude Modulated Wave clc;clear all;close all; t=0:0.0001:0.015; m=input('Modulation Index:'); fm=input('Signal frequency:'); fc=input('Carrier frequency:'); x=sin(2*pi*fm*t); y=sin(2*pi*fc*t); e=(1+(m.*x)).*y; plot(e); title('Amplitude Modulation'); xlabel('Time'); ylabel('Amplitude'); OUTPUT Modulation Index:0.5 Signal frequency:100 Carrier frequency:1000 Dept. of Electronics & Communication Engg. Page No: 1 SCT College of Engineering Pappanamcode-18

Upload: ajaydev1111

Post on 12-May-2015

1.271 views

Category:

Education


1 download

TRANSCRIPT

Page 1: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 1

AM, FM and PWM using MATLAB

AIM

To implement a program in MATLAB to generate Amplitude Modulated (AM), Frequency Modulated (FM) & Pulse Width Modulated (PWM) waveforms.

PROGRAM

Amplitude Modulated Wave

clc;clear all;close all;

t=0:0.0001:0.015;

m=input('Modulation Index:');

fm=input('Signal frequency:');

fc=input('Carrier frequency:');

x=sin(2*pi*fm*t);

y=sin(2*pi*fc*t);

e=(1+(m.*x)).*y;

plot(e);

title('Amplitude Modulation');

xlabel('Time');

ylabel('Amplitude');

OUTPUT

Modulation Index:0.5

Signal frequency:100

Carrier frequency:1000

Dept. of Electronics & Communication Engg. Page No: 1SCT College of EngineeringPappanamcode-18

Page 2: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Frequency Modulated Wave

clc;clear all;close all;

a=input('Amplitude:');

fc=input('Carrier frequency:');

fm=input('Signal frequency:');

m=input('Modulation index:');

n=0:0.001:0.2;

y=a*sin(2*pi*fc*n-(m*cos(2*pi*fm*n)));

plot(n,y);

title('Frequency Modulation');

xlabel('Time');

ylabel('Amplitude');

OUTPUT

Amplitude:1

Carrier frequency:100

Signal frequency:10

Modulation index:5

Dept. of Electronics & Communication Engg. Page No: 2SCT College of EngineeringPappanamcode-18

Page 3: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Pulse Width Modulated Wave

clc;clear all;close all;

fs=100;

t=0:1/(5*fs):2;

x=sawtooth(2*pi*20*t);

m=0.75*sin(2*pi*t);

k=length(x);

for i=1:k

if (m(i)>=x(i))

pwm(i)=1;

else if (m(i)<x(i))

pwm(i)=0;

end;

end;

end;

plot(t,pwm,t,m);

axis([0,-1,-2,2]);

title('Pulse Width Modulation');

xlabel('Time');

ylabel('Amplitude');

Dept. of Electronics & Communication Engg. Page No: 3SCT College of EngineeringPappanamcode-18

Page 4: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

OUTPUT

RESULT

The programs for AM, FM & PWM signals are implemented in MATLAB and the output waveforms are generated.

Dept. of Electronics & Communication Engg. Page No: 4SCT College of EngineeringPappanamcode-18

Page 5: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 2

Linear Convolution

AIM

To write a program in MATLAB for the linear convolution of 2 sequences.

PROGRAM

clc;clear all;close all;

a=input('First sequence:');

b=input('Second sequence:');

c=fliplr(b);

d=length(a);

e=length(b);

f=[zeros(1,e-1),a,zeros(1,e)];

g=0;

i=d+e-1;

for h=0:(d+e-1)

j=[zeros(1,g),c,zeros(1,i)];

k=sum(f.*j);

con(g+1)=k;

g=g+1;

i=i-1;

end;

m=0:d+e-1;

stem(m,con);

title('Convlouted sequence');

xlabel('Time');

ylabel('Amplitude');

Dept. of Electronics & Communication Engg. Page No: 5SCT College of EngineeringPappanamcode-18

Page 6: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

OUTPUT

First sequence:[1 2 3 4]

Second sequence:[4 3 2 1]

RESULT

The program for convolution of 2 sequences is implemented using MATLAB and the resulting sequence is graphically generated.

Dept. of Electronics & Communication Engg. Page No: 6SCT College of EngineeringPappanamcode-18

Page 7: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 3

FIR Filters

AIM

To write a program in MATLAB for implementing FIR filters.

PROGRAM

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

fp=input('Enter passband frequency:');

fs=input('Enter stopband frequency:');

f=input('Enter sampling frequency:');

wp=2*fp/f;

ws=2*fs/f;

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n=ceil(num/dem);

n1=n+1;

if(rem(n,2)~=0)

n1=n;

n=n-1;

end;

y=boxcar(n1);

%LOW PASS FILTER

b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,1);

plot(o/pi,m);

Dept. of Electronics & Communication Engg. Page No: 7SCT College of EngineeringPappanamcode-18

Page 8: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

title('Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%HIGH PASS FILTER

b=fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,2);

plot(o/pi,m);

title('High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND PASS FILTER

wn=[wp,ws];

b=fir1(n,wn,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,3);

plot(o/pi,m);

title('Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND STOP FILTER

b=fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,4);

plot(o/pi,m);

title('Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

Dept. of Electronics & Communication Engg. Page No: 8SCT College of EngineeringPappanamcode-18

Page 9: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

OUTPUT

Enter passband ripple:0.05

Enter stopband ripple:0.04

Enter passband frequency:1500

Enter stopband frequency:2000

Enter sampling frequency:9000

RESULT

The program for FIR filters are implemented using MATLAB and the corresponding frequency responses are obtained.

Dept. of Electronics & Communication Engg. Page No: 9SCT College of EngineeringPappanamcode-18

Page 10: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 4

Butterworth IIR Filters

AIM

To design & simulate Butterworth IIR filters using MATLAB.

PROGRAM

Low Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=buttord(w1,w2,rp,rs);

[b,a]=butter(n,wn);

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('IIR Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

Dept. of Electronics & Communication Engg. Page No: 10SCT College of EngineeringPappanamcode-18

Page 11: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:200

Enter stopband frequency:400

Enter passband frequency:1000

High Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=buttord(w1,w2,rp,rs);

Dept. of Electronics & Communication Engg. Page No: 11SCT College of EngineeringPappanamcode-18

Page 12: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

[b,a]=butter(n,wn,'high');

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('IIR High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:1200

Enter stopband frequency:1000

Enter passband frequency:4000

Dept. of Electronics & Communication Engg. Page No: 12SCT College of EngineeringPappanamcode-18

Page 13: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Band Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=buttord(w1,w2,rp,rs);

[b,a]=butter(n,wn);

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

Dept. of Electronics & Communication Engg. Page No: 13SCT College of EngineeringPappanamcode-18

Page 14: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

title('IIR Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.4

Enter stopband ripple:50

Enter passband frequency:[800 1200]

Enter stopband frequency:[500 1500]

Enter passband frequency:4000

Band Stop Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

Dept. of Electronics & Communication Engg. Page No: 14SCT College of EngineeringPappanamcode-18

Page 15: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=buttord(w1,w2,rp,rs);

[b,a]=butter(n,wn,'stop');

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('IIR Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.4

Enter stopband ripple:50

Enter passband frequency:[800 1500]

Enter stopband frequency:[1000 1200]

Enter passband frequency:4000

Dept. of Electronics & Communication Engg. Page No: 15SCT College of EngineeringPappanamcode-18

Page 16: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT

The IIR Butterworth filters are designed using MATLAB and the output waveforms are obtained.

Experiment: 5

Chebyshev Type 1 Filters

AIM

To design & simulate Chebyshev Type 1 filters using MATLAB.

PROGRAM

Low Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

Dept. of Electronics & Communication Engg. Page No: 16SCT College of EngineeringPappanamcode-18

Page 17: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=cheb1ord(w1,w2,rp,rs);

[b,a]=cheby1(n,rp,wn);

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('Chebyshev Type 1 Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:1000

Enter stopband frequency:1500

Enter passband frequency:4000

Dept. of Electronics & Communication Engg. Page No: 17SCT College of EngineeringPappanamcode-18

Page 18: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

High Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=cheb1ord(w1,w2,rp,rs);

[b,a]=cheby1(n,rp,wn,'high');

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

Dept. of Electronics & Communication Engg. Page No: 18SCT College of EngineeringPappanamcode-18

Page 19: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

title('Chebyshev Type 1 High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:1500

Enter stopband frequency:1000

Enter passband frequency:5000

Band Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

Dept. of Electronics & Communication Engg. Page No: 19SCT College of EngineeringPappanamcode-18

Page 20: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=cheb1ord(w1,w2,rp,rs);

[b,a]=cheby1(n,rp,wn);

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('Chebyshev Type 1 Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:[1000 1200]

Enter stopband frequency:[800 1500]

Enter passband frequency:4500

Dept. of Electronics & Communication Engg. Page No: 20SCT College of EngineeringPappanamcode-18

Page 21: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Band Stop Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=cheb1ord(w1,w2,rp,rs);

[b,a]=cheby1(n,rp,wn,'stop');

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

Dept. of Electronics & Communication Engg. Page No: 21SCT College of EngineeringPappanamcode-18

Page 22: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('Chebyshev Type 1 Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:[1000 1200]

Enter stopband frequency:[800 1500]

Enter passband frequency:4500

Dept. of Electronics & Communication Engg. Page No: 22SCT College of EngineeringPappanamcode-18

Page 23: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT

The Chebyshev Type 1 filters are implemented using MATLAB p waveforms are obtained.

Experiment: 6

Chebyshev type 2 Filters

AIM

To design & simulate Chebyshev Type 2 filters using MATLAB.

PROGRAM

Low Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

Dept. of Electronics & Communication Engg. Page No: 23SCT College of EngineeringPappanamcode-18

Page 24: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

w2=2*ws/fs;

[n,wn]=cheb2ord(w1,w2,rp,rs);

[b,a]=cheby2(n,rp,wn);

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('Chebyshev Type 2 Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:1000

Enter stopband frequency:1500

Enter passband frequency:4000

Dept. of Electronics & Communication Engg. Page No: 24SCT College of EngineeringPappanamcode-18

Page 25: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

High Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=cheb2ord(w1,w2,rp,rs);

[b,a]=cheby2(n,rp,wn,'high');

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

Dept. of Electronics & Communication Engg. Page No: 25SCT College of EngineeringPappanamcode-18

Page 26: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

title('Chebyshev Type 2 High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:1000

Enter stopband frequency:800

Enter passband frequency:4500

Band Pass Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

Dept. of Electronics & Communication Engg. Page No: 26SCT College of EngineeringPappanamcode-18

Page 27: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=cheb2ord(w1,w2,rp,rs);

[b,a]=cheby2(n,rp,wn);

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('Chebyshev Type 2 Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:[800 1500]

Enter stopband frequency:[1000 1200]

Enter passband frequency:4500

Dept. of Electronics & Communication Engg. Page No: 27SCT College of EngineeringPappanamcode-18

Page 28: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Band Stop Filter

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

wp=input('Enter passband frequency:');

ws=input('Enter stopband frequency:');

fs=input('Enter passband frequency:');

w1=2*wp/fs;

w2=2*ws/fs;

[n,wn]=cheb2ord(w1,w2,rp,rs);

[b,a]=cheby2(n,rp,wn,'stop');

w=0:0.01:pi;

[h,om]=freqz(b,a,w);

Dept. of Electronics & Communication Engg. Page No: 28SCT College of EngineeringPappanamcode-18

Page 29: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

m=20*log10(abs(h));

an=angle(h);

subplot(2,1,1);

plot(om/pi,m);

title('Chebyshev Type 2 Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised frequency');

subplot(2,1,2);

plot(om/pi,an);

ylabel('Phase (radians)');

xlabel('Normalised frequency');

OUTPUT

Enter passband ripple:0.5

Enter stopband ripple:50

Enter passband frequency:[800 1500]

Enter stopband frequency:[1000 1200]

Enter passband frequency:4500

Dept. of Electronics & Communication Engg. Page No: 29SCT College of EngineeringPappanamcode-18

Page 30: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT

The Chebyshev Type 2 filters are implemented using MATLAB & the output waveforms are obtained.

Experiment: 7

FIR Filters Using Window Methods

AIM

To design & simulate FIR filters using various windows such as rectangular, Hamming, Kaiser, Hanning, Blackman & Bartlett windows in MATLAB.

PROGRAM- RECTANGULAR WINDOW

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

fp=input('Enter passband frequency:');

fs=input('Enter stopband frequency:');

f=input('Enter sampling frequency:');

Dept. of Electronics & Communication Engg. Page No: 30SCT College of EngineeringPappanamcode-18

Page 31: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

wp=2*fp/f;

ws=2*fs/f;

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n=ceil(num/dem);

n1=n+1;

if(rem(n,2)~=0)

n1=n;

n=n-1;

end;

y=rectwin(n1);

%LOW PASS FILTER

b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,1);

plot(o/pi,m);

title('Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%HIGH PASS FILTER

b=fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,2);

plot(o/pi,m);

title('High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND PASS FILTER

wn=[wp,ws];

b=fir1(n,wn,y);

Dept. of Electronics & Communication Engg. Page No: 31SCT College of EngineeringPappanamcode-18

Page 32: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,3);

plot(o/pi,m);

title('Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND STOP FILTER

b=fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,4);

plot(o/pi,m);

title('Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

OUTPUT

Enter passband ripple:0.05

Enter stopband ripple:0.04

Enter passband frequency:1500

Enter stopband frequency:2000

Enter sampling frequency:9000

Dept. of Electronics & Communication Engg. Page No: 32SCT College of EngineeringPappanamcode-18

Page 33: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

.

PROGRAM-HAMMING WINDOW

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

fp=input('Enter passband frequency:');

fs=input('Enter stopband frequency:');

Dept. of Electronics & Communication Engg. Page No: 33SCT College of EngineeringPappanamcode-18

Page 34: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

f=input('Enter sampling frequency:');

wp=2*fp/f;

ws=2*fs/f;

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n=ceil(num/dem);

n1=n+1;

if(rem(n,2)~=0)

n1=n;

n=n-1;

end;

y=hamming(n1);

%LOW PASS FILTER

b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,1);

plot(o/pi,m);

title('Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%HIGH PASS FILTER

b=fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,2);

plot(o/pi,m);

title('High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND PASS FILTER

wn=[wp,ws];

Dept. of Electronics & Communication Engg. Page No: 34SCT College of EngineeringPappanamcode-18

Page 35: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

b=fir1(n,wn,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,3);

plot(o/pi,m);

title('Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND STOP FILTER

b=fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,4);

plot(o/pi,m);

title('Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

OUTPUT

Enter passband ripple:0.02

Enter stopband ripple:0.01

Enter passband frequency:1200

Enter stopband frequency:1700

Enter sampling frequency:9000

Dept. of Electronics & Communication Engg. Page No: 35SCT College of EngineeringPappanamcode-18

Page 36: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

PROGRAM-KAISER WINDOW

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

fp=input('Enter passband frequency:');

fs=input('Enter stopband frequency:');

Dept. of Electronics & Communication Engg. Page No: 36SCT College of EngineeringPappanamcode-18

Page 37: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

f=input('Enter sampling frequency:');

beta=input('Enter beta value:');

wp=2*fp/f;

ws=2*fs/f;

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n=ceil(num/dem);

n1=n+1;

if(rem(n,2)~=0)

n1=n;

n=n-1;

end;

y=kaiser(n1,beta);

%LOW PASS FILTER

b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,1);

plot(o/pi,m);

title('Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%HIGH PASS FILTER

b=fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,2);

plot(o/pi,m);

title('High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND PASS FILTER

Dept. of Electronics & Communication Engg. Page No: 37SCT College of EngineeringPappanamcode-18

Page 38: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

wn=[wp,ws];

b=fir1(n,wn,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,3);

plot(o/pi,m);

title('Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND STOP FILTER

b=fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,4);

plot(o/pi,m);

title('Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

OUTPUT

Enter passband ripple:0.02

Enter stopband ripple:0.01

Enter passband frequency:1000

Enter stopband frequency:1500

Enter sampling frequency:10000

Dept. of Electronics & Communication Engg. Page No: 38SCT College of EngineeringPappanamcode-18

Page 39: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Enter beta value:5.8

PROGRAM-HANNING WINDOW

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

fp=input('Enter passband frequency:');

fs=input('Enter stopband frequency:');

Dept. of Electronics & Communication Engg. Page No: 39SCT College of EngineeringPappanamcode-18

Page 40: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

f=input('Enter sampling frequency:');

wp=2*fp/f;

ws=2*fs/f;

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n=ceil(num/dem);

n1=n+1;

if(rem(n,2)~=0)

n1=n;

n=n-1;

end;

y=hanning(n1);

%LOW PASS FILTER

b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,1);

plot(o/pi,m);

title('Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%HIGH PASS FILTER

b=fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,2);

plot(o/pi,m);

title('High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND PASS FILTER

wn=[wp,ws];

Dept. of Electronics & Communication Engg. Page No: 40SCT College of EngineeringPappanamcode-18

Page 41: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

b=fir1(n,wn,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,3);

plot(o/pi,m);

title('Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND STOP FILTER

b=fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,4);

plot(o/pi,m);

title('Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

OUTPUT

Enter passband ripple:0.03

Enter stopband ripple:0.01

Enter passband frequency:1400

Enter stopband frequency:2000

Enter sampling frequency:8000

Dept. of Electronics & Communication Engg. Page No: 41SCT College of EngineeringPappanamcode-18

Page 42: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

PROGRAM-BLACKMAN WINDOW

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

fp=input('Enter passband frequency:');

fs=input('Enter stopband frequency:');

Dept. of Electronics & Communication Engg. Page No: 42SCT College of EngineeringPappanamcode-18

Page 43: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

f=input('Enter sampling frequency:');

wp=2*fp/f;

ws=2*fs/f;

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n=ceil(num/dem);

n1=n+1;

if(rem(n,2)~=0)

n1=n;

n=n-1;

end;

y=blackman(n1);

%LOW PASS FILTER

b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,1);

plot(o/pi,m);

title('Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%HIGH PASS FILTER

b=fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,2);

plot(o/pi,m);

title('High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND PASS FILTER

wn=[wp,ws];

Dept. of Electronics & Communication Engg. Page No: 43SCT College of EngineeringPappanamcode-18

Page 44: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

b=fir1(n,wn,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,3);

plot(o/pi,m);

title('Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND STOP FILTER

b=fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,4);

plot(o/pi,m);

title('Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

OUTPUT

Enter passband ripple:0.03

Enter stopband ripple:0.01

Enter passband frequency:2000

Enter stopband frequency:2500

Enter sampling frequency:7000

Dept. of Electronics & Communication Engg. Page No: 44SCT College of EngineeringPappanamcode-18

Page 45: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

PROGRAM-BARTLETT WINDOW

clc;clear all;close all;

rp=input('Enter passband ripple:');

rs=input('Enter stopband ripple:');

fp=input('Enter passband frequency:');

fs=input('Enter stopband frequency:');

Dept. of Electronics & Communication Engg. Page No: 45SCT College of EngineeringPappanamcode-18

Page 46: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

f=input('Enter sampling frequency:');

wp=2*fp/f;

ws=2*fs/f;

num=-20*log10(sqrt(rp*rs))-13;

dem=14.6*(fs-fp)/f;

n=ceil(num/dem);

n1=n+1;

if(rem(n,2)~=0)

n1=n;

n=n-1;

end;

y=bartlett(n1);

%LOW PASS FILTER

b=fir1(n,wp,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,1);

plot(o/pi,m);

title('Low Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%HIGH PASS FILTER

b=fir1(n,wp,'high',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,2);

plot(o/pi,m);

title('High Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND PASS FILTER

wn=[wp,ws];

Dept. of Electronics & Communication Engg. Page No: 46SCT College of EngineeringPappanamcode-18

Page 47: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

b=fir1(n,wn,y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,3);

plot(o/pi,m);

title('Band Pass Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

%BAND STOP FILTER

b=fir1(n,wn,'stop',y);

[h,o]=freqz(b,1,256);

m=20*log10(abs(h));

subplot(2,2,4);

plot(o/pi,m);

title('Band Stop Filter');

ylabel('Gain (in dB)');

xlabel('Normalised Frequency');

OUTPUT

Enter passband ripple:0.04

Enter stopband ripple:0.02

Enter passband frequency:1500

Enter stopband frequency:2000

Enter sampling frequency:8000

Dept. of Electronics & Communication Engg. Page No: 47SCT College of EngineeringPappanamcode-18

Page 48: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT

FIR filters using Rectangular, Hamming, Kaiser, Hanning, Blackman & Bartlett windows are implemented in MATLAB & output waveforms are obtained.

Experiment: 8

Circular Convolution

AIM

To write a program in MATLAB for the circular convolution of 2 sequences.

Dept. of Electronics & Communication Engg. Page No: 48SCT College of EngineeringPappanamcode-18

Page 49: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

PROGRAM

clc;clear all;close all;

a=input('First sequence:');

b=input('Second sequence:');

d=length(a);

e=length(b);

if(d>e)

f=a;

g=[b,zeros(1,d-e)];

end;

if(d<e)

f=[a,zeros(1,e-d)];

g=b;

end;

n=0;

i=length(f)-1;

for h=0:i

k=sum(f.*g);

con(n+1)=k;

n=n+1;

g=circshift(g,[0 -1]);

end;

stem(con);

title('Circular convoluted sequence:');

xlabel('Time');

ylabel('Amplitude');

OUTPUT

First sequence:[1 2 3]

Second sequence:[5 4 3 2]

Dept. of Electronics & Communication Engg. Page No: 49SCT College of EngineeringPappanamcode-18

Page 50: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT

The circular convolution of 2 sequences is implemented using MATLAB & resulting sequence is graphically obtained.

Experiment: 9

Linear Convolution Using Circular Convolution

Dept. of Electronics & Communication Engg. Page No: 50SCT College of EngineeringPappanamcode-18

Page 51: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

AIM

To write a program in MATLAB for the linear convolution of 2 sequences using circular convolution.

PROGRAM

clc;clear all;close all;

x=input('Enter first sequence:');

h=input('Enter second sequence:');

n1=length(x);

n2=length(h);

N=n1+n2-1;

x=[x zeros(1,n2-1)];

h=[h zeros(1,n1-1)];

for n=0:N-1

y(n+1)=0;

for i=0:N-1

j=mod(n-i,N);

y(n+1)=y(n+1)+x(i+1)*h(j+1);

end;

end;

disp(y);

stem(y);

title('Linear convolution using circular convolution');

ylabel('Amplitude');

xlabel('Time');

OUTPUT

Enter first sequence:[1 2 3 4]

Enter second sequence:[4 1 4]

4 9 18 27 16 16

Dept. of Electronics & Communication Engg. Page No: 51SCT College of EngineeringPappanamcode-18

Page 52: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT

The linear convolution of 2 sequences using circular convolution is implemented using MATLAB & resulting sequence is graphically obtained.

Experiment: 10

Discrete Time Sequence

Dept. of Electronics & Communication Engg. Page No: 52SCT College of EngineeringPappanamcode-18

Page 53: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

AIM

To generate discrete time unit step, sinusoidal, exponential & addition sequences.

PROGRAM

clc;clear all;close all;

N=input('Enter length:');

%UNIT STEP SEQUENCE

x=ones(1,N);

n=0:1:N-1;

subplot(2,2,1);

stem(n,x);

title('Unit step sequence');

xlabel('Time');

ylabel('Amplitude');

%SINUSOIDAL SEQUENCE

x1=cos(.2*pi*n);

subplot(2,2,2);

stem(n,x1);

title('Sinusoidal sequence');

xlabel('Time');

ylabel('Amplitude');

%EXPONENTIAL SEQUENCE

x2=exp(n);

subplot(2,2,3);

stem(n,x2);

title('Exponential sequence');

xlabel('Time');

ylabel('Amplitude');

%ADDITION OF 2 SINUSOIDAL SEQUENCES

x3=sin(.1*pi*n)+sin(.2*pi*n);

subplot(2,2,4);

Dept. of Electronics & Communication Engg. Page No: 53SCT College of EngineeringPappanamcode-18

Page 54: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

stem(n,x3);

title('Added sequence');

xlabel('Time');

ylabel('Amplitude');

OUTPUT

Enter length:21

RESULT

The discrete time unit step, sinusoidal, exponential & addition of 2 sinusoidal sequences are obtained in MATLAB.

Experiment: 11

DFT & IDFT

Dept. of Electronics & Communication Engg. Page No: 54SCT College of EngineeringPappanamcode-18

Page 55: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

AIM

To find Discrete Fourier Transform (DFT) & Inverse Discrete Fourier Transform (IDFT) of a sequence.

PROGRAM

clc;clear all;close all;

x1=input('Enter sequence:');

N=input('Enter samples:');

xk=fft(x1)/N;

n=0:1:length(xk)-1;

subplot(2,2,2);

stem(n,abs(xk));

title('Magnitude Spectrum');

subplot(2,2,3);

stem(x1,angle(xk));

title('Angle of Fourier Transform');

xk1=ifft(xk)*N;

subplot(2,2,4);

stem(n,abs(xk1));

title('Inverse of Fourier Transform');

subplot(2,2,1);

stem(n,x1);

title('Input Signal');

OUTPUT

Enter sequence:[1 2 3 4]

Dept. of Electronics & Communication Engg. Page No: 55SCT College of EngineeringPappanamcode-18

Page 56: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Enter samples:3

RESULT

The DFT & IDFT of a sequence is obtained in MATLAB & output waveforms are obtained.

Experiment: 12

Linear Convolution Using Overlap-Save MethodDept. of Electronics & Communication Engg. Page No: 56SCT College of EngineeringPappanamcode-18

Page 57: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

AIM

To compute the linear convolution of 2 sequences using overlap-save method.

PROGRAM

clc; close all; clear all;

x=input('Enter input sequence:');

h=input('Enter impulse sequence:');

N=4;

if(N<length(h))

error('N must be >= length of h');

end;

Nx=length(x);

m=length(h);

m1=m-1;

l=N-m1;

x=[zeros(1,m-1),x,zeros(1,N-1)];

h=[h,zeros(1,N-m)];

k=floor((Nx+m1-1)/l);

Y=zeros(k+1,N);

for k=0:k

xk=x(k*l+1:k*l+N);

Y(k+1,:)=circonv(xk,h,N);

end;

Y=Y(:,m:N);

y=(Y(:));

stem(y);

title('Overlap-Save Method');

ylabel('Amplitude');

xlabel('Time');

OUTPUT

Dept. of Electronics & Communication Engg. Page No: 57SCT College of EngineeringPappanamcode-18

Page 58: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Enter input sequence:[1 2 3 4 5]

Enter impulse sequence:[3 2 1]

RESULT

The linear convolution of 2 sequences is obtained using overlap-save method and output waveforms are obtained.

Experiment: 13

Linear Convolution Using Overlap-Add Method

Dept. of Electronics & Communication Engg. Page No: 58SCT College of EngineeringPappanamcode-18

Page 59: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

AIM

To compute the linear convolution of 2 sequences using overlap-add method.

PROGRAMclc; close all; clear all;

x=[1,2,-1,2,3,-2,-3,-1,1,1,2,-1];

h=[1,2,1,1];

N=4;

y=ovrladd(x,h,N);

disp(y);

‘ovrladd’ function

function y= ovrladd(x,h,L);

nx=length(x);

m=length(h);

m1=m-1;

r=rem(nx,L);

n=L+m1;

x=[x,zeros(1,L-r)];

h=[h,zeros(1,n-m)];

K=floor(nx/L);

Y=zeros(K+1,n);

z=zeros(1,m1);

for k=0:K

xp=x(k*L+1:k*L+L);

xk=[xp z];

y(k+1,:)=circonv(xk,h,n);

end;

yp=y';

[x,y]=size(yp);

for i=L+1:x

for j=1:y-1

temp1=i-L;

Dept. of Electronics & Communication Engg. Page No: 59SCT College of EngineeringPappanamcode-18

Page 60: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

temp2=j+1;

temp3=yp(temp1,temp2)+yp(i,j);

yp(temp1,temp2)=yp(i,j);

yp(temp1,temp2)=temp3;

end;

end;

z=1;

for j=1:y

for i=1:x

if ((i<=L&j<=y-1)|(j==y));

ypnew(z)=yp(i,j);

z=z+1;

end;

end;

end;

y=ypnew;

‘circonv’ function

function[y]=circonv(x,h,N);

n2=length(x);

n3=length(h);

x=[x,zeros(1,N-n2)];

h=[h,zeros(1,N-n3)];

m=[0:1:N-1];

M=mod(-m,N);

h=h(M+1);

for n=1:1:N

m=n-1;

p=0:1:N-1;

q=mod(p-m,N);

hm=h(q+1);

H(n,:)=hm;

Dept. of Electronics & Communication Engg. Page No: 60SCT College of EngineeringPappanamcode-18

Page 61: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

end;

y=x*H';

OUTPUT

Columns 1 through 13

1 4 4 3 8 5 -2 -6 -6 -1 4 5 1

Columns 14 through 19

1 -1 0 0 0 0

RESULT

The linear convolution of 2 sequences is obtained using overlap-add method and output sequence is obtained.

Experiment: 14

Distributions

AIM

Dept. of Electronics & Communication Engg. Page No: 61SCT College of EngineeringPappanamcode-18

Page 62: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

To generate Gaussian, Poisson & random distributions using MATLAB.

PROGRAMclc;clear all;close all;

%GAUSSIAN SIGNAL

x1=gauspuls('cutoff',50e3,.6,-40);

x=-x1:1e-7:x1;

y=gauspuls(x,50e3,.6);

%POISSON SIGNAL

lambda=input('Enter value of lambda:');

m=input('Size of first array:');

n=input('Size of second array:');

R=poissrnd(lambda,m,n);

%RANDOM SIGNAL

p=input('Enter value:');

d=rand(1,p);

subplot(3,1,1);

plot(x,y);

xlabel('Time');

ylabel('Amplitude');

title('Gaussian distribution');

subplot(3,1,2);

plot(R);

xlabel('Time');

ylabel('Amplitude');

title('Poisson distribution');

subplot(3,1,3);

plot(d);

xlabel('Time');

ylabel('Amplitude');

title('Random distribution');

OUTPUT

Dept. of Electronics & Communication Engg. Page No: 62SCT College of EngineeringPappanamcode-18

Page 63: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Enter value of lambda:0.05

Size of first array:10

Size of second array:20

Enter value:21

RESULT

The Gaussian, Poisson & random distributions are implemented using MATLAB anf output waveforms are obtained.

Experiment: 15

Frequency Sampling

AIM

Dept. of Electronics & Communication Engg. Page No: 63SCT College of EngineeringPappanamcode-18

Page 64: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

To obtain a filter using frequency sampling method.

PROGRAM

clc;clear all;close all;

N=33;

alpha=(N-1)/2;

Hrk=[ones(1,9),zeros(1,16),ones(1,8)];

k1=0:(N-1)/2;k2=(N+1)/2:N-1;

theetak=[(-alpha*(2*pi)/N)*k1,(alpha*(2*pi)/N)*(N-k2)];

Hk=Hrk.*(exp(i*theetak));

hn=real(ifft(Hk,N));

w=0:0.01:pi;

H=freqz(hn,1,w);

plot(w/pi,20*log10(abs(H)));

hold on;

Hrk=[ones(1,9),0.5,zeros(1,14),0.5,ones(1,8)];

k1=0:(N-1)/2;k2=(N+1)/2:N-1;

theetak=[(-alpha*(2*pi)/N)*k1,(alpha*(2*pi)/N)*(N-k2)];

Hk=Hrk.*(exp(i*theetak));

hn=real(ifft(Hk,N));

w=0:0.01:pi;

H=freqz(hn,1,w);

plot(w/pi,20*log10(abs(H)),'.');

ylabel('Magnitude in dB');

xlabel('Normalised frequency \omega/\pi');

hold off;

OUTPUT

Dept. of Electronics & Communication Engg. Page No: 64SCT College of EngineeringPappanamcode-18

Page 65: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT

The filter is obtained using frequency sampling method in MATLAB.

Dept. of Electronics & Communication Engg. Page No: 65SCT College of EngineeringPappanamcode-18

Page 66: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 16

Up-sampling

AIM

To up-sample a given finite length sequence.

PROGRAM

N=input('Enter length of sinusoidal signal:');

L=input('Upsampling factor:');

fi=input('Input signal frequency:');

n=0:N-1;

x=sin(2*pi*fi*n);

y=zeros(1,L*length(x));

y([1:L:length(y)])=x;

subplot(2,1,1);

stem(n,x);

title('Input sequence:');

xlabel('Time n');

ylabel('Amplitude');

subplot(2,1,2);

stem(n,y(1:length(x)));

title(['Output sequence, upsampling factor=',num2str(L)]);

xlabel('Time n');

ylabel('Amplitude');

Dept. of Electronics & Communication Engg. Page No: 66SCT College of EngineeringPappanamcode-18

Page 67: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

OUTPUT

Enter length of sinusoidal signal:25

Upsampling factor:2

Input signal frequency:100

RESULT

The given sequence is up-sampled and the resulting waveforms are obtained.

Dept. of Electronics & Communication Engg. Page No: 67SCT College of EngineeringPappanamcode-18

Page 68: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 17

Down-sampling

AIM

To down-sample a given finite length sequence.

PROGRAM

clc;clear all;close all;

N=input('Enter length of sinusoidal signal:');

M=input('Downsampling factor:');

fi=input('Input signal frequency:');

n=0:N-1;

m=0:N*M-1;

x=sin(2*pi*fi*m);

y=x([1:M:length(x)]);

subplot(2,1,1);

stem(n,x(1:N));

title('Input sequence');

ylabel('Amplitude');

xlabel('Time');

subplot(2,1,2);

stem(n,y);

title(['Output sequence with downsampling factor ',num2str(M)]);

ylabel('Amplitude');

xlabel('Time');

Dept. of Electronics & Communication Engg. Page No: 68SCT College of EngineeringPappanamcode-18

Page 69: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

OUTPUT

Enter length of sinusoidal signal:25

Downsampling factor:3

Input signal frequency:100

RESULT

The given sequence is down-sampled and the resulting waveforms are obtained.

Dept. of Electronics & Communication Engg. Page No: 69SCT College of EngineeringPappanamcode-18

Page 70: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

Experiment: 18

Random Sequence

AIM

To generate a random sequence in MATLAB.

PROGRAM

clc;clear all;close all;

N=input('Enter length of random sequence:');

y=linspace(1,N,N);

x = 0+sqrt(1)*randn(1,N);

disp(x);

plot(y,x);

title('Random Sequence');

OUTPUT

Enter length of random sequence:12

Columns 1 through 7

0.1139 1.0668 0.0593 -0.0956 -0.8323 0.2944 -1.3362

Columns 8 through 12

0.7143 1.6236 -0.6918 0.8580 1.2540

Dept. of Electronics & Communication Engg. Page No: 70SCT College of EngineeringPappanamcode-18

Page 71: Matlab fair-record-model

DIGITAL SIGNAL PROCESSING LAB RECORD

RESULT

The required random sequence is obtained using MATLAB.

Dept. of Electronics & Communication Engg. Page No: 71SCT College of EngineeringPappanamcode-18