Filtering high frequencies from response signal

조회 수: 7 (최근 30일)
Joe Bennet
Joe Bennet 2021년 1월 20일
댓글: Star Strider 2021년 1월 21일
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;
load('7004x4.mat')
t= g{:,1};
sm= g{:,3};
sm= rmmissing(sm);
t=rmmissing(t);
n=10;
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)';
plot(t,sm)
xlabel('Time Elapsed (s)')
ylabel('Strain')
title('Strain Signal')
fs= 6.2e-4;

채택된 답변

Star Strider
Star Strider 2021년 1월 20일
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)
figure
plot(Fv, abs(FTsm(Iv))*2)
grid
xlim([0 50])
title('Fourier Transform')
xlabel('Frequency (Hz)')
ylabel('Amplitude')
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
figure
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
figure
plot(t, sm)
hold on
plot(t, sm_filtered)
hold off
grid
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.
  댓글 수: 5
Joe Bennet
Joe Bennet 2021년 1월 21일
Thank you so much!
Star Strider
Star Strider 2021년 1월 21일
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mathieu NOE
Mathieu NOE 2021년 1월 20일
hello
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.

카테고리

Help CenterFile Exchange에서 Filter Analysis에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by