clear all; close all; wc = 0.5*pi; wc1 = 0.25*pi; wc2 = 0.75*pi; N = 13; alpha = (N-1)/2; eps = 0.001; n = 0:1:(N-1); hd = sin(wc*(n-alpha+eps))./(pi*(n-alpha+eps)); %%LPF %hd = (sin(pi*(n-alpha+eps))-sin(wc*(n-alpha+eps)))./(pi*(n-alpha+eps)); %%HPF %hd = (sin(wc2*(n-alpha+eps))-sin(wc1*(n-alpha+eps)))./(pi*(n-alpha+eps)); %%BPF %hd = (sin(wc1*(n-alpha+eps))-sin(wc2*(n-alpha+eps)) + sin(pi*(n-alpha+eps)))./(pi*(n-alpha+eps)); %%BRF wr = boxcar(N); hn = hd .* wr'; w = 0:0.01:pi; h = freqz(hn,1,w); %plot(w/pi,abs(h)); % hold on wh = 100*hamming(N); %wh = blackman(N); %wh = hann(N); %wh = bartlett(N); %wh = kaiser(N,8.885); hn = hd.*wh'; hn1 = hn'; xlswrite('D:\PHD\OMP_ASIC\hn1.xlsx',hn1); w = 0:0.01:pi; h1 = freqz(hn,1,w); figure(1) plot(w/pi,abs(h1),'-.'); xlabel('Normalized Frequency') ylabel('Magnitude') %hn = xlsread('D:\PHD\OMP_ASIC\hn1.xlsx'); %%%%%%%%%%%%% Filter verification %%%%%%%%%%%%%%%%%% ts=1/100e3; t = 0:ts:2e-3; x = sin(2*pi*22e3*t) .* sin(2*pi*20e3*t); xlswrite('D:\PHD\OMP_ASIC\xin.xlsx',x); y = filter(hn,1,x); mxy = max(y); figure(2) plot(t,y); xlabel('Time') ylabel('Amplitude') %hn1 = hn'; % %%%% Direct form to Lattice structure...... hnlatice = tf2latc(hn); [f,g] = latcfilt(hnlatice,x); xlswrite('D:\PHD\OMP_ASIC\hn2.xlsx',hnlatice); %y1 = filter(hnlatice,1,x); % %%%% Direct form to Cascade structure...... [b,a] = eqtflength(hn',1); % make lengths equal [z,p,k] = tf2zp(b,a); sos = zp2sos(z,p,k); xlswrite('D:\PHD\OMP_ASIC\hn3.xlsx',sos(:,1:3)); % lpf_out = xlsread('D:\PHD\OMP_ASIC\op.xlsx'); lpf_out1 = downsample( lpf_out , 2); xlswrite('D:\PHD\OMP_ASIC\op_float.xlsx',lpf_out1); fm = max(f); lpf_out1 = xlsread('D:\PHD\OMP_ASIC\op1.xlsx'); lpfom = lpf_out1/max(lpf_out1); ym = y/max(y); figure(3) plot(1:201,x); xlabel('Time') ylabel('Amplitude') xlim([0 201]) RMSE = norm(ym - lpfom')/norm(ym);