Académique Documents
Professionnel Documents
Culture Documents
MATLAB PROGRAMS
1. Generation of signals
2. sum of sinusoidal signals
3. linear convolution
4. N-point FFT
5. power density spectrum
6. To find frequency response of analog LP/HP filters.
7. design FIR filter (LP/HP) using windowing technique
program 1: generation of signals
% exponential Sequence
x1=.8.^(n);
subplot(2,2,2),stem(n,x1);
xlabel('n'),ylabel('x1(n)');
title('exponential sequence');
generation of signals
output:
program 2: sum of sinusoidal signals
t=0:0.05:3*pi;
x1=sin(t*5);%sine wave with period 5
x2=sin(t*9);%sine wave with period 7
x3=x1+x2;%sum of x1 and x2
subplot(3,1,1);
plot(t,x1)
xlabel('time'),ylabel('amplitude')
title('sin signal-1');
subplot(3,1,2);
plot(t,x2)
xlabel('time'),ylabel('amplitude')
title('sin signal-2');
subplot(3,1,3);
plot(t,x3)
xlabel('time'),ylabel('amplitude')
title('sum of sin signals');
sum of sinusoidal signals
output:
Program 3: linear convolution
Aim: To find the out put with linear convolution operation Using Mat lab tool
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Theory:
Linear Convolution involves the following operations.
1. Folding
2. Multiplication
3. Addition
4. Shifting
These operations can be represented by a Mathematical Expression as follows:
Program:
clc;
close all;
clear all;
x=input('enter the sequence');
N=length(x);
n=0:1:N-1;
y=fft(x,N)
subplot(2,1,1);
stem(n,x);
title('input sequence');
xlabel('time index n----->');
ylabel('amplitude x[n]----> ');
subplot(2,1,2);
stem(n,y);
title('output sequence');
xlabel(' Frequency index K---->');
ylabel('amplitude X[k]------>');
N-point FFT
Output:
enter the sequence[2 3 1 4]
y=
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Program
clc;
close all;
clear all;
b=ones(1,5);%FIR system1
a=[1];
d=[1,-1];%FIR System2
f=[1];
w=0:.01:2*pi;
[h1]=freqz(b,a,w);
[h2]=freqz(d,f,w);
subplot(2,2,1),plot(w/pi,abs(h1));
xlabel('normalised frequency\omega/\pi'),ylabel('magnitude');grid
subplot(2,2,3),plot(w/pi,angle(h1));
xlabel('normalised frequency\omega/\pi'),ylabel('phase in radius');grid
subplot(2,2,2),plot(w/pi,abs(h2));
xlabel('normalised frequency\omega/\pi'),ylabel('magnitude');grid
subplot(2,2,4),plot(w/pi,angle(h2));
xlabel('normalised frequency\omega/\pi'),ylabel('phase in radius');grid
frequency response of filter
Output:
Program7: design FIR filter (LP/HP) using windowing technique
clc;
close all;
clear all;
n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1)
b=fir1(n,fn,window)
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');
FIR LPF using blackman window
window =
output
window =
b=
0.0000 -0.0003 -0.0009 0.0027 0.0101 -0.0000 -0.0386 -0.0430 0.0794
0.2906 0.3999 0.2906 0.0794 -0.0430 -0.0386 -0.0000 0.0101
0.0027 -0.0009 -0.0003 0.0000
program for FIR LPF using hanning window
clc;
close all;
clear all;
n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=hann(n+1);
b=fir1(n,fn,window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');
Output for FIR LPF using hanning window
window =
b=
0.0000 -0.0003 -0.0009 0.0027 0.0101 -0.0000 -0.0386 -0.0430
0.0794 0.2906 0.3999 0.2906 0.0794 -0.0430 -0.0386 -0.0000
0.0101 0.0027 -0.0009 -0.0003 0.0000
Program for FIR LPF using rectangular window
clc;
close all;
clear all;
n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=rectwin(n+1)
b=fir1(n,fn,window)
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('magnitude response of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase response of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');
output for FIR LPF using rectangular window
window =
window =
b=
0.0000 -0.0003 -0.0009 0.0027 0.0101 -0.0000 -0.0386 -0.0430 0.0794
0.2906 0.3999 0.2906 0.0794 -0.0430 -0.0386 -0.0000 0.0101
0.0027 -0.0009 -0.0003 0.0000
program for FIR HPF using blackman window
n=20;
fp=300;
fq=200;
fs=1000;
fn=2*fp/fs;
window=blackman(n+1);
b=fir1(n,fn,'high',window);
[H W]=freqz(b,1,128);
subplot(2,1,1);
plot(W/pi,abs(H));
title('mag res of lpf');
ylabel('gain in db-------->');
xlabel('normalized frequency------>');
subplot(2,1,2);
plot(W/pi,angle(H));
title('phase res of lpf');
ylabel('angle-------->');
xlabel('normalized frequency------>');
Output for FIR HPF using blackman window
fn= 0.6