I'm on it for a few hours trying to tweak it in all sort of ways but the output comes out scrambled and I can't understand why.
I am trying to implement an HPF with a stopband frequency of 500Hz and passband frequency of 600Hz. This is what I've done so far:
M=131072; %the number of samples
Wp=1200*pi; %passband cutoff frequency
m=0:M/2 %the sampling points
q=length(m);
Wm=2*pi*m./(M+1) %stopband cutoff frequency
mtr=ceil(Wp/(2*pi)) %round to positive part,i.e.ceil(3.5)=4;ceil(-3.2)=-3;
Ad=(Wm>=(Wp/(M+1)))
Ad(mtr)=0.38
Hd=Ad.*exp(-j*0.5*M*Wm) %frequency domain sampling vector H(k)
Hd=[Hd conj(fliplr(Hd(2:M/2+1)))]
h=real(ifft(Hd))
w=linspace(0,q,1966140) %linspace(x1,x2,n) generates n points. The spacing between the
%points is (x2-x1)/(n-1).
H=freqz(h,(1),w); %the amplitude -frequency characteristic diagram of the filter
figure(1)
plot(w,20*log10(abs(H))) %parameters are respectively the normalized frequency and
%amplitude
xlabel('the normailzed frequency');ylabel('gian/dB');
title('Gain response - HighPass Filter');
axis([0 2000 -50 2]);
the output of:
Ad=(Wm>=(Wp/(M+1)))
gives all 1's after cell 601 in the array (601 included).
after:
Ad(mtr)=0.38
I get all 1's after cell 600 in the array (600 included).
I think everything is ok until:
Hd=[Hd conj(fliplr(Hd(2:M/2+1)))]
and maybe something gets scrambled with something here:
w=linspace(0,q,1966140)
H=freqz(h,(1),w);
figure(4)
plot(w,20*log10(abs(H)))

qis undefined. It's also a lot easier to run if you terminate your statements with a semicolon – Hilmar Dec 22 '21 at 22:18