MATLAB: How to design IIR highpass filter with cutoff frequency, fc = 10 Hz using two other IIR filter? i already try using the butterworth but i dont know how to cut off the freq.

high pass filterhigh pass iir filter with cut off freq 10khz

clc; clear all; rp = input('Enter the passband ripple = '); rs = input('Enter the stopband ripple = '); wp = input('Enter the passband frequency = '); ws = input('Enter the stopband frequency = '); fs = input('Enter the sampling frequency = '); w1 = 2*wp/fs; w2 = 2*ws/fs; [n,wn] = buttord(w1,w2,rp,rs,'s'); [b,a] = butter(n,wn,'high','s'); w = 0:0.01:pi; [h,om] = freqs(b,a,w); m = 20*log10(abs(h)); an = angle(h); subplot(2,1,1); plot(om/pi,m); ylabel('Gain in dB —->'); xlabel('Normalised frequency —->'); title('Amplitude Response'); grid on; subplot(2,1,2); plot(om/pi,an); xlabel('Normalised frequency —->'); ylabel('Phase in radians —->'); title('Phase Response'); grid on;
Enter the passband ripple = 0.2 Enter the stopband ripple = 40 Enter the passband frequency = 2000 Enter the stopband frequency = 3500 Enter the sampling frequency = 8000

Best Answer

You are designing a lowpass filter by definition, since your stopband frequency is higher than your passband frequency.
For a highpass filter, the stopband frequency has to be lower than the passband frequency.
For a bandpass filter, your passband frequencies are a (1x2) vector of the upper and lower passbands, and your stopband frequencies are a (1x2) vector with the lower frequency lower than the lower passband frequency and the higher frequency higher than the higher passband frequency.
I would design the filter you describe similar to the way you are doing it, but with some significant differences. First, in your code, by using the 's' argument, you are instructing the butter function to design a continuous-time filter. That is not what you want if you are processing a sampled signal. (You then have to convert it to a discrete filter with the bilinear function to use it as a discrete filter.) The Signal Processing Toolbox functions assume that you want to design discrete filters by default, because that is how signals exist in computers. Second, I would also convert the transfer function to second-order-section representation to create a stable filter. Third, then use the freqz function, not freqs, to calculate and display the Bode plot. It will produce the plot by itself if you do not ask it for any outputs. Continuous filters are reasonable if you want to use them in Simulink or build them in hardware. (To build them in hardware, you first have to use circuit synthesis techniques to define the component values and configuration, and whether you want an active or passive design. I took a full year course on that in graduate school, so I will not even attempt to describe the process here.)
My code for your filter:
Fs = 8000;
Fn = Fs/2;
Wp = 2000/Fn;
Ws = 3500/Fn;
Rp = 0.2;
Rs = 40;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn);
[sos,g] = tf2sos(b,a);
figure(1)
freqz(sos, 2048, Fs)
EDIT I saw your Comment (that I deleted there) to my other Answer. To design a stable, highpass filter with a passband of 10 Hz, this works (assuming the same sampling frequency of 8 kHz):
Fs = 8000; % Highpass Design
Fn = Fs/2;
Wp = 10/Fn;
Ws = 3/Fn;
Rp = 0.2;
Rs = 40;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn,'high');
[sos,g] = tf2sos(b,a);
figure(1)
freqz(sos, 2048, Fs)
If you want to design a bandpass filter with a 10 Hz to 2000 Hz passband, this produces a stable filter:
Fs = 8000; % Bandpass Design
Fn = Fs/2;
Wp = [10 2000]/Fn;
Ws = [ 3 3500]/Fn;
Rp = 0.2;
Rs = 40;
[n,Wn] = buttord(Wp,Ws,Rp,Rs);
[b,a] = butter(n,Wn);
[sos,g] = tf2sos(b,a);
figure(1)
freqz(sos, 2048, Fs)
My general filter design procedure is here: How to design a lowpass filter for ocean wave data in Matlab?