Vous êtes sur la page 1sur 26

CYCLE -I

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

Aim: To generate different types of signals


EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Program:
clc;
close all;
clear all;

% unit step sequence


N=21;
x=ones(1,N);
n=0:1:N-1;
subplot(2,2,1);stem(n,x);
xlabel('n');ylabel('x(n)');
title('unit step sequence');

% exponential Sequence
x1=.8.^(n);
subplot(2,2,2),stem(n,x1);
xlabel('n'),ylabel('x1(n)');
title('exponential sequence');

%analog sin signal


x2=sin(.1*pi*n);
subplot(2,2,3);plot(n,x2);
xlabel('n');ylabel('x2(n)');
title('analog sin signal');

%disrete sin signal


x3=sin(.2*pi*n);
subplot(2,2,4);stem(n,x3);
xlabel('n');ylabel('x3(n)');
title('discrete sin signal');

generation of signals

output:
program 2: sum of sinusoidal signals

Aim: To generate sum of sinusoidal signals


EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Program:
clc;
close all;
clear all;

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:

x[ ]= Input signal Samples


h[ ]= Impulse response co-efficient.
y[ ]= Convolution output.
n = No. of Input samples
h = No. of Impulse response co-efficient.
Program:
clc;close all;clear all;
x=input('enter input sequence');
h=input('enter impulse response');
y=conv(x,h);
subplot(3,1,1);
stem(x);
xlabel('n');ylabel('x(n)');
title('input signal')
subplot(3,1,2);
stem(h);
xlabel('n');ylabel('h(n)');
title('impulse response')
subplot(3,1,3);
stem(y);
xlabel('n');ylabel('y(n)');
title('linear convolution')
disp('The resultant signal is');
disp(y)
linear convolution
output:
enter input sequence[1 4 3 2]
enter impulse response[1 0 2 1]
The resultant signal is
1 4 5 11 10 7 2
program 4: N-point FFT
Aim: To compute N-point FFT
EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Theory:
DFT of a sequence
N−
1 −j 2 ∏Kn
X[K] = ∑x[n ]e N
K=0

Where N= Length of sequence.


K= Frequency Coefficient.
n = Samples in time domain.

FFT : -Fast Fourier transformer .


There are Two methods.
1.Decimation in time (DIT FFT).
2. Decimation in Frequency (DIF FFT).

Why we need FFT ?


The no of multiplications in DFT = N2.
The no of Additions in DFT = N(N-1).
For FFT.
The no of multiplication = N/2 log 2N.
The no of additions = N log2 N.

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=

10.0000 1.0000 + 1.0000i -4.0000 1.0000 - 1.0000i


program 5: auto correlation & power density spectrum

Aim: To compute N-point FFT


EQUIPMENTS:
PC with windows (95/98/XP/NT/2000).
MATLAB Software
Program
clc;
close all;
clear all;
x=input('enter the sequence');
N=length(x);
n=0:1:N-1;
y=xcorr(x,x);
subplot(3,1,1);
stem(n,x);
xlabel(' n----->');ylabel('Amplitude--->');
title('input seq');
subplot(3,1,2);
N=length(y);
n=0:1:N-1;
stem(n,y);
xlabel('n---->');ylabel('Amplitude----.');
title('autocorr seq for input');
disp('autocorr seq for input');
disp(y)
p=fft(y,N);
subplot(3,1,3);
stem(n,p);
xlabel('K----->');ylabel('Amplitude--->');
title('psd of input');
disp('the psd fun:');
disp(p)
auto correlation & power density spectrum
enter the sequence[1 0 1 2]
autocorr seq for input
2 1 2 6 2 1 2

the psd fun:


Columns 1 through 5
16.0000 -4.0048 - 1.9286i 3.6174 + 4.5361i -0.6126 - 2.6840i
-0.6126 + 2.6840i
Columns 6 through 7
3.6174 - 4.5361i -4.0048 + 1.9286i
program 6: frequency response of filter
Aim: To find frequency response of analog LP/HP filters.

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

FIR LPF using blackman window

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 =

-0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492


0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014
0.0402 0.0092 -0.0000

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 Hamming window
clc;
close all;
clear all;
n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=hamming(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 Hamming window

output

window =

-0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492


0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014
0.0402 0.0092 -0.0000

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 =

-0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492


0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014
0.0402 0.0092 -0.0000

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 =

-0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492


0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014
0.0402 0.0092 -0.0000
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 triangular window
clc;
close all;
clear all;
n=20;
fp=200;
fq=300;
fs=1000;
fn=2*fp/fs;
window=triang(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 triangular window

window =

-0.0000 0.0092 0.0402 0.1014 0.2008 0.3400 0.5098 0.6892 0.8492


0.9602 1.0000 0.9602 0.8492 0.6892 0.5098 0.3400 0.2008 0.1014
0.0402 0.0092 -0.0000

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

window = -0.0000 0.0092 0.0402 0.1014 0.2008 0.3400


0.5098 0.6892 0.8492 0.9602 1.0000 0.9602 0.8492
0.6892 0.5098 0.3400 0.2008 0.1014 0.0402 0.0092
-0.0000
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

Vous aimerez peut-être aussi