# How to use freqz to plot the frequency response from neg frequency to pos frequency

11 visualizzazioni (ultimi 30 giorni)
YAMENG SONG il 6 Feb 2024
Risposto: Paul il 7 Feb 2024
Hi, I'm building a low pass filter with kasier window, but when I plot the frequency respnose I found it could only plot half of it (0 to positve), and it looks like this:
how should I plot the other half? (neg freq to 0)
here's my code
f_sampling = 40e3; % sampling frquency
f_pass = 10e3; % pass-band frequency
f_stop = 15e3; % stop-band frequency
A_dB = 80; % stop-band attenuations
Beta=A_dB/10 +0.5; % Increasing β widens the mainlobe and decreases the amplitude of the sidelobes (i.e., increases the attenuation).
N_window = (f_sampling/(f_stop - f_pass))*A_dB/15;
N_remez = (f_sampling/(f_stop - f_pass))*A_dB/22;
% maksure N is an odd number
N_window=floor(N_remez);
if rem(N_window,2)==0
N_window=N_window+1;
end
%Compute end points of array interval NN
NN=(N_window-1)/2;
% Compute 6 dB gain band edge frequency f0
f_mid = (f_pass + f_stop)/2;
% window building
phi=2*pi*(-NN:NN)*f_mid/f_sampling;
h=sin(phi)./phi;
h(NN+1)=1;
h0=h.*kaiser(2*NN+1,Beta)';
h1=h0*(f_pass + f_stop)/f_sampling;
% Frequency response
[H1, w1] = freqz(h1, 1, 8000, f_sampling);
maxGain_dB = max(20*log10(abs(H1(1:find(w1>f_pass,1)))));
% Plotting
figure(1);
% Impulse Response
subplot(2, 1, 1);
n = -NN:NN;
stem(n, h1);
title('Impulse Response of the Filter');
xlabel('window length');
ylabel('Amplitude');
% Frequency Response (Magnitude)
subplot(2, 1, 2);
plot(w1, 20 * log10(abs(H1)));
title('Frequency Response of the Filter');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
ylim([-100, 30]);
xlim([-f_sampling/2, f_sampling/2]);
grid on;
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

Voss il 6 Feb 2024
Here's one way:
f_sampling = 40e3; % sampling frquency
f_pass = 10e3; % pass-band frequency
f_stop = 15e3; % stop-band frequency
A_dB = 80; % stop-band attenuations
Beta=A_dB/10 +0.5; % Increasing β widens the mainlobe and decreases the amplitude of the sidelobes (i.e., increases the attenuation).
N_window = (f_sampling/(f_stop - f_pass))*A_dB/15;
N_remez = (f_sampling/(f_stop - f_pass))*A_dB/22;
% maksure N is an odd number
N_window=floor(N_remez);
if rem(N_window,2)==0
N_window=N_window+1;
end
%Compute end points of array interval NN
NN=(N_window-1)/2;
% Compute 6 dB gain band edge frequency f0
f_mid = (f_pass + f_stop)/2;
% window building
phi=2*pi*(-NN:NN)*f_mid/f_sampling;
h=sin(phi)./phi;
h(NN+1)=1;
h0=h.*kaiser(2*NN+1,Beta)';
h1=h0*(f_pass + f_stop)/f_sampling;
% Frequency response
[H1, w1] = freqz(h1, 1, 8000, f_sampling);
maxGain_dB = max(20*log10(abs(H1(1:find(w1>f_pass,1)))));
% Plotting
figure(1);
% Impulse Response
subplot(2, 1, 1);
n = -NN:NN;
stem(n, h1);
title('Impulse Response of the Filter');
xlabel('window length');
ylabel('Amplitude');
% Frequency Response (Magnitude)
subplot(2, 1, 2);
% plot(w1, 20 * log10(abs(H1)));
plot([-flip(w1); w1], 20 * log10(abs([flip(H1); H1])));
title('Frequency Response of the Filter');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
ylim([-100, 30]);
xlim([-f_sampling/2, f_sampling/2]);
grid on;
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Paul il 7 Feb 2024
Use the third argument to freqz to specify the desired frequency points:
f_sampling = 40e3; % sampling frquency
f_pass = 10e3; % pass-band frequency
f_stop = 15e3; % stop-band frequency
A_dB = 80; % stop-band attenuations
Beta=A_dB/10 +0.5; % Increasing β widens the mainlobe and decreases the amplitude of the sidelobes (i.e., increases the attenuation).
N_window = (f_sampling/(f_stop - f_pass))*A_dB/15;
N_remez = (f_sampling/(f_stop - f_pass))*A_dB/22;
% maksure N is an odd number
N_window=floor(N_remez);
if rem(N_window,2)==0
N_window=N_window+1;
end
%Compute end points of array interval NN
NN=(N_window-1)/2;
% Compute 6 dB gain band edge frequency f0
f_mid = (f_pass + f_stop)/2;
% window building
phi=2*pi*(-NN:NN)*f_mid/f_sampling;
h=sin(phi)./phi;
h(NN+1)=1;
h0=h.*kaiser(2*NN+1,Beta)';
h1=h0*(f_pass + f_stop)/f_sampling;
Change here
% Frequency response
freq = linspace(-f_sampling/2,f_sampling/2,16000);
H1 = freqz(h1, 1, freq, f_sampling);
plot(freq, 20 * log10(abs(H1)));
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Multirate Signal Processing in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by