%%%%%%%%%%%%%%%%%%%%%%%%%%%%filtros diseño dia 18 de junio del 2015
%%%%%%%%%%%%%%%%%%%%%%%%%%%
M1=32;
M2=3;
fs=96000/2/96; %%%%frecuencia de paso
fp=450;
h=firpmord([450,500 ],[ 1,0 ] ,[ .01,0.001], 96000);%%%intruccion en firpm del lado izquierho h frez
[H,w]=freqz(h,1);
plot(w/pi, abs(H))
n
fo
%% %%%%%%%%%%%%%%%%%
%%
[n,f0,mo,w]=firpmord([450,2500 ],[ 1,0] ,[ .01/2,0.001], 96000);
h1=firpm(n,f0,mo,w);
n
f0
[H,w]=freqz(h1,1);
plot(w/pi, abs(H))
%% %%%%
[n,f0,mo,w]=firpmord([450,500 ],[ 1,0] ,[ .01/2,0.001], 3000);
n
f0
h2=firpm(n,f0,mo,w);
[H,w]=freqz(h2,1);
plot(w/pi, abs(H))
%%%%sr 96khz to 1 khz in 3 stages such tahat
%M1=8;
%M2=6;
%M3=2;
%F1=96000/8=12000;
%F2=12000/6=2000;
%F3=
[n,f0,mo,w]=firpmord([450,11500 ],[ 1,0] ,[ .01/3,0.001], 96000);
h5=firpm(n,f0,mo,w);
[H5,w]=freqz(h5,1)
plot(w/pi, abs(H5))
[n,f0,mo,w]=firpmord([450,1500 ],[ 1,0] ,[ .01/3,0.001], 12000);
h6=firpm(n,f0,mo,w);
[H6,w]=freqz(h6,1)
plot(w/pi, abs(H6))
[n,f0,mo,w]=firpmord([450,500 ],[ 1,0] ,[ .01/3,0.001], 12000);
h7=firpm(n,f0,mo,w);
[H7,w]=freqz(h7,1)
plot(w/pi, abs(H7))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Ejemplo con 4 etapas
%M1=4 M2=4 M3=3 M4=2
%F1=24000
%F2=24000/4=6000 fp=450 fs=2000-500
%F3=6000/3
[n,f0,mo,w]=firpmord([450,23500 ],[ 1,0] ,[ .01/4,0.001], 96000);
n
h1=firpm(n,f0,mo,w);
[H1,w]=freqz(h1,1)
plot(w/pi, abs(H1))
[n,f0,mo,w]=firpmord([450,55000 ],[ 1,0] ,[ .01/4,0.001], 24000);
n
h2=firpm(n,f0,mo,w);
[H2,w]=freqz(h2,1)
plot(w/pi, abs(H2))
%%%fs=2000-500
[n,f0,mo,w]=firpmord([450,1500 ],[ 1,0] ,[ .01/4,0.001], 24000);
n
h3=firpm(n,f0,mo,w);
[H2,w]=freqz(h2,1)
plot(w/pi, abs(H2))
%%%%fs=F4-500
[n,f0,mo,w]=firpmord([450,500 ],[ 1,0] ,[ .01/4,0.001], 2000);
n
h3=firpm(n,f0,mo,w);
[H2,w]=freqz(h2,1)
plot(w/pi, abs(H2))
%%%%%%
ff=[0,1/15,1.5/15,0.6,0.8,1];
a=[0,0,0.8,0.7,.9,0];
x=fir2(1000,ff,a);
x=5*x+0.01*sin(2*pi*(1:1001)*300/32000)+0.01*sin(2*pi*(1:1001)*400/32000;
X,F1=freqz(x,1,2048,32000);
plot()
%%%%1 etapa fp=900 fs=16000/16=1000
[n,f0,mo,w]=firpmord([900,1000 ],[ 1,0] ,[ .01,0.001], 32000);
n
h=firpm(n,f0,mo,w);
[H,F1]=freqz(h,1,2048,32000);
%plot(F1, abs(H))
grid
x1=filter(h,1,x);
[X1,F1]=freqz(x1,1,2048,32000);
%plot(F1,abs(X1))
grid
y=downsample(x1,16);
[n,f0,mo,w]=firpmord([900,1000 ],[ 1,0] ,[ .01,0.001], 32000);
n
h=firpm(n,f0,mo,w);
[H,F1]=freqz(h,1,2048,32000);
%plot(F1, abs(H))
grid
x1=filter(h,1,x);
[Y1,F1]=freqz(y,1,2048,2000);
plot(F1,abs(Y))
grid
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%F0=32000; M1=8 F1=4000 fp=900
%% %%%%%%%%
[n,f0,mo,w]=firpmord([900,3000 ],[ 1,0] ,[ .01/2,0.001], 32000);
n
h1=firpm(n,f0,mo,w);
[H,F1]=freqz(h,1,2048,32000);
x1=filter(h1,1,x);
[Y1,F1]=freqz(y1,1,2048,32000);
plot(F1,abs(Y1))
grid
y2=downsample(y1,8);
[Y2,F1]=freqz(y2,1,2048,4000);
plot(F1,abs(Y2))
grid
h2=firpm(n,f0,mo,w);
[H2,F1]=freqz(h2,1,2048,4000);
plot(F1,abs(H2))
y3=filter(h2,1,y2);
[Y3,F1]=freqz(y3,1,2048,4000);
plot(F1,abs(Y3))
grid
y4=downsample(y3,2);
[Y4,F1]=freqz(y4,1,2048,2000);
plot(F1,abs(Y4))
grid
%% %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% IFIR 29 de junio del 2015
%%(){}[]
%%%The basic idea of an ifir structure is to
wpg=Mw
%the normalized pasanand and stop band frequenies 0.1 and 0.12
dev=[(10^(Rp/20)/1]/(10^(Rp/20)+1),10^(-As/20)]
dev=[(10^(.1/20)/1]/(10^(.1/20)+1),10^(-60/20)]
[n,fo,mo,w]=firpmord([.1 .12],[1 0],dev)
n
h=firpm(n,fo,mo,w)
[H,w]=freqz(h,1)
plot(w/pi,20log10(abs(G))),grid
%%
%dev=[(10^(Rp/20)/1]/(10^(Rp/20)+1),10^(-As/20)]
dev=[(10^(.1/20)/1/(10^(.1/20)+1),10^(-60/20)]
[n,fo,mo,w]=firpmord([.1 .12],[1 0],dev)
n
g=firpm(n,fo,mo,w)
[G,w]=freqz(g,1)
plot(w/pi,20*log10(abs(G))),grid
gg=upsample(g,6)
[GG,w]=freqz(gg,1)
plot(w/pi,20*log10(abs(G))),grid
[n,fo,mo,w]=firpmord([.1 2/6 -.12],[1 0],dev/2)
n
hi=firpm(n,fo,mo,w)
[HI,w]=freqz(hi,1)
plot(w/pi,20*log10(abs(HI))),'b',w/pi/20*log 10(abs(HI)),grid,legend ('GG','HI'))
plot(w/pi,20*log10(abs(GG.*HI))),grid,legend ('IFIR'))
axis([0,.1,-.1,.1])%%banda de paso
axis([0.12,1,-220,-60])%%banda de rechazo
%%desing ifir
wp=.9
ws=.85
dp=.001
ds=.0001
%%
[n,fo,mo,w]=firpmord([.85 .9],[0 1],[.0001 .001])
n
h=firpm(n,fo,mo,w)
[H,w]=freqz(h,1)
g=firpm(n,fo,mo,w)
gg=upsample(g,4)
[GG,w]=freqz(gg,1)
%%1-.9 wp 1-.85ws
[n,fo,mo,w]=firpmord([.1*4 .15*4],[1 0],[.0001/2 .001/2])
n
g=firpm(n,fo,mo,w)
gg=upsample(g,4)
[GG,w]=freqz(gg,1)
figure
%plot(w/pi,abs(H)),grid%% esta mal
%Ws=2/M+ws=2/4+.15=.65
[n,fo,mo,w]=firpmord([.65 .9],[0 1],[.0001/2 .001/2])
hi=firpm(n,fo,mo,w)
HI=upsample(hi,4)
[HI,w]=freqz(hi,1)
plot(w/pi,abs(HI)),grid
%subplot(3,1,1),plot(w/pi,abs(GG)),grid
%subplot(3,1,2),plot(w/pi,abs(HI)),grid
%subplot(3,1,3),plot(w/pi,abs(HI)),grid
%N=
%banda de paso comprobar
plot(w/pi,abs(HI.*GG)),grid
axis([.9,1,1-.001,1+.001])
%banda de rechazo
axis([0,1,.85,0,.0001])
%% wp=[.4,.6]
%ws=[.35,.65]
%Dp=.001 Ds=.0001
[n,fo,mo,w]=firpmord([.35,.4,.6,.65],[0 1 0],[.0001 0.001/2 .0001])
n
h=firpm(n,fo,mo,w)
[H,w]=freqz(h,1)
plot(w/pi,abs(H)),grid
%.5=2/M m=4 wp=.1 ws=.15
%%
[n,fo,mo,w]=firpmord([.1*4 .15*4],[1 0],[.0001/2 .001/2])
n
g=firpm(n,fo,mo,w)
gg=upsample(g,4)
[GG,w]=freqz(gg,1)
plot(w/pi,abs(GG)),grid
%%
[n,fo,mo,w]=firpmord([.15,.4,.6,.85],[0 1 0],[.0001/2 .001/2 .0001/2])
n
hi=firpm(n,fo,mo,w)
HI=upsample(hi,4)
[GG,w]=freqz(gg,1)
plot(w/pi,abs(HI)),grid
plot(w/pi,abs(HI.*GG)),grid,legend('IFIR')
axis([0.65,1,0,.001])
plot(w/pi,abs(HI.*GG)),grid,legend('IFIR')%%%esta mal
%% [H, I]=ifir
%%wp=.1 ws=.15 rp=.01
[H,I]=ifir(6,'low',[0.1 0.15 ],[.01 .001])
[n,fo,mo,w]=firpmord([],[0 1 0],[.0001/2 .001/2 .0001/2])
n
[HH,w]=freqz(H,1)
[II,w]=freqz(I,1)
plot(3,1,1),plot(w/pi,abs(HH)),grid,legend('GG')
plot(3,1,2),plot(w/pi,abs(II)),grid,legend('Interp')
plot(3,1,3),plot(w/pi,abs(HH.*II)),grid,legend('IFIR')
%% dise;o de filtro pasa alta wp=.9 %%%falto todo de este ejercicio
[H,I]=ifir(5,'high',[0.81 ],[.01 .001])
[n,fo,mo,w]=firpmord([],[0 1 0],[.0001/2 .001/2 .0001/2])
%%
%% []{} dia 30 de junio del 2015,
%%k=[wp*M/2*pi] omhega=wpM-2k*pi beta=ws*M-2*k*pi
%%desing LP hLP(n)\'][/.,?><"|}[=-_+
%2 Find
h=fir1(14,.3)
stem(0 14,h)
grid,legend('Hl')
hi=/0.0011 0.0039 0.0160 0.0204 -0.0210 -0.1245 -0.2445 -.2984 -.2445 -.1245 -.0210 0.0204 0.0160 0.0039 -.0011
%%
[H,w]=freqz(h,1);
[H2,w]=freqz(h2,1);
subplot (3,1,1),plot(w/pi,abs(H)),grid legend('HLP=H')
subplot (3,1,2),plot(w/pi,abs(H2)),grid legend('HHP=H2')
subplot (3,1,3),plot(w/pi,abs(H)),'b',grid legend('HLP=HHP')
%%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%LP desing HP filter LP cpmplimentary
%wp=.9
%ws=.7
%Rp=Rs=.001
[n,fo,mo,w]=firpmord([.7 .9],[1 0],[0.001 0.001]);
n
h=firpm(n.fo,mo,w);
stem(0:32,h);grid , legend('h')
%N1=n/2+1=32/2+1=17
N1=17
h1=-h;
h1(17)=h1(17)+1;
%stem()
[H1,w]=freqz(h1,1);
plot(w/pi,abs(H1)),grid,legend('HHP=H1')
[H,w]=freqz(h,1)
subplot(3,1,1),plot(w/pi,abs(H1)),grid,legend('HLP=H')
subplot(3,1,2),plot(w/pi,abs(H1)),'r'grid,legend('HLP=H')
subplot(3,1,3),plot(w/pi,abs(H)),grid,legend('HLP=H')
%% desing BS filter wp=[0.1 ,.5] ws=[.2,.4] Rp=Rs=.001
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[n,fo,mo,w]=firpmord([.1,.2,.4,.5],[0 1 0],[0.001 0.001 0.001]);
n
hBP=firpm(n+1,fo,mo,w);
stem(0:66,hBP)
plot(w/pi,abs(hBP)),grid,legend('hBP')
hBS=-hBP;
hBS(34)=-hBP(34)+1;
stem(0:66,hBS),grid
plot(w/pi,abs(hBS)),grid,legend('hBS')
[HBP,w]=freqz(hBP,1);
[HBS,w]=freqz(hBS,1);
subplot(3,1,1),plot(w/pi,abs(HBP),'b'),grid,legend('HBP')
subplot(3,1,2),plot(w/pi,abs(HBS),'r'),grid,legend('HNS')
subplot(3,1,3),plot(w/pi,abs(HBP),'b'),grid,legend('HBP')
%%
%%%frequency masking filter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%we desing the fir wp=0.61 ws=.65 RP=RS=.001
[n,fo,mo,w]=firpmord([.61,.63],[0 1 0],[0.001 0.001]);
n
h=firpm(n+1,fo,mo,w);
[H,w]=freqz(h,1);
plot(w/pi,abs(H)),grid,legend('H')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M=4;
k=.61*4/2
%k=1
%% wpg=.61*4-2
wpg
wsg=.63*4-2
wsg=.52
%%
wp0=0.61
ws0=(2(k+1))
wp1=(2k/wpg)/M
%%
[n,fo,mo,w]=firpmord([.44,0.52],[1 0],[0.001/2 0.001/2]);
n
hBP=firpm(n+1,fo,mo,w);
N=n/2+1=46+1=47
g=firpm
gc(47)=-g(47)+1;
[G,w]=freqz(g,1);
[Gc,w]=freqz(gc,1);
subplot(2,1,1),plot(w/pi,abs(H)),grid,legend('H')
%%
gg=upsample(g,4);
ggc=upsample(gc,4);
[GG,w]=freqz(gg,1);
[GGc,w]=freqz(ggc,1);
subplot(2,1,1),plot(w/pi,abs(GG)),grid,legend('gg')
subplot(2,1,1),plot(w/pi,abs(GGc)),grid,legend('ggc')
%%
[n,fo,mo,w]=firpmord([.61,0.87],[1 0],[0.001/2 0.001/2]);
n
mfo=firpm(n+1,fo,mo,w);
[MFO,w]=freqz(mfo,1);
subplot(2,1,1),plot(w/pi,abs(MFO)),grid,legend('gg')
subplot(2,1,1),plot(w/pi,abs(GGc)),grid,legend('ggc')
%%
[n,fo,mo,w]=firpmord([.39,0.63],[1 0],[0.001/2 0.001/2]);
n
mf1=firpm(n,fo,mo,w);
[MF1,w]=freqz(mf1,1);
plot(w/pi,abs(MF1)),grid,legend('MF1')
subplot(2,1,1),plot(w/pi,abs(GG),'b',w/pi,abs(GGc),'--'),grid,legend('GG','MFO')
subplot(2,1,1),plot(w/pi,abs(GG),'b',w/pi,abs(GGc),'--'),grid,legend('GG','MFO')
subplot(2,1,1),plot(w/pi,abs(GGc),'b',w/pi,abs(GGc),'--'),grid,legend('GG','MFO')
subplot(2,1,1),plot(w/pi,abs(GF1),'b',w/pi,abs(GGc),'--'),grid,legend('GG','MF1')
%%%%%%
%%wp=.5 ws=0.55 Rp=.1 Rs=.01 M=5 .5*5-2=wpg wpg =.5 wsg=.55*
[n,fo,mo,w]=firpmord([.5,.75],[1 0],[0.0001/2 0.0001/2]);
g=firpm(n,fo.mo.w);
N=38/2+1
gc=g;
gc(20)=-g(20)+1;
[G,w]=freqz(g,1);
[Gc,w]=freqz(gc,1);
%plot*w/pi,abs(G),'b',w/pi,abs(Gc),'--')
gg=upsample(g,5);
ggc=upsample(gc,5);
[GG,w]=freqz(gg,1);
[GGc,w]=freqz(ggc,1);
mf1=firpm(n,fo,mo,w);
[MF1,w]=freqz(mf1,1);
plot(w/pi,abs(GGc),'b',w/pi,abs(GG),'--'),grid,legend('GG','MFO')
ws0=(4-.75)/5
ws0=
wp0=.5
[n,fo,mo,w]=firpmord([.5,.65],[1 0],[0.0001/2 0.0001]);
mf0=firpm(n,fo.mo.w);
wp1=(2-.5)/5;
[n,fo,mo,w]=firpmord([wp1,.55],[1 0],[0.0001/2 0.0001]);
mf1=firpm(n,fo.mo.w);
plot(w/pi,abs(MFO),'b',w/pi,abs(MF1),'--'),grid,legend('MF0','MF1')