Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

  • Be the first to comment

  • Be the first to like this


  1. 1. %Matthew Mobley %Filter arbitrary data contained in a .mat file %Largely adapted from search for filtering matlab demo clear all; %==============================DEFINITIONS================================% %load data [FileName,PathName] = uigetfile('*.mat','Select the .mat-file'); X = importdata(FileName); %define filter parameters (here a 4th order lowpass butterworth filter %centered at 0.05*pi rad/sample is the default) prompt = {'Enter Filter Order:','Enter Filter Frequency:', 'Select Filter Type'}; dlg_title = 'Filter Parameters'; num_lines = 1; def = {'4','0.05','low'}; answer = inputdlg(prompt,dlg_title,num_lines,def); FilterOrder = str2double(answer(1)); f0 = str2double(answer(2)); filtertype = char(answer(3)); [b a] = butter(FilterOrder, f0, filtertype); %=========================================================================% %============================FFT & FILTER PLOT============================% %take fft of data X_mags = abs(fft(X)); num_bins = length(X_mags); %normalize magnitudes normX_mags = X_mags./(max(X_mags)); %plot frequency spectrum plot([0:1/(num_bins/2 -1):1], normX_mags(1:num_bins/2)) xlabel('Normalized Frequency (pi rads/sample)') ylabel('Normalized Magnitude') %store filter response curve in H H = freqz(b,a, floor(num_bins/2)); %plot filter response curve hold on plot([0:1/(num_bins/2 -1):1], abs(H),'r'); legend('Normalized Frequency Data', 'Applied Filter Response'); %=========================================================================% %=======================COMPARATIVE TIME SERIES PLOT======================% figure(2); %filter temperature data Tfiltered = filter(b,a, X); Page 1 of 3Data_Filtering 5/22/2015file:///C:/Users/Owner/Documents/Experiment%20Design/html/Data_Filtering.html
  2. 2. %plot time series data subplot(2,1,1), plot(X), title('Unfiltered Data'), xlabel('Sample'), ylabel ('Absolute Magnitude'); subplot(2,1,2), plot(Tfiltered), title('Filtered Data'), xlabel('Sample'), ylabel ('Absolute Magnitude'); %=========================================================================% Page 2 of 3Data_Filtering 5/22/2015file:///C:/Users/Owner/Documents/Experiment%20Design/html/Data_Filtering.html
  3. 3. Published with MATLAB® R2012b Page 3 of 3Data_Filtering 5/22/2015file:///C:/Users/Owner/Documents/Experiment%20Design/html/Data_Filtering.html