MATLAB Answers

Filtering high frequencies from response signal

35 views (last 30 days)
Joe Bennet
Joe Bennet on 20 Jan 2021
Commented: Star Strider on 21 Jan 2021
I have a data set comprising a number of strain measurements obtained from a strain gauge and would like to filter out the ultra high frequncy noise present inbetween the seperate measurements. See code attached below :)
clc, clear, close all;
t= g{:,1};
sm= g{:,3};
sm= rmmissing(sm);
t = arrayfun(@(i) mean(t(i:i+n-1)),1:n:length(t)-n+1)';
sm= arrayfun(@(i) mean(sm(i:i+n-1)),1:n:length(sm)-n+1)';
xlabel('Time Elapsed (s)')
title('Strain Signal')
fs= 6.2e-4;


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 20 Jan 2021
Try this:
D1 = load('7004x4.mat');
T1 = D1.g;
Q1 = T1(1:5,:);
t = T1{:,1};
sm = T1{:,3};
t = rmmissing(t);
sm = rmmissing(sm);
% Signal Vector
L = size(sm,1); % Data Length
Fs = 1/mean(diff(t)); % Sampling Frequency
Ts = 1/Fs; % Sampling Interval
Fn = Fs/2; % Nyquist Frequency
smc = sm - mean(sm); % Subtract Mean (Makes Other Peaks More Prominent)
FTsm = fft(smc)/L; % Normalised Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector (One-Sided Fourier Transform)
plot(Fv, abs(FTsm(Iv))*2)
xlim([0 50])
title('Fourier Transform')
xlabel('Frequency (Hz)')
Wp = [30]/Fn; % Passband Frequency (Normalised)
Ws = [1.01].*Wp; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 60; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
freqz(sos, 2^20, Fs) % Filter Bode Plot
set(subplot(2,1,1), 'XLim',Wp*Fn.*[0.8 1.2]) % Optional
set(subplot(2,1,2), 'XLim',Wp*Fn.*[0.8 1.2]) % Optional
sm_filtered = filtfilt(sos, g, sm); % Filter With IIR Filter
plot(t, sm)
hold on
plot(t, sm_filtered)
hold off
xlabel('Time (Units Estimated)')
ylabel('AMplitude (Units Not Specified)')
legend('Original Signal', 'Lowpass-Filtered Signal', 'Location','SE')
Adjust the value of ‘Wp’ (Passband Frequency) of the filter to get the result you want. The Fourier transform plot can help with that decision.


Show 2 older comments
Star Strider
Star Strider on 20 Jan 2021
It would be straightforward to change that code to a bandpass filter.
Change ‘Wp’ and ‘Ws’ respectively to:
Wp = [Flo Fhi]/Fn; % Passband Frequency (Normalised)
Ws = [0.9 1.1].*Wp; % Stopband Frequency (Normalised)
where ‘Flo’ and ‘Fhi’ are the frequencies that define the filter passband. All of them must be between (that is, not including) 0 Hz and the Nyquist frequency. AAgain, use the Fourier Transform plot to guide your choices.
I would not use the Savitzky-Golay filter on your signal, since while useful in many situations, is difficult to use as a frequency-selective filter with your signal. It is primarily useful to eliminate broadband noise, and your signal has frequency-limited noise that you can eliminate with a frequency-selective filter.
Star Strider
Star Strider on 21 Jan 2021
My pleasure!
If my Answer helped you solve your problem, please Accept it!

Sign in to comment.

More Answers (1)

Mathieu NOE
Mathieu NOE on 20 Jan 2021
try also sgolayfilt
function y=sgolayfilt(x,order,framelen,weights,dim)
%SGOLAYFILT Savitzky-Golay Filtering.
% SGOLAYFILT(X,ORDER,FRAMELEN) smooths the signal X using a
% Savitzky-Golay (polynomial) smoothing filter. The polynomial order,
% ORDER, must be less than the frame length, FRAMELEN, and FRAMELEN must
% be odd. The length of the input X must be >= FRAMELEN. If X is a
% matrix, the filtering is done on the columns of X.


Sign in to comment.



Community Treasure Hunt

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

Start Hunting!