Filtering high frequencies from response signal
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Joe Bennet
 el 20 de En. de 2021
  
    
    
    
    
    Comentada: Star Strider
      
      
 el 21 de En. de 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 :)
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;
0 comentarios
Respuesta aceptada
  Star Strider
      
      
 el 20 de En. de 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)
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 comentarios
  Star Strider
      
      
 el 21 de En. de 2021
				My pleasure!  
                           If my Answer helped you solve your problem, please Accept it!
.
Más respuestas (1)
  Mathieu NOE
      
 el 20 de En. de 2021
        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.
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


