Vous êtes sur la page 1sur 9

IMPULSE SEQUENCE:

clear all
close all
n=[0:4];
x=[n==0];
stem(n,x)

x =

1 0 0 0 0

sum of two signals:

close all
clear all
N=21;
n=0:1:N-1;
subplot(5,1,1);
stem(n,sin(.1*pi*n))
title('sine1')
subplot(5,1,2)
stem(n,sin(.2*pi*n))
title('sine2')
x=sin(.1*pi*n)+sin(.2*pi*n)
subplot(5,1,3)
stem(n,x);
title('sum of two sinusoidal signals')
y=fft(x);
subplot(5,1,4)
f=0:1:N-1;
plot(f,abs(y));
title('magnitude vs frequency')
subplot(5,1,5)
plot(f,angle(y));

OUTPUT:
x =

Columns 1 through 16

0 0.8968 1.5388 1.7601 1.5388 1.0000 0.3633 -0.1420


-0.3633 -0.2788 -0.0000 0.2788 0.3633 0.1420 -0.3633 -1.0000

Columns 17 through 21

-1.5388 -1.7601 -1.5388 -0.8968 -0.0000

WINDOWING TECHNIQUES:

KAISER WINDOW:

cf=input('cutoff freq for HPF');


sf=input('sampling freq');
order=input('order of filter');
b=fir1(order,cf/sf,'high',kaiser(order+1))
[h,wn]=freqz(b);
subplot(2,2,1)
plot(wn,20*log(abs(h)));
title('high pass filter');
subplot(2,2,2)
plot(wn,angle(h));
cf=input('cutoff freq for LPF');
sf=input('sampling freq');
order=input('order of filter');
b=fir1(order,cf/sf,kaiser(order+1))
[h,wn]=freqz(b);
subplot(2,2,3)
plot(wn,20*log(abs(h)));
title('low pass filter');
subplot(2,2,4)
plot(wn,angle(h));

INPUT:
cutoff freq for HPF 800
sampling freq4000
order of filter4

OUTPUT:
b =

-0.1610 -0.2085 0.9051 -0.2085 -0.1610

INPUT:
cutoff freq for LPF 800
sampling freq 4000
order of filter 4

OUTPUT:

b =

0.1668 0.2160 0.2344 0.2160 0.1668

RECTANGULAR WINDOW:

cf=input('cutoff freq for HPF');


sf=input('sampling freq');
order=input('order of filter');
b=fir1(order,cf/sf,'high',boxcar(order+1))
[h,wn]=freqz(b);
subplot(2,2,1)
plot(wn,angle(h));
cf=input('cutoff freq for LPF');
sf=input('sampling freq');
order=input('order of filter');
b=fir1(order,cf/sf,boxcar(order+1))
[h,wn]=freqz(b);
subplot(2,2,3)
plot(wn,20*log(abs(h)));
title('low pass filter');
subplot(2,2,4)
plot(wn,angle(h));
cutoff freq for HPF 800
sampling freq 4000
order of filter 4

b =

-0.1737 -0.2147 0.9180 -0.2147 -0.1737

cutoff freq for LPF 800


sampling freq 4000
order of filter 4

b =

0.1726 0.2134 0.2281 0.2134 0.1726

HAMMIMG WINDOW:

cf=input('cutoff freq for HPF');


sf=input('sampling freq');
order=input('order of filter');
b=fir1(order,cf/sf,'high',hamming(order+1))
[h,wn]=freqz(b);
subplot(2,2,1)
plot(wn,20*log(abs(h)));
title('high pass filter');
subplot(2,2,2)
plot(wn,angle(h));
cf=input('cutoff freq for LPF');
sf=input('sampling freq');
order=input('order of filter');
b=fir1(order,cf/sf,hamming(order+1))
[h,wn]=freqz(b);
subplot(2,2,3)
plot(wn,20*log(abs(h)));
title('low pass filter');
subplot(2,2,4)
plot(wn,angle(h));

INPUT;

cutoff freq for HPF 800


sampling freq 4000
order of filter 4

OUTPUT:
b =

-0.0124 -0.1033 0.8181 -0.1033 -0.0124

INPUT:

cutoff freq for LPF 800


sampling freq 4000
order of filter 4
OUTPUT:

b =

0.0284 0.2370 0.4692 0.2370 0.0284

FIR FILTERS:

CHEBYSHEV LPF:

clear all;
alphap=1;
alphas=15;
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas)
[b,a]=cheby1(n,alphap,wn)
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(ph/pi,m);
ylabel('gain in dB');
xlabel('normalized frequency');
subplot(2,1,2);
plot(ph/pi,an);
ylabel('phase in radians');
xlabel('normalized frequency');

n =

wn =

0.2000

b =

0.0018 0.0073 0.0110 0.0073 0.0018

a =

1.0000 -3.0543 3.8290 -2.2925 0.5507

CHEBYSHEV HPF:

clear all;
alphap=1;
alphas=15;
wp=0.2*pi;
ws=0.3*pi;
[n,wn]=cheb1ord(wp/pi,ws/pi,alphap,alphas)
[b,a]=cheby1(n,alphap,wn,'high')
w=0:0.01:pi;
[h,ph]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(ph/pi,m);
ylabel('gain in dB');
xlabel('normalized frequency');
subplot(2,1,2);
plot(ph/pi,an);
ylabel('phase in radians');
xlabel('normalized frequency');

n =

wn =

0.2000

b =

0.3439 -1.3757 2.0636 -1.3757 0.3439

a =

1.0000 -2.0653 1.9792 -0.8971 0.2328

BUTTERWORTH HPF:

clear all;
alphap=0.4;
alphas=30;
fp=400;
fs=800;
f=2000;
omp=2*fp/f;
oms=2*fs/f;
[n,wn]=buttord(omp,oms,alphap,alphas)
[b,a]=butter(n,wn,'high')
w=0:0.1:pi;
[h,om]=freqz(b,a,w);
m=20*log(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('gain in dB');
xlabel('normalized frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in radians');
xlabel('normalized frequency');

n =

wn =

0.5821

b =

0.0535 -0.2139 0.3209 -0.2139 0.0535

a =

1.0000 0.6418 0.6165 0.1449 0.0259

BUTTERWORTH LPF:

clear all;
alphap=0.4;
alphas=30;
fp=400;
fs=800;
f=2000;
omp=2*fi/f;
oms=2*fs/f;
[n,wn]=buttord(omp,oms,alphap,alphas)
[b,a]=butter(n,wn)
w=0:0.01:pi;
[b,om]=freqz(b,a,w,whole);
m=abs(h);
an=angle(h);
subplot(2,1,1);
plot(om/pi,20*log(m));
ylabel('gain in dB');
xlabel('normalized frequency');
subplot(2,1,2);
plot(om/pi,an);
ylabel('phase in radians');
xlabel('normalized frequency');

>> lpf output


n = 4
wn = 0.5821
b = 0.1518 0.6073 0.9109 0.6073 0.1518
a =1.0000 0.6418 0.6165 0.1449 0.0259

1D AND 2D
%1D SEQUENCE

x=1:4
y=dct2(x)
subplot(2,1,1)
stem(x,y)
title('1D SEQUENCE')
xlabel('x(input)');
ylabel('y(dct output)');

%2D SEQUENCE

x=[1:4;5:8]
y=dct2(x,2,4)
subplot(2,1,2)
stem(x,y)
title('2D SEQUENCE')
xlabel('x(input)');
ylabel('y(dct output)');

x =

1 2 3 4

y =

5.0000 -2.2304 0 -0.1585

x =

1 2 3 4
5 6 7 8

y =

12.7279 -3.1543 0 -0.2242


-5.6569 0 0 0

DECIMATION AND INTERPOLATION

n=0:0.025:1;
x=sin(2*pi*2*n)+sin(2*pi*4*n)
y=decimate(x,2)
subplot(4,1,1)
stem(n,sin(2*pi*4*n))
title('input sequence')
subplot(4,1,2)
stem(n,sin(2*pi*2*n))
title('input sequence')
subplot(4,1,3)
stem(y)
title('decimation')
z=interp(x,2)
subplot(4,1,4)
stem(z)
title('interpolation')

x =

Columns 1 through 16

0 0.8968 1.5388 1.7601 1.5388 1.0000 0.3633 -0.1420


-0.3633 -0.2788 -0.0000 0.2788 0.3633 0.1420 -0.3633 -1.0000

Columns 17 through 32

-1.5388 -1.7601 -1.5388 -0.8968 -0.0000 0.8968 1.5388 1.7601


1.5388 1.0000 0.3633 -0.1420 -0.3633 -0.2788 -0.0000 0.2788

Columns 33 through 41

0.3633 0.1420 -0.3633 -1.0000 -1.5388 -1.7601 -1.5388 -0.8968


-0.0000

y =

Columns 1 through 16

0.0029 1.5289 1.5346 0.3677 -0.3566 0.0018 0.3530 -0.3640


-1.5378 -1.5273 -0.0018 1.5296 1.5386 0.3594 -0.3457 -0.0092

Columns 17 through 21

0.3609 -0.3660 -1.5440 -1.5119 -0.0252

z =

Columns 1 through 16

0.0000 0.4655 0.8968 1.2632 1.5388 1.7074 1.7601 1.7003


1.5388 1.2969 1.0000 0.6787 0.3633 0.0819 -0.1420 -0.2931

Columns 17 through 32

-0.3633 -0.3552 -0.2788 -0.1526 -0.0000 0.1526 0.2788 0.3552


0.3633 0.2931 0.1420 -0.0819 -0.3633 -0.6787 -1.0000 -1.2969

Columns 33 through 48

-1.5388 -1.7003 -1.7601 -1.7074 -1.5388 -1.2632 -0.8968 -0.4655


-0.0000 0.4655 0.8968 1.2632 1.5388 1.7074 1.7601 1.7003

Columns 49 through 64

1.5388 1.2969 1.0000 0.6787 0.3633 0.0819 -0.1420 -0.2931


-0.3633 -0.3552 -0.2788 -0.1526 -0.0000 0.1526 0.2788 0.3552

Columns 65 through 80
0.3633 0.2931 0.1420 -0.0819 -0.3633 -0.6787 -1.0000 -1.2969
-1.5388 -1.7003 -1.7601 -1.7074 -1.5388 -1.2632 -0.8968 -0.4655

Columns 81 through 82

-0.0000 0.4655

Vous aimerez peut-être aussi