MATLAB: How should I remove low frequency noises with Highpass filter

accelerometerfiltfilthighpass filteriir

I have some data from accelerometer in three directions (x,y,z). They have been taken at three hours with sampling rate of 5120. It tried to filter out the noises before 1 Hz or even 3 Hz but I have not been successful. I used iir with butterwoth and cheby2. I got some values even more than raw data or the same. I got error when I used filtfilt function. Anybody has idea?
Thanks

Best Answer

I tried this way to verify my filtration. The maximum value for raw data is 17.5 and I tried to filter out for the frequency range of 1-500 , 1-2560, 3-500 and 3-2560 Hz. I got values higher than 17.5. I created the signal at the following modal frequencies.
Mode Freq 1 1.5 2 5.2 3 5.5 4 8.2 5 9.4 6 13.3 7 16.1 8 20.1 9 23.2 10 27.2 11 30.3 12 31.2 13 31.7 14 37.4 15 45.0 16 55.1 17 56.9 18 64.3 19 71.3 20 85.2 21 90.6 22 111.1 23 112.5 24 122.0 25 127.8 26 131.8 27 141.8 28 159.1 29 176.0 30 179.0 31 187.7
I tried the following code
time=1000; fs= 5120;
t=linspace(0,time,fs*time); N=length(t);
loopvariable=xlsread('ModalFrequencies.xlsx'); y=0;
for counter = 1 : length(loopvariable) f = loopvariable(counter,2); y = y + sin(2*pi*f*t); end
%-----------------------Filter and Loop for all chosen frequencies------- for counter = 1:length(loopvariable)
%Filter parameters
low_freq_cutoff = loopvariable(counter,1); %lower cutoff frequency in Hz high_freq_cutoff= loopvariable(counter,2); %high cutoff frequency in Hz
if s == 1 %Create the filter (BandPass) Fs = 5120; % Sampling Frequency
Fstop1 = low_freq_cutoff; % First Stopband Frequency Fpass1 = low_freq_cutoff+2; % First Passband Frequency Fpass2 = high_freq_cutoff-5; % Second Passband Frequency Fstop2 = high_freq_cutoff; % Second Stopband Frequency Astop1 = 10; % First Stopband Attenuation (dB) Apass = 1; % Passband Ripple (dB) Astop2 =10; % Second Stopband Attenuation (dB) match = 'stopband'; % Band to match exactly
% Construct an FDESIGN object and call its BUTTER method. h = fdesign.bandpass(Fstop1, Fpass1, Fpass2, Fstop2, Astop1, Apass, ... Astop2, Fs); Hd = design(h, 'butter', 'MatchExactly', match); else %Create the filter (HighPass)
Hd1 = designfilt('lowpassiir','FilterOrder',12, ... 'HalfPowerFrequency',0.15,'DesignMethod','butter'); %Create the filter (LowPass) Fs = 5120; % Sampling Frequency
Fpass = high_freq_cutoff-5; % Passband Frequency Fstop = high_freq_cutoff; % Stopband Frequency Apass = 0.2; % Passband Ripple (dB) Astop = 60; % Stopband Attenuation (dB) match = 'stopband'; % Band to match exactly
% Construct an FDESIGN object and call its BUTTER method. h = fdesign.lowpass(Fpass, Fstop, Apass, Astop, Fs); Hd2 = design(h, 'cheby2', 'MatchExactly', match);; end
%-------------------------Gather all the data from the chosen files---------------
%Apply Filter and append to results if s == 1 %Apply bandpass if unitToggle == 1 %Means selection is in/s, so adjust to mm/s y_filtered = filter(Hd,y); else y_filtered = filtfilt(Hd,y); end else %Apply High/Low Pass if unitToggle == 1 %Means selection is in/s, so adjust to mm/s y_filtered = filter(Hd1,y); else y_filtered = filter(Hd1,y); end end
%-----------------get the maximums and minimums. We need the minimums in case the magnitude---------- %is larger than the max y_filtered_max = max(y_filtered);
y_filtered_min = min(y_filtered);
y_filtered_max = max([y_filtered_max abs(y_filtered_min)]);
%Write the maximums to the output table OutputSummary(counter+1,1) = low_freq_cutoff; OutputSummary(counter+1,2) = high_freq_cutoff; OutputSummary(counter+1,3) = y_filtered_max;
end