I am using the freqz command, and the second argument, n, is documented as N-point frequency response. Therefore, I take it to mean that as n gets larger, the resolution of the frequency response should get finer and more smooth. But when I run this command, this is not what happens. Instead, I see the magnitude values changing. This makes no sense, and the documentation is quite poor.
MATLAB: Does the magnitude response of freqz change with the value of the input argument n
freqzMATLAB
Related Solutions
The passbands and stopbands for the Signal Processing Toolbox filter functions are actually normalised to the closed interval [0, pi] radians. It is calculated as the passband and stopband frequency in Hz divided by the Nyquist frequency.
Example for frequency calculations for the filters your signal:
Ts = 0.002; % Sampling Interval (seconds)
Fs = 1/Ts; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
Note that the highest frequency you can design in your filter is the Nyquist frequency, here 250 Hz.
An example of a Chebyshev Type II filter design for filtering an EKG signal is here:
Fs = 250; % Sampling Frequency (Hz)Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = [1.0 100]/Fn; % Passband Frequencies (Normalised)
Ws = [0.5 101]/Fn; % Stopband Frequencies (Normalised)
Rp = 10; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[sosbp,gbp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)freqz(sosbp, 2^17, Fs)EKG_filt = filtfilt(sosbp, gbp, EKG_original); % Filter EKG Signal
The filter passband goes from 1 Hz to 100 Hz.
Try this:
D = load('100m.mat');EKG = D.val; % Signal
L = numel(EKG); % Signal Length (Samples)
Fs = 360; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
t = linspace(0, L, L)/Fs; % Time Vector
b = fir1(12, (35/Fn)); % Order 12 FIR LPF Fco = 35 Hz
EKGfilt = filtfilt(b,1,EKG); % Filter Signal
figurefreqz(b,1, 2^12, Fs) % Display Filter Bode Plot
figureplot(t, EKG)hold onplot(t, EKGfilt)hold offgrid
The filter does not appear to be very effective, however it is what you requested, and from the freqz plot, has approximately 6 dB attenuation at 35 Hz.
EDIT — (29 Nov 2019 at 13:54)
Changed filter to filtfilt, since there appears to be significant phase delay usiung filter, even thouigh this is a FIR filter.
Best Answer