Agni
Agni

Reputation: 135

Band pass implementation matlab

I've 2 raw signals X and Y measuring vibrations of a rotating shaft at const. speed 633.33 Hz. My goal is to extract only specific frequency component (say 1X or .35X)and plot orbits (X signal plotted against Y signal) for them. I took the raw signal and I applied the low pass filter using Butterworth filter. it gave me smooth signal in the time domain. Now when I'm trying to apply the butterworth band pass filter between frequencies (630 Hz to 640 Hz) its not working properly. I don't know if I'm doing it right. The following picture is after the application of low pass filter ( butterworth).

enter image description here

This is another after I applied butterworth low pass and band pass filters. There is complete change in the original signal.

enter image description here I'm expecting the filter to do something like this a cleaner orbit for 1X frequency component.

enter image description here

My MATLAB code is as follows.

  L = length(X); % length of signal
  fs= 2e6; % sampling frequency
  df = fs/L; % Frequency window
  dt = 1/df; % time window
  %calculate time axis
  T = (0:dt:(L-1)*dt)';
  subplot(3,2,1);
  plot(T,X);
  title('before filtering X signal')
  subplot (3,2,2);
  plot(T,Y);
  title('before filtering Y signal')
  subplot(3,2,5);
  plot(X,Y);
  title('Orbits before filtering')
  X = detrend(X,0); % Removing DC Offset
  Y = detrend(Y,0); % Removing DC Offset

  % Butterworth low pass filter to remove high frequency components
  [b2,a2] = butter(6,5*633/(fs/2),'low');
  dataInX = X; 
  X = filter(b2,a2,dataInX); %filter command filters 
  dataInY = Y;
  Y = filter(b2,a2,dataInY);

  % butter worth band pass to only plot for 1X frequency component
  [b1,a1] = butter(1,[633/(fs/2) 640/(fs/2)],'bandpass');
  dataInX = X; 
  X = filter(b1,a1,dataInX); %filter command filters 
  dataInY = Y;
  Y = filter(b1,a1,dataInY);

  subplot(3, 2 ,3);
  plot(T,X);
  axis tight
  title('X signal after filtering')
  subplot(3,2,4);
  plot(T,Y);
  axis tight
  title('Y signal after filtering')
  subplot(3,2,6);
  plot(X,Y);
  title('Orbit after filtering')
  axis tight

I'm also attaching my data file for reference.

I'm new into the world of filters and DSP. Could someone help to fix this one with suggestions or hints or ideas.

Upvotes: 4

Views: 3476

Answers (1)

Felix Darvas
Felix Darvas

Reputation: 507

After lowpassing the signal ( i.e. [b2,a2] = butter(6,5*633/(fs/2),'low');) you can down sample from 2 MHz to ~ 4 kHZ and wont see much change in the result. Downsampling in this case will not change any resolution that the filter not already has reduced.

You could e. use resample(x,1,500) to downsample your 2 MHz signal to 4 kHz AFTER applying the lowpass. Then you should have no trouble with your narrow bandpass. Make sure to pass the new samplingrate onto the filter.

Also, if you have the full signal available, use filtfilt instead of filt to avoid phase distortion. In this case, you can lower the filter order a bit, but 4th order for the lowpass and the bandpass (after resampling) should just work fine.

Upvotes: 1

Related Questions