SlideShare a Scribd company logo
%Matthew Mobley
%Filter arbitrary data contained in a .mat file
%Largely adapted from http://dadorran.wordpress.com 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
%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
Published with MATLAB® R2012b
Page 3 of 3Data_Filtering
5/22/2015file:///C:/Users/Owner/Documents/Experiment%20Design/html/Data_Filtering.html

More Related Content

Viewers also liked

Your Child Deserves Support
Your Child Deserves SupportYour Child Deserves Support
Your Child Deserves Support
Dunne Dunne LLP
 
Lamb & Lentil Broth
Lamb & Lentil BrothLamb & Lentil Broth
Lamb & Lentil Broth
Urbanrajah
 
Obrada teksta - 2. dio
Obrada teksta - 2. dioObrada teksta - 2. dio
Obrada teksta - 2. dio
Goran Igaly
 
Regulamento
RegulamentoRegulamento
Regulamento
escolapicua
 
Employing people with disabilities
Employing people with disabilitiesEmploying people with disabilities
Employing people with disabilities
Pinkoane Mojabeng
 
Darly 7f
Darly 7fDarly 7f
Predavanja 06 Konstruktori i destruktori
Predavanja 06  Konstruktori i destruktoriPredavanja 06  Konstruktori i destruktori
Predavanja 06 Konstruktori i destruktori
Goran Igaly
 
Register renaming technique
Register renaming techniqueRegister renaming technique
Register renaming technique
Jinto George
 
Tilaaja tuottaja-semnaari Maijaliisa Junnila
Tilaaja tuottaja-semnaari Maijaliisa JunnilaTilaaja tuottaja-semnaari Maijaliisa Junnila
Tilaaja tuottaja-semnaari Maijaliisa Junnila
TilTu-seminaari
 

Viewers also liked (10)

Resepi
ResepiResepi
Resepi
 
Your Child Deserves Support
Your Child Deserves SupportYour Child Deserves Support
Your Child Deserves Support
 
Lamb & Lentil Broth
Lamb & Lentil BrothLamb & Lentil Broth
Lamb & Lentil Broth
 
Obrada teksta - 2. dio
Obrada teksta - 2. dioObrada teksta - 2. dio
Obrada teksta - 2. dio
 
Regulamento
RegulamentoRegulamento
Regulamento
 
Employing people with disabilities
Employing people with disabilitiesEmploying people with disabilities
Employing people with disabilities
 
Darly 7f
Darly 7fDarly 7f
Darly 7f
 
Predavanja 06 Konstruktori i destruktori
Predavanja 06  Konstruktori i destruktoriPredavanja 06  Konstruktori i destruktori
Predavanja 06 Konstruktori i destruktori
 
Register renaming technique
Register renaming techniqueRegister renaming technique
Register renaming technique
 
Tilaaja tuottaja-semnaari Maijaliisa Junnila
Tilaaja tuottaja-semnaari Maijaliisa JunnilaTilaaja tuottaja-semnaari Maijaliisa Junnila
Tilaaja tuottaja-semnaari Maijaliisa Junnila
 

Similar to Filtering

Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig
Michael Peacock
 
Moodle Quick Forms
Moodle Quick FormsMoodle Quick Forms
Moodle Quick Forms
Jalpa Bhavsar
 
What's new in Django 1.2?
What's new in Django 1.2?What's new in Django 1.2?
What's new in Django 1.2?
Jacob Kaplan-Moss
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
Lean Teams Consultancy
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
Michelangelo van Dam
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
Michelangelo van Dam
 
CakePHP workshop
CakePHP workshopCakePHP workshop
CakePHP workshop
Walther Lalk
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
Mike Dirolf
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
chartjes
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
Michelangelo van Dam
 
Big Data Analytics using Mahout
Big Data Analytics using MahoutBig Data Analytics using Mahout
Big Data Analytics using Mahout
IMC Institute
 
Phactory
PhactoryPhactory
Phactory
chriskite
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
Michelangelo van Dam
 
Wc no
Wc noWc no
Api Design
Api DesignApi Design
Api Design
sartak
 
Library Project
Library ProjectLibrary Project
Library Project
Holly Sanders
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
Jason Lotito
 
Drupal 7 database api
Drupal 7 database api Drupal 7 database api
Drupal 7 database api
Andrii Podanenko
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
Pavel Novitsky
 

Similar to Filtering (20)

Powerful and flexible templates with Twig
Powerful and flexible templates with Twig Powerful and flexible templates with Twig
Powerful and flexible templates with Twig
 
Moodle Quick Forms
Moodle Quick FormsMoodle Quick Forms
Moodle Quick Forms
 
What's new in Django 1.2?
What's new in Django 1.2?What's new in Django 1.2?
What's new in Django 1.2?
 
Test driven development_for_php
Test driven development_for_phpTest driven development_for_php
Test driven development_for_php
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
CakePHP workshop
CakePHP workshopCakePHP workshop
CakePHP workshop
 
Python Development (MongoSF)
Python Development (MongoSF)Python Development (MongoSF)
Python Development (MongoSF)
 
Building Testable PHP Applications
Building Testable PHP ApplicationsBuilding Testable PHP Applications
Building Testable PHP Applications
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Big Data Analytics using Mahout
Big Data Analytics using MahoutBig Data Analytics using Mahout
Big Data Analytics using Mahout
 
Phactory
PhactoryPhactory
Phactory
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Wc no
Wc noWc no
Wc no
 
Api Design
Api DesignApi Design
Api Design
 
Library Project
Library ProjectLibrary Project
Library Project
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
 
Drupal 7 database api
Drupal 7 database api Drupal 7 database api
Drupal 7 database api
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
 

Filtering

  • 1. %Matthew Mobley %Filter arbitrary data contained in a .mat file %Largely adapted from http://dadorran.wordpress.com 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. %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. Published with MATLAB® R2012b Page 3 of 3Data_Filtering 5/22/2015file:///C:/Users/Owner/Documents/Experiment%20Design/html/Data_Filtering.html