cannot use element wise operator in frequency response?

1 view (last 30 days)
Hi guys,
I am trying to get the requency response of the averaging FIR filter using the element wise operator, code below:
Fs=8e3; % sampling frequency
Fc=170; % cutoff frequency
alpha=1-2*pi*Fc/Fs;
nb=round(log2(1/(1-alpha))); % number of shift to the right correspending to multiplication by alpha
NbPoints=1000;
Ndec=Fs/2/1000;
Fstart=1;
i=1:Ndec*NbPoints;
freq=Fstart*10.^(i/NbPoints);
H_f=(1-alpha)*cos(pi.*freq/Fs)/sqrt(1+(alpha^2)-2*alpha*cos(2*pi.*freq/Fs));
semilogx(freq,20*log10(abs(H_f)))
the problem the H_f provides me only one output and not the vector result. how can I fix this.
  3 Comments
SimTec
SimTec on 24 Aug 2022
my bad. I just corrected it.. I still do not get the value of the H_f as a vector
Bruno Luong
Bruno Luong on 24 Aug 2022
The division "/" before sqrt is NOT elemetwise division "./".

Sign in to comment.

Accepted Answer

Abderrahim. B
Abderrahim. B on 24 Aug 2022
Fs=8e3; % sampling frequency
Fc=170; % cutoff frequency
alpha=1-2*pi*Fc/Fs;
nb=round(log2(1/(1-alpha))); % number of shift to the right correspending to multiplication by alpha
NbPoints=1000;
Ndec=Fs/2/1000;
Fstart=1;
i=1:Ndec*NbPoints;
freq=Fstart*10.^(i/NbPoints)
freq = 1×4000
1.0023 1.0046 1.0069 1.0093 1.0116 1.0139 1.0162 1.0186 1.0209 1.0233 1.0257 1.0280 1.0304 1.0328 1.0351 1.0375 1.0399 1.0423 1.0447 1.0471 1.0495 1.0520 1.0544 1.0568 1.0593 1.0617 1.0641 1.0666 1.0691 1.0715
H_f=(1-alpha)*cos(pi.*freq/Fs)./sqrt(1+(alpha^2)-2*alpha*cos(2*pi.*freq/Fs))
H_f = 1×4000
1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000 1.0000
semilogx(freq,20*log10(abs(H_f)))

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!