This code shows the FIR filter magnitude response with the normalized frequency from 0 to pi, how i can make mirroring of this magnitude response to start from -pi to pi ??

조회 수: 5 (최근 30일)
This code shows the FIR filter magnitude response with the normalized frequency through interval from [0 to pi] in a figure, my question is how i can make mirroring of this magnitude response to start through interval from [-pi to pi] ??
clc;
close all;
clear all;
n1= 15; %order
Fs= 100; %sampling frequency
fc= Fs/4; %cutoff frequency
%nyq_f= Fs/2; %normalize cutoff frequency wrt to nyquist freq
%wn= fc/nyq_f; %normalized fc
wc= (2*pi*fc)/Fs;
wn= wc/pi;
%window= hamming(n+1)
H1= fir1(n1,wn,hamming(n1+1));
h1= freqz(H1); %frequency response
f1= linspace(0,Fs/2,512);
w1= (2*pi*f1)/Fs;
w= w1/pi;
plot (w, abs(h1))
axis([0 1 -0.1 1.1])

답변 (1개)

Mathieu NOE
Mathieu NOE 2022년 5월 9일
hello
here you are (nothing fancy !)
clc;
close all;
clear all;
n1= 15; %order
Fs= 100; %sampling frequency
fc= Fs/4; %cutoff frequency
%nyq_f= Fs/2; %normalize cutoff frequency wrt to nyquist freq
%wn= fc/nyq_f; %normalized fc
wc= (2*pi*fc)/Fs;
wn= wc/pi;
%window= hamming(n+1)
H1= fir1(n1,wn,hamming(n1+1));
h1= freqz(H1); %frequency response
f1= linspace(0,Fs/2,512);
w1= (2*pi*f1)/Fs;
w= w1/pi;
h1_mag = abs(h1);
plot (w, h1_mag)
axis([0 1 -0.1 1.1])
% This code shows the FIR filter magnitude response with the normalized frequency through interval from [0 to pi] in a figure,
% my question is how i can make mirroring of this magnitude response to start through interval from [-pi to pi] ??
w_flip = flip(w);
h1_mag_flip = flip(h1_mag);
w_all = [-w_flip(1:end-1) w];
h1_mag_all = [h1_mag_flip(1:end-1); h1_mag];
plot (w_all, h1_mag_all)
axis([-1 1 -0.1 1.1])

카테고리

Help CenterFile Exchange에서 Digital and Analog Filters에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by