Sei sulla pagina 1di 17

%TWO CHANNEL QUADRATURE MIRROR FILTER BANK

%PERFECT RECONSTRUCTION OF INPUT

clear all;
close all;
clc;

x=[1 2 3 4 5];%INPUT SEQUENCE


%ANALYSIS FILTERS
H0=[1 1];
H1=[1 -1];
%SYNTHESIS FILTERS
G0=[1 1];
G1=[-1 1];
u0=downsample(conv(x,H0),2);
u1=downsample(conv(x,H1),2);
v0=conv(upsample(u0,2),G0);
v1=conv(upsample(u1,2),G1);
xout=(v0+v1)%OUTPUT IS PERFECT RECONSTRUCTION OF INPUT WITH UNIT
DELAY AND
DOUBLE AMPLITUDE

Output
xout = 0

8 10

%TWO CHANNEL QUADRATURE MIRROR FILTER BANK


%USING POLYPHASE DECOMPOSITION
%PERFECT RECONSTRUCTION OF INPUT
clear all;
close all;
clc;
N=input('enter the no of samples in your input= ');
n=1:N;
x=input('enter the input= ');
h=input('enter the h(n) of the low pass filter in the analysis
filter section= ');
k=1:2:length(h);
heven=h(k);
k=2:2:length(h);
hodd=h(k);
if(mod(length(h),2)~=0)
hodd(round(length(h)/2))=0;
end
%POLYPHASE COMPONENTS (2 band) of h(n)
P0=heven;
P1=hodd;
y(n+1)=x(n);
x(N+1)=0;
a=conv(downsample(x,2),P0);
b=conv(downsample(y,2),P1);
c=a+b;
d=a-b;
e=c+d;
f=c-d;
g=upsample(conv(e,P1),2);
h=upsample(conv(f,P0),2);
n=1:length(g);
y(n+1)=g(n);
h(length(h)+1)=0;
xout=y+h %output is perfect reconstruction of input except for
delay and
scaling

Output
enter the no of samples in your input= 4
enter the input= [1 2 3 4]
enter the h(n) of the low pass filter in the analysis filter section= [1 1]
xout =0

%M CHANNEL FILTER BANK


%USING POLYPHASE DECOMPOSITION
%PERFECT RECONSTRUCTION OF INPUT
clear all;
close all;
clc;
x=input('enter the input sequence= ');
M=input('enter the value of M-channel= ');
P=input('enter the polyphase matrix= ');
Q=fliplr(inv(P));
a=0;
for i=1:M
a=a+conv(upsample(downsample(conv(x,P(i,1:M)),M),M),Q(i,1:M));
end
Xout=a

Output
enter the input sequence= [1 2 3 4 5]
enter the value of M-channel= 3
enter the polyphase matrix= [1 1 1;1 -1 1;1 1 -1]
Xout =0

%PROGRAM FOR FILTERING AUDIO THROUGH LINEAR AND NON LINEAR


FILTERS
clear all;
close all;
clc;
[x,fs]=audioread('1.mp3');%sound(x,fs);
c=input('press 1 for linear filter and 2 for non-linear filter=
');
if c==1
b=input('enter the linear FIR filter coefficients= ');
y=filter(b,1,x);
sound(y,fs);
end
if c==2
b=input('enter the non-linear FIR filter coefficients= ');
y=filter(b,1,x);
sound(y,fs);
end

%PROGRAM OF UPSAMPLING AND RECONSTRUCTION

clear all;
close all;
clc;
%frequency spectrum of bandlimitted iinput
freq=[0 .45 .5
1];
mag=[0 1 0 0 ];
x=fir2(100,freq,mag);
[xz,w]=freqz(x,1,512);
L=input('enter the upsampling factor= ');
subplot(3,1,1);
plot(w/pi,abs(xz));grid;xlabel('w/pi');ylabel('magnitude');title
('input spectrum(band limitted)');
%upsample by a factor L and its frequency spectrum
y=upsample(x,L);
[yz,an]=freqz(y,1,512);
subplot(3,1,2);
plot(an/pi,abs(yz));grid;xlabel('w/pi');ylabel('magnitude');
title('spectrum of upsampled signal');
%reconstruction of original spectrum
z=5*decimate(y,L);
[num, den]=freqz(z,1,512);
subplot(3,1,3)
plot(den/pi,abs(num));grid;xlabel('w/pi');ylabel('magnitude');
title('reconstructed original spectrum');

Output
enter the upsampling factor= 4

%ASSIGNMENT PROGRAM(NOV_27)
%CHECKING RELATION OF U1,U2,U3,U4 WITH V1,V2,V3,V4

clear all;
close all;
clc;
x_input=[1 2 3 4];
N=4;
y_input=zeros(1,4);
for k=0:3
y_input(k+1)=(x_input(k+1))*(exp(-1i*0*k));
end
y_output=conv(y_input,[1 1 1 1]);
v1=downsample(y_output,4)
for k=0:3
y_input(k+1)=(x_input(k+1))*(exp(-1i*(pi/2)*k));
end
y_output=conv(y_input,[1 1 1 1]);
v2=downsample(y_output,4)
for k=0:3
y_input(k+1)=x_input(k+1)*exp(-1i*pi*k);
end
y_output=conv(y_input,[1 1 1 1]);
v3=downsample(y_output,4)
for k=0:3
y_input(k+1)=x_input(k+1)*exp(-1i*(3*pi/2)*k);
end
y_output=conv(y_input,[1 1 1 1]);
v4=downsample(y_output,4)
y_output=conv([1 1 1 1],x_input);
u1=downsample(y_output,4)
y_output=conv(x_input,[1 1i -1 -1i]);
u2=downsample(y_output,4)

y_output=conv(x_input,[1 -1 1 -1]);
u3=downsample(y_output,4)
y_output=conv(x_input,[1 -1i -1 1i]);
u4=downsample(y_output,4)

Output
v1 =1

v2 =1.0000 + 0.0000i -3.0000 + 2.0000i


v3 =1.0000 + 0.0000i -3.0000 - 0.0000i
v4 =1.0000 + 0.0000i -3.0000 - 2.0000i

u1 =1

u2 =1.0000 + 0.0000i -3.0000 + 2.0000i


u3 = 1 -3
u4 = 1.0000 + 0.0000i -3.0000 - 2.0000i

%PROGRAM FOR UPSAMPLING OF A SAMPLED SIGNAL AND PASSING THROUGH


IT THROUGH A FILTER

clear all;
close all;
clc;
%input signal
t=0:.0001:1;
fm=2;
x=4*sin(2*pi*fm*t);
subplot(7,1,1);
plot(t,x);title('input signal');
%sampled signal
fs=8*fm;
T=1/fs;
n=0:50;
xsam=4*sin(2*pi*(fm/fs)*n);
subplot(7,1,2);
stem(n,xsam);title('sampled signal');
%upsampled signal
l=2;
xupsam=upsample(xsam,2);
n=1:length(xupsam);
subplot(7,1,3);
stem(n,xupsam);title('upsampled signal')
%dft of sampled signal
xsamdft=fft(xsam,32);
subplot(7,1,4);
plot(abs(xsamdft));title('dft of sampled signal');
%dft of upsampled signal
xupsamdft=fft(xupsam,32);
subplot(7,1,5);
plot(abs(xupsamdft));title('dft of upsampled signal');
%design of filter
[b,a]=butter(10,.9989);
[z,p]=bilinear(b,a,fs);
h=filter(z,p,xupsam);
subplot(7,1,6);
n=1:102;
stem(n,h);title('filtered signal');

%dft of filtered signal


xfiltered=fft(h,32);
subplot(7,1,7);
plot(abs(xfiltered));title('dft of filtered

Output

signal');

% PROGRAM FOR CHECKING-FREQUENCY RESPONSE OF ANALYSIS FILTERS ARE


UNIFORMLY SHIFTED VERSIONS OF H0(W)
% 2 CHANNEL (N=2)

clear all;
close all;
clc;
%BANDLIMITTED SPECTRUM CREATION
freq=[0 .45 .5
1];
mag=[0 1 0 0 ];
x=fir2(50,freq,mag);
[xz,w]=freqz(x,1,512);
subplot(2,1,1);
plot(w/pi,abs(xz));grid;xlabel('normalized
frequency');ylabel('magnitude');
title('spectrum of analysis filter H0(W)');
k=1:25;
x(2*k)=-1*x(2*k);
[xz,w]=freqz(x,1,512);
subplot(2,1,2);
plot(w/pi,abs(xz));grid;xlabel('normalized
frequency');ylabel('magnitude');
title('spectrum of analysis filter H1(W)');

Output

%DESIGN OF BUTTERWOTH LOWPASS FILTER

clear all;
close all;
clc;
Ap=input('enter the passband ripple in db = ');
As=input('enter the stopband ripple in db = ');
Fp=input('enter the passband edge frequency = ');
Fs=input('enter the stopband edge frequency = ');
Fsam=input('enter the sampling frequency = ');
d=input('enter 1 for to meet passband and 2 for to meet
stopband= ');
omegap=2*pi*Fp/Fsam;
omegas=2*pi*Fs/Fsam;
omegap=2*tan(omegap/2);
omegas=2*tan(omegas/2);
if omegap>omegas
disp('enter correctly(Fs value should be higher than Fp for
lowpass)');
else
N=.5*log((10^(.1*As)-1)/(10^(.1*Ap)1))/(log(omegas/omegap));
N=ceil(N)
if d==1
omegacut=omegap/((10^(.1*Ap)-1)^(1/(2*N)))
end
if d==2
omegacut=omegas/((10^(.1*As)-1)^(1/(2*N)))
end
for k=0:N-1
S(k+1)=omegacut*exp(1i*pi*.5)*exp(1i*((2*k)+1)*pi/(2*N));
end
z=[];
p=S;
[n,de]=zp2tf(z,p,omegacut^N);
h=tf(n,de)
[numd,dend] = bilinear(n,de,1);
H=tf(numd,dend,1,'variable','z^-1') %H(z)
[mag,pha]=freqz(numd,dend);
figure;
plot(pha/pi,20*log(abs(mag)));
grid;

xlabel('NORMALIZED FREQUENCY')
ylabel('MAGNITUDE IN dB')
figure;
plot(pha/pi,pha);
grid;
xlabel('NORMALIZED FREQUENCY')
ylabel('PHASE')
figure;
pzmap(H);
end

%DESIGN OF BUTTERWOTH HIGHPASS FILTER

clear all;
close all;
clc;
Ap=input('enter the passband ripple in db = ');
As=input('enter the stopband ripple in db = ');
Fp=input('enter the passband edge frequency = ');
Fs=input('enter the stopband edge frequency = ');
Fsam=input('enter the sampling frequency = ');
d=input('enter 1 for to meet passband and 2 for to meet
stopband= ');
omegap=2*pi*Fp/Fsam;
omegas=2*pi*Fs/Fsam;
omegap=2*tan(omegap/2);
omegas=2*tan(omegas/2);
if omegap<omegas
disp('enter correctly(Fp value should be higher than Fs
for lowpass)');
else
omegapl=1;
omegasl=omegap/omegas;
N=.5*log((10^(.1*As)-1)/(10^(.1*Ap)1))/(log(omegasl/omegapl));
N=ceil(N);
if d==1
omegacut=omegapl/((10^(.1*Ap)-1)^(1/(2*N)));
end
if d==2
omegacut=omegasl/((10^(.1*As)-1)^(1/(2*N)));
end
for k=0:N-1
S(k+1)=omegacut*exp(1i*pi*.5)*exp(1i*((2*k)+1)*pi/(2*N));
end
z=[];
p=S;
[n,de]=zp2tf(z,p,omegacut^N);
h=tf(n,de)
for k=1:N+1
de(k)=de(k)*omegap^N;
N=N-1;
end
de=fliplr(de);

n=fliplr(n);
h=tf(n,de);
[numd,dend] = bilinear(n,de,1);
H=tf(numd,dend,1,'variable','z^-1')
[mag,pha]=freqz(numd,dend);
figure;
plot(pha/pi,20*log(abs(mag)));
grid;
xlabel('FREQUENCY(Hz)')
ylabel('MAGNITUDE IN dB')
figure;
plot(pha/pi,pha);
grid;
xlabel('FREQUENCY(Hz)')
ylabel('phase')
figure;
pzmap(H);
end

%H(z)

%DESIGN OF CHEBYSHEV LOWPASS FILTER

clear all;
close all;
clc;
Ap=input('enter the passband ripple in db = ');
As=input('enter the stopband ripple in db = ');
Fp=input('enter the passband edge frequency = ');
Fs=input('enter the stopband edge frequency = ');
Fsam=input('enter the sampling frequency = ');
omegap=2*pi*Fp/Fsam;
omegas=2*pi*Fs/Fsam;
omegap=2*tan(omegap/2);
omegas=2*tan(omegas/2);
if omegap>omegas
disp('enter correctly(Fs value should be higher than Fp for
lowpass)');
else
N=acosh(((10^(.1*As)-1)/(10^(.1*Ap)1))^.5)/(acosh(omegas/omegap));
N=ceil(N)
ep=(10^(.1*Ap)-1)^.5;
beta=((((1+ep^2)^.5)+1)/(ep))^(1/N);
r1=(((beta^2)+1)/(2*beta));
r2=(((beta^2)-1)/(2*beta));
pole=zeros(1,N);
for k=0:N-1
phi=(pi/2)+((2*k+1)*pi)/(2*N);
pole(k+1)=r2*cos(phi)+(1i*r1*sin(phi));
end
zero=[];
[num,den]=zp2tf(zero,pole,1);
num(N+1)=num(N+1)*den(N+1);
if mod(N,2)==0
num(N+1)=num(N+1)/(1+ep^2)^.5;
else
num(N+1)=-num(N+1);
end
h=tf(num,den)
numerator=[];
denominator=[];
numerator(N+1)=num(N+1)*omegap^N;
for k=0:N

end

denominator(k+1)=den(k+1)*omegap^k;

h_low=tf(numerator,denominator)
[b,a]= bilinear(numerator,denominator,1);
H_digital=tf(b,a,1,'variable','z^-1') %H(z)
[mag,pha]=freqz(b,a);
figure;
plot(pha/pi,20*log(abs(mag)));
grid;
xlabel('NORMALIZED FREQUENCY')
ylabel('MAGNITUDE IN dB')
figure;
plot(pha/pi,pha);
grid;
xlabel('NORMALIZED FREQUENCY')
ylabel('PHASE')
figure;
pzmap(H_digital);
end

Potrebbero piacerti anche