Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
clear all;
close all;
clc;
Output
xout = 0
8 10
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
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
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
u1 =1
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');
Output
signal');
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
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
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)
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