KEMBAR78
MATLAB Signal Processing Guide | PDF | Matlab | Amplitude
0% found this document useful (0 votes)
97 views24 pages

MATLAB Signal Processing Guide

The document contains 10 experiments related to signal processing using MATLAB. Experiment 1 provides an introduction to MATLAB including its basic components and how to start and run programs. Experiment 2 focuses on writing a program to generate common signals like sine, cosine, triangular and sawtooth waves. Experiment 3 describes writing a program to perform linear convolution on two sequences and obtain the output.

Uploaded by

Aviral Chaurasia
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)
97 views24 pages

MATLAB Signal Processing Guide

The document contains 10 experiments related to signal processing using MATLAB. Experiment 1 provides an introduction to MATLAB including its basic components and how to start and run programs. Experiment 2 focuses on writing a program to generate common signals like sine, cosine, triangular and sawtooth waves. Experiment 3 describes writing a program to perform linear convolution on two sequences and obtain the output.

Uploaded by

Aviral Chaurasia
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/ 24

INDEX

EXP. AIM DATE SIGNATURE


NO.
1. Introduction to MATLAB.

2. To generate a functional sequence of a signal (Sine, Cosine,


triangular, Square, Sawtooth and sinc) using MATLAB
function.

3. To write MATLAB programs to find out the linear


convolution of two sequences.

4. To write MATLAB programs to find out the Circular


convolution of two sequences.

5. Implement IIR Butterworth analog low pass for a 4 KHz


cut off frequency in MATLAB using IIM.

6. Write a MATLAB program to design the IIR Butterworth


Using Bilinear Transformation method.

7. To verify FFT in MATLAB.

8.

9.

10.

1
EXPERIMENT NO: 1

AIM:

Introduction to MATLAB.

APPARATUS REQUIRED:

HARDWARE: Personal Computer


SOFTWARE : MATLAB 7.8

INTRODUCTION TO MATLAB:

• MATLAB is a technical language to ease scientific computations.


• The name is derived from MATrix LABoratory .
• It provides many of the attributes of spreadsheets and programming languages.
• MATLAB is a case sensitive language (a variable named “c” is different than another
one called “C”).
• In interactive mode MATLAB scripts are platform independent (good for cross
platform portability).
• MATLAB works with matrices.
• Everything MATLAB understands is a matrix (from text to large cell arrays and
structure arrays).

BASIC COMPONENTS OF THE MATLAB ENVIRONMENT:

MATLAB has the following basic window components:


• Command Window - to execute commands in the MATLAB environment
• Editor Window – To write program
• Current Directory Window - to quickly access files on the MATLAB path
• Figure Window - to display graphical output from MATLAB code
• Workspace Window - to view variable definitions and variable memory allocations
• Command History Window - displays all commands issued in MATLAB since the last
session (good for learning and verification)

2
PROCEDURE:

1. Start the MATLAB program.


2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window/Figure window
8. Stop the program.

3
EXPERIMENT NO: 2

AIM:
Write a program for the generation of basic signals such as unit impulse, unit step, ramp,
exponential, sinusoidal and cosine.

APPARATUS REQUIRED:

HARDWARE: Personal Computer


SOFTWARE : MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window/Figure window
8. Stop the program.

PROGRAM: (Generation of Continuous Time Signals)


%%%%%%%PROGRAM: (Generation of Continuous Time Signals)

%Program for sine wave


t=0:0.1:10;
y=sin(2*pi*t);
subplot(3,3,1);
plot(t,y,'k');
xlabel('Time');
ylabel('Amplitude');
title('Sine wave');

%Program for cosine wave


t=0:0.1:10;
y=cos(2*pi*t);
subplot(3,3,2);
plot(t,y,'g');
xlabel('Time');
ylabel('Amplitude');
title('Cosine wave');

%Program for square wave


t=0:0.001:10;

4
y=square(t);
subplot(3,3,3);
plot(t,y,'m');
xlabel('Time');
ylabel('Amplitude');
title('Square wave');

%Program for sawtooth wave


t=0:0.1:10;
y=sawtooth(t);
subplot(3,3,4);
plot(t,y,'b');
xlabel('Time');
ylabel('Amplitude');
title('Sawtooth wave');
%Program for Triangular wave
t=0:.0001:20;
y=sawtooth(t,.5); % sawtooth with 50% duty cycle

% (triangular)
subplot(3,3,5);
plot(t,y, 'r');
ylabel ('Amplitude');
xlabel ('Time Index');
title('Triangular waveform');

%Program for Sinc Pulse


t=-10:.01:10;
y=sinc(t);
axis([-10 10 -2 2]);
subplot(3,3,6)
plot(t,y)
ylabel ('Amplitude');
xlabel ('Time Index');
title('Sinc Pulse');

% Program for Exponential Growing signal


t=0:.1:8;
a=2;
y=exp(a*t);
subplot(3,3,7);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
title('Exponential growing Signal');

% Program for Exponential Growing signal


t=0:.1:8;
a=2;
y=exp(-a*t);
subplot(3,3,8);
plot(t,y);
ylabel ('Amplitude');
xlabel ('Time Index');
title('Exponential decaying Signal');

5
RESULT:

Sine wave Cosine wave Square wave


1 1 1

0.5 0.5 0.5


Amplitude

Amplitude

Amplitude
0 0 0

-0.5 -0.5 -0.5

-1 -1 -1
0 5 10 0 5 10 0 5 10
Time Time Time
Sawtooth wave Triangular waveform Sinc Pulse
1 2 1

0.5 1
Amplitude

Amplitude

Amplitude
0.5
0 0
0
-0.5 -1

-1 -2 -0.5
0 5 10 -10 0 10 -10 0 10
Time Time Index Time Index
6
Exponential
x 10 growing Signal Exponential decaying Signal
10 1
Amplitude

Amplitude

5 0.5

0 0
0 5 10 0 5 10
Time Index Time Index

Thus the MATLAB program triangular, Square, Saw tooth and sinc plotted. Time
Signals) programs for functional sequence of a signal (Sine, Cosine) using MATLAB
function written and the results were plotted.

6
EXPERIMENT NO: 3

AIM:
To write MATLAB programs to find out the linear convolution of two sequences.

APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8

PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.
PROGRAM: (Linear Convolution)

%%%%%%%%PROGRAM: (Linear Convolution)


% linear convolution
close all
clear all
x=input('Enter x: ')
h=input('Enter h: ')
m=length(x);
n=length(h);
X=[x,zeros(1,n)];
H=[h,zeros(1,m)];
for i=1:n+m-1
Y(i)=0;
for j=1:i
Y(i)=Y(i)+X(j)*H(i-j+1);
end
end
Y

INPUT:
>> LIN_CONVOLUTION
Enter x: [1 2 3 4 5]
x =
1 2 3 4 5
Enter h: [1 2 3 1]

7
h =
1 2 3 1
Y =
1 4 10 17 24 25 19 5

RESULT:

Thus the MATLAB program written and the results were plotted.

8
EXPERIMENT NO: 4

AIM:
To write MATLAB programs to find out the Circular convolution of two sequences.

APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8

PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

PROGRAM: (Circular Convolution)


%%%%%%%%%PROGRAM: (Circular Convolution
clc; clear;
a = input('enter the sequence x(n) = ');
b = input('enter the sequence h(n) = ');
n1=length(a);
n2=length(b);
N=max(n1,n2);
x = [a zeros(1,(N-n1))];
for i = 1:N
k = i;
for j = 1:n2
H(i,j)=x(k)* b(j);
k = k-1;
if (k == 0)
k = N;
end
end
end
y=zeros(1,N);
M=H';
for j = 1:N
for i = 1:n2
y(j)=M(i,j)+y(j);

9
end
end
disp('The output sequence is y(n)= ');
disp(y);
stem(y);
title('Circular Convolution');
xlabel('n');
ylabel('y(n)');
INPUT:(Circular Convolution)
enter the sequence x(n) = [1 2 3 4]
enter the sequence h(n) = [1 2 1 1]
The output sequence is y(n)=
14 11 12 13

RESULT:

Thus the MATLAB program written and the results were plotted.

10
EXPERIMENT NO: 5

AIM:
Implement IIR Butterworth analog low pass filter for a 4 KHz cut off frequency in
MATLAB using IIM.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

PROGRAM:

%%%%%%%%%%PROGRAM: (IIR Butterworth Filter using Impulse Method)


N=input('ENTER THE FILTER ORDER N = ');
fs=input('ENTER THE SAMPLING FREQUENCY fs = ');
fc=input('ENTER THE CUT-OFF FREQUENCY fc = ');
wc=2*pi*fc;
[na,da]=butter(N,wc,'s');
[n,d]=impinvar(na,da,fs);
[h,f]=freqz(n,d,512,fs);
gain=20*log10(abs(h));
subplot(2,1,1);
plot(f,gain);
xlabel('Frequency---->');
ylabel('Magnitude---->');
title('AMPLITUDE RESPONSSE');
subplot(2,1,2);
zplane(n,d);
z=roots(n); p=roots(d);
xlabel('Real part---->');
ylabel('Imaginary part---->');
title('POLE-ZERO PLOT');

OUTPUT: (IIR Butterworth Filter using Impulse Method)

11
ENTER THE FILTER ORDER N = 3
ENTER THE SAMPLING FREQUENCY fs = 1500
ENTER THE CUT-OFF FREQUENCY fc = 4

RESULT:

AMPLITUDE RESPONSSE
0

-50
Magnitude---->

-100

-150

-200
0 100 200 300 400 500 600 700 800
Frequency---->

POLE-ZERO PLOT
1
Imaginary part---->

0.5

-0.5

-1
-3 -2 -1 0 1 2 3
Real part---->

12
EXPERIMENT NO: 6

AIM:
Write a MATLAB program to design the IIR Butterworth Using Bilinear Transformation
method.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

PROGRAM:

%%%%%%%%%%%PROGRAM: (IIR Butterworth Using Bilinear Transformation)


wp=input('ENTER THE PASSBAND EDGE FREQUENCIES wp= ');
ws=input('ENTER THE STOPBAND EDGE FREQUENCIES ws= ');
rp=input('ENTER THE PASSBAND RIPPLE rp= ');
rs=input('ENTER THE STOPBAND RIPPLE rs= ');
fs=input('ENTER THE SAMPLING FREQUENCY fs= ');
wpn=wp/(fs/2);
wsn=ws/(fs/2);
[N,fc]=buttord(wpn,wsn,rp,rs);
disp('ORDER OF THE FILTER');
disp(N);
[n,d]=butter(N,wpn);
[h,f]=freqz(n,d,512,fs);
gain=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(f,gain);
xlabel('FREQUENCY---->');
ylabel('MAGNITUDE');
title('AMPLITUDE RESPONSE');
subplot(2,1,2);
zplane(n,d);
z=roots(n);

13
p=roots(d);
xlabel('RREAL PART---->');
ylabel('IMAGINARY PART');
title('POLE-ZERO PLOT');

INPUT: (IIR Butterworth Using Bilinear Transformation)


>> BUTTER_BLT
ENTER THE PASSBAND EDGE FREQUENCIES wp= [200 300]
ENTER THE STOPBAND EDGE FREQUENCIES ws= [50 450]
ENTER THE PASSBAND RIPPLE rp= 3
ENTER THE STOPBAND RIPPLE rs= 20
ENTER THE SAMPLING FREQUENCY fs= 1000
ORDER OF THE FILTER
2

RESULT:

14
EXPERIMENT NO: 7

AIM:
To verify FFT in MATLAB.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

PROGRAM:
%%%%%%%%%%%%%PROGRAM %%%%%%%%%%%%%
N=input('type length of DFT= ');
T=input('type sampling period= ');
freq=input('type the sinusoidal freq= ');
k=0:N-1;
f=sin(2*pi*freq*1/T*k);
F=fft(f);
stem(k,abs(F));
grid on;
xlabel('k');
ylabel('X(k)');

INPUT:
type length of DFT= 32
type sampling period= 64
type the sinusoidal freq= 11
>>

OUTPUT:

15
16
EXPERIMENT NO: 8

AIM:
To write a program for calculation of DFT using MATLAB.

APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R 7.8

PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

PROGRAM:

% MATLAB code for DFT


clc;
xn=input('Input sequence: ');
N = input('Enter the number of points: ');
Xk=calcdft(xn,N);
disp('DFT X(k): ');
disp(Xk);
mgXk = abs(Xk);
phaseXk = angle(Xk);
k=0:N-1;

subplot (2,1,1);
stem(k,mgXk);
title ('DFT sequence: ');
xlabel('Frequency');
ylabel('Magnitude');
subplot(2,1,2);
stem(k,phaseXk);
title('Phase of the DFT sequence');
xlabel('Frequency');
ylabel('Phase');
INPUT:
Input sequence: [1 4 5 7 6 7 4 13 12]
Enter the number of points: 9

L =

9
RESULT:
DFT X(k):
59.0000
-1.3336 +10.7647i
-8.6775 +12.5699i
-11.5000 + 0.8660i
-3.4889 - 5.9890i
-3.4889 + 5.9890i
-11.5000 - 0.8660i
-8.6775 -12.5699i
-1.3336 -10.7647i

DFT sequence:
60
Magnitude

40

20

0
0 1 2 3 4 5 6 7 8
Frequency
Phase of the DFT sequence
4

2
Phase

-2

-4
0 1 2 3 4 5 6 7 8
Frequency
EXPERIMENT NO: 8

AIM:
To write a program for calculation of IDFT using MATLAB.

APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R 7.8

PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

PROGRAM:

% MATLAB code for IDFT


clc;
Xk = input('Input sequence X(k): ');
xn=calcidft(Xk);
N=length(xn);
disp('xn');
disp(xn);
n=0:N-1;
stem(n,xn);
xlabel('time');
ylabel('Amplitude');
title('IDFT')

INPUT:
Input sequence X(k): [1 4 5 -6 -8 9]
RESULT:
xn =

0.8333
2.5000 + 1.1547i
-1.6667 - 2.5981i
-1.5000 + 0.0000i
-1.6667 + 2.5981i
2.5000 - 1.1547i

xn
0.8333
2.5000 + 1.1547i
-1.6667 - 2.5981i
-1.5000 + 0.0000i
-1.6667 + 2.5981i
2.5000 - 1.1547i

IDFT
3

2.5

1.5

1
Amplitude

0.5

-0.5

-1

-1.5

-2
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time
EXPERIMENT NO: 10

AIM:
To write a program to design the FIR low pass and High pass filters using Blackman
window using MATLAB.

APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB R 7.8

PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

PROGRAM:

%%%%%%%%% BLACKMAN WINDOW %%%%%%%%


clc;
clear all;
close all;
rp=input('Enter Pass band Ripple: ');
rs=input('Enter Stop band Ripple: ');
fp=input('Enter Pass band Frequency: ');
fs=input('Enter Stop band Frequency: ');
f=input('Enter Sampling Frequency: ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
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,1,1);
plot(o/pi,m);
ylabel('Gain (dB)');
xlabel('Frequency')
%%%% High Pass Filter %%%%%%%%
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('Gain (dB)');
xlabel('Frequency')

INPUT: (Blackman Window)


Enter Pass band Ripple: 0.03
Enter Stop band Ripple: 0.01
Enter Pass band Frequency: 2000
Enter Stop band Frequency: 2500
Enter Sampling Frequency: 7000
RESULT:

50

0
Gain (dB)

-50

-100

-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Frequency

50

0
Gain (dB)

-50

-100

-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Frequency

Thus the program to design FIR low pass and high pass Filters using Blackman Window
is written and response of the filter using MATLAB are executed.
EXPERIMENT NO: 11

AIM:
To write a program to design the FIR low pass and High pass filters using Hamming
window using MATLAB.
APPARATUS REQUIRED:
HARDWARE: Personal Computer
SOFTWARE: MATLAB 7.8
PROCEDURE:
1. Start the MATLAB program.
2. Open new M-file
3. Type the program
4. Save in current directory
5. Compile and Run the program
6. If any error occurs in the program correct the error and run it again
7. For the output see command window\ Figure window
8. Stop the program.

PROGRAM: (Hamming Window)


%%%%%%%%% HAMMING WINDOW %%%%%%%%
clc;
clear all;
close all;
rp=input('Enter Pass band Ripple: ');
rs=input('Enter Stop band Ripple: ');
fp=input('Enter Pass band Frequency: ');
fs=input('Enter Stop band Frequency: ');
f=input('Enter Sampling Frequency: ');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
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,1,1);
plot(o/pi,m);
ylabel('Gain (dB)');
xlabel('Frequency')
%%%% High Pass Filter %%%%%%%%
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('Gain (dB)');
xlabel('Frequency')

Result: (Hamming Window)

Input Parameters
Enter Pass band Ripple: 0.02
Enter Stop band Ripple: 0.01
Enter Pass band Frequency: 1200
Enter Stop band Frequency: 1700
Enter Sampling Frequency: 9000
>>

50

0
Gain (dB)

-50

-100

-150
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Frequency

50

0
Gain (dB)

-50

-100
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Frequency

RESULT:

Thus the program to design FIR low pass and high pass Filters using HAMMING
Window is written and response of the filter using MATLAB are executed.

You might also like