I designed a FIR Kaiser windowed low pass digital filter with filter design app, and had MATLAB generate the code for it and return the filter object:
function Hd = filter_lp_100 %FILTER_LP_100 Returns a discrete-time filter object. % MATLAB Code % Generated by MATLAB(R) 9.2 and the DSP System Toolbox 9.4. % Generated on: 04-Aug-2017 17:09:08 % FIR Window Lowpass filter designed using the FIR1 function. % All frequency values are in Hz. Fs = 500; % Sampling Frequency Fpass = 100; % Passband Frequency Fstop = 110; % Stopband Frequency Dpass = 0.057501127785; % Passband Ripple Dstop = 0.0000000001; % Stopband Attenuation flag = 'scale'; % Sampling Flag % Calculate the order from the parameters using KAISERORD. [N,Wn,BETA,TYPE] = kaiserord([Fpass Fstop]/(Fs/2), [1 0], [Dstop Dpass]); % Calculate the coefficients using the FIR1 function. b = fir1(N, Wn, TYPE, kaiser(N+1, BETA), flag); Hd = dfilt.dffir(b);
But this filter does not attenuate the input signal, it even amplifies it! I expected that PSD for the output becomes smaller, or at most equal to input PSD(for the pass band) and that's not happening in any point. Please see the plots. Blue is input signal power spectrum density, Red is output PSD, and yellow is filter response.
I tried different filters, none of them is performing. My code is very simple, I copied the part that does filtering and plotting filter response:
%% FILTER %%%%%%%%%%%%%%%%%%%%%%%%%% coef=filter_lp_100; % MATLAB filter generated function above out_signal=filter(coef.numerator,1,in_signal); %%% plotting filter response. f is physical frequencies, fs is sampling rate: h=freqz(coef,f,fs); plot(f,10*log10(abs(h)))
Do you see anything wrong with this?