SlideShare une entreprise Scribd logo
1  sur  17
Moving Average in C
C Program for a Moving Average Filter
Colin McAllister, 24/7/2017
Moving Average in C
 A simple C program to transform input data to
output data. (Time-series data)
 Purpose: Demonstration of C programming.
 Audience: Aspiring C or C++ Developers.
 Model: A simple signal processing example.
 Features: data types, control flow, floating point
numbers, program input and output.
Block Diagram of Filter
Data Types
 0,1 – Boolean constants (False,True)
 int – Signed integer
 unsigned int – Unsigned integer
 double – Floating point (real) number
 double x[t], y[t] – Arrays of data
C Language Features
 main() function
 Program input - scanf()
 Program output - printf()
 Control flow – A simple “while(True)“ loop
 Blocks of code – Bound by “{“ and “}“
 Data types – assignment (equals sign “=“)
 Floating point numbers – Average value
Integrated Development Environment
Hello World Template
First Draft of Program
Input and Output of Floating Point
Program Statements
puts("Moving Average"); /* output */
puts("Enter sample"); /* output */
scanf("%lf", &value_in); /* input */
printf("Input value %fn", value_in);
Terminal Window:
$ ./MovingAvg
Moving Average
Enter sample
12.34
Input value 12.340000
Calculate Average of Three Numbers
#define SAMPLES 3
double x[SAMPLES];
double value_in, avg;
int i;
int main(void) {
puts("Moving Average"); /* output */
printf("Enter %d samples:n", SAMPLES); /* output */
for(i=0; i<SAMPLES; i++)
{ scanf("%lf", &value_in); /* input */
x[2]=x[1];
x[1]=x[0];
x[0]=value_in;
avg = (x[0]+x[1]+x[2])/3.0;
printf("Average %fn", avg);
}
Calculate Average – Terminal Window
 $ ./MovingAvg
 Moving Average
 Enter 3 samples:
 1.0
 Average 0.333333
 2.0
 Average 1.000000
 4.0
 Average 2.333333
Shift Data and Calculate Average
Shift Data and Calculate Average (Detail)
Shift and Calculate – Terminal Window
 $ ./MovingAvg
 Moving Average, Window Size 3
 Enter many samples:
 2.0
 x 0.000000, y 0.666667
 2.0
 x 2.000000, y 1.333333
 2.0
 x 2.000000, y 2.000000
 0.0
 x 2.000000, y 1.333333
 0.0
 x 0.000000, y 0.666667
 0.0
 x 0.000000, y 0.000000
Your Questions or Comments?
Clip art from www.123rf.com
Coding Considerations
 Develop in your favourite IDE
 Fix compiler errors and warnings
 Use Debugger to step through code
 Make code modular – Use functions
 Port program from C to C++
 Use OOP features of C++
 Use modern containers and iterators
 Try different compilers or even languages
Application Considerations
 Applications: Read about FIR Filters
 Optimisation: Avoid shifting the data
 Optimisation: Replace double with int
 Generate test data using Trig functions
 Generate noisy test data using rand()
 Use filter to improve Signal/Noise ratio
 Frequency response of Low pass filter
 Plot graphs to visualise Filter operation

Contenu connexe

Tendances

Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051hello_priti
 
Arduino and c programming
Arduino and c programmingArduino and c programming
Arduino and c programmingPunit Goswami
 
Generate pwm signal through arduino of various duty
Generate pwm signal through arduino of various dutyGenerate pwm signal through arduino of various duty
Generate pwm signal through arduino of various dutyPANKAJPRAJAPATI45
 
Arm organization and implementation
Arm organization and implementationArm organization and implementation
Arm organization and implementationShubham Singh
 
Arm7 Interfacing examples
Arm7   Interfacing examples Arm7   Interfacing examples
Arm7 Interfacing examples Dr.YNM
 
Instruction set of 8085
Instruction set  of 8085Instruction set  of 8085
Instruction set of 8085shiji v r
 
Finite state machines
Finite state machinesFinite state machines
Finite state machinesdennis gookyi
 
Voltage Mode Control of Buck Converter
Voltage Mode Control of Buck ConverterVoltage Mode Control of Buck Converter
Voltage Mode Control of Buck ConverterManish Kumar
 
Unit-I Basic Embedded System Notes
Unit-I Basic Embedded System NotesUnit-I Basic Embedded System Notes
Unit-I Basic Embedded System NotesDr. Pankaj Zope
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Irfan Anjum
 
Plc analog Tutorial
Plc analog TutorialPlc analog Tutorial
Plc analog TutorialElectro 8
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts NishmaNJ
 
Integrator OP Amp
Integrator OP AmpIntegrator OP Amp
Integrator OP AmpDr.Raja R
 
Arm programmer's model
Arm programmer's modelArm programmer's model
Arm programmer's modelv Kalairajan
 
8051 assembly programming
8051 assembly programming8051 assembly programming
8051 assembly programmingsergeiseq
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller Raghav Shetty
 

Tendances (20)

Architecture of 8051
Architecture of 8051Architecture of 8051
Architecture of 8051
 
Introduction to Embedded Systems a Practical Approach
Introduction to Embedded Systems a Practical ApproachIntroduction to Embedded Systems a Practical Approach
Introduction to Embedded Systems a Practical Approach
 
L298 Motor Driver
L298 Motor DriverL298 Motor Driver
L298 Motor Driver
 
Arduino and c programming
Arduino and c programmingArduino and c programming
Arduino and c programming
 
Generate pwm signal through arduino of various duty
Generate pwm signal through arduino of various dutyGenerate pwm signal through arduino of various duty
Generate pwm signal through arduino of various duty
 
Arm organization and implementation
Arm organization and implementationArm organization and implementation
Arm organization and implementation
 
ANALOG AND DIGITAL ELECTRONICS unit 5
ANALOG AND DIGITAL ELECTRONICS unit 5ANALOG AND DIGITAL ELECTRONICS unit 5
ANALOG AND DIGITAL ELECTRONICS unit 5
 
Arm7 Interfacing examples
Arm7   Interfacing examples Arm7   Interfacing examples
Arm7 Interfacing examples
 
Instruction set of 8085
Instruction set  of 8085Instruction set  of 8085
Instruction set of 8085
 
Finite state machines
Finite state machinesFinite state machines
Finite state machines
 
Timer 2 concept
Timer 2 conceptTimer 2 concept
Timer 2 concept
 
Voltage Mode Control of Buck Converter
Voltage Mode Control of Buck ConverterVoltage Mode Control of Buck Converter
Voltage Mode Control of Buck Converter
 
Unit-I Basic Embedded System Notes
Unit-I Basic Embedded System NotesUnit-I Basic Embedded System Notes
Unit-I Basic Embedded System Notes
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)
 
Plc analog Tutorial
Plc analog TutorialPlc analog Tutorial
Plc analog Tutorial
 
ARM Exception and interrupts
ARM Exception and interrupts ARM Exception and interrupts
ARM Exception and interrupts
 
Integrator OP Amp
Integrator OP AmpIntegrator OP Amp
Integrator OP Amp
 
Arm programmer's model
Arm programmer's modelArm programmer's model
Arm programmer's model
 
8051 assembly programming
8051 assembly programming8051 assembly programming
8051 assembly programming
 
Programming with PIC microcontroller
Programming with PIC microcontroller Programming with PIC microcontroller
Programming with PIC microcontroller
 

Similaire à Moving Average Filter in C

2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2Don Dooley
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
Operators in c language
Operators in c languageOperators in c language
Operators in c languageAmit Singh
 
CSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxCSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxTasnimSaimaRaita
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxKrishanPalSingh39
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04hassaanciit
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c programNishmaNJ
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariTHE NORTHCAP UNIVERSITY
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxAnkitaVerma776806
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures Pradipta Mishra
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Hazwan Arif
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structuresPradipta Mishra
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 

Similaire à Moving Average Filter in C (20)

2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
 
CSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptxCSE 103 Project Presentation.pptx
CSE 103 Project Presentation.pptx
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
1 introduction to c program
1 introduction to c program1 introduction to c program
1 introduction to c program
 
Fundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan KumariFundamentals of computer programming by Dr. A. Charan Kumari
Fundamentals of computer programming by Dr. A. Charan Kumari
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
 
Mcs 011 solved assignment 2015-16
Mcs 011 solved assignment 2015-16Mcs 011 solved assignment 2015-16
Mcs 011 solved assignment 2015-16
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
Intro to c chapter cover 1 4
Intro to c chapter cover 1 4Intro to c chapter cover 1 4
Intro to c chapter cover 1 4
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 

Plus de Colin

Circles in Triangles using Geometric Construction
Circles in Triangles using Geometric ConstructionCircles in Triangles using Geometric Construction
Circles in Triangles using Geometric ConstructionColin
 
Inscribe Circles in Triangles using Geometric Construction
Inscribe Circles in Triangles using Geometric ConstructionInscribe Circles in Triangles using Geometric Construction
Inscribe Circles in Triangles using Geometric ConstructionColin
 
Inscribe Semicircle In Square by Geometric Construction
Inscribe Semicircle In Square by Geometric ConstructionInscribe Semicircle In Square by Geometric Construction
Inscribe Semicircle In Square by Geometric ConstructionColin
 
Openness And Social Networking (odp)
Openness And Social Networking (odp)Openness And Social Networking (odp)
Openness And Social Networking (odp)Colin
 
Openness And Social Networking (PDF)
Openness And Social Networking (PDF)Openness And Social Networking (PDF)
Openness And Social Networking (PDF)Colin
 
Openness And Social Networking
Openness And Social NetworkingOpenness And Social Networking
Openness And Social NetworkingColin
 
The Cool Physics of Heat
The Cool Physics of HeatThe Cool Physics of Heat
The Cool Physics of HeatColin
 
The Cool Physics Of Heat
The Cool Physics Of HeatThe Cool Physics Of Heat
The Cool Physics Of HeatColin
 

Plus de Colin (8)

Circles in Triangles using Geometric Construction
Circles in Triangles using Geometric ConstructionCircles in Triangles using Geometric Construction
Circles in Triangles using Geometric Construction
 
Inscribe Circles in Triangles using Geometric Construction
Inscribe Circles in Triangles using Geometric ConstructionInscribe Circles in Triangles using Geometric Construction
Inscribe Circles in Triangles using Geometric Construction
 
Inscribe Semicircle In Square by Geometric Construction
Inscribe Semicircle In Square by Geometric ConstructionInscribe Semicircle In Square by Geometric Construction
Inscribe Semicircle In Square by Geometric Construction
 
Openness And Social Networking (odp)
Openness And Social Networking (odp)Openness And Social Networking (odp)
Openness And Social Networking (odp)
 
Openness And Social Networking (PDF)
Openness And Social Networking (PDF)Openness And Social Networking (PDF)
Openness And Social Networking (PDF)
 
Openness And Social Networking
Openness And Social NetworkingOpenness And Social Networking
Openness And Social Networking
 
The Cool Physics of Heat
The Cool Physics of HeatThe Cool Physics of Heat
The Cool Physics of Heat
 
The Cool Physics Of Heat
The Cool Physics Of HeatThe Cool Physics Of Heat
The Cool Physics Of Heat
 

Dernier

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 

Dernier (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 

Moving Average Filter in C

  • 1. Moving Average in C C Program for a Moving Average Filter Colin McAllister, 24/7/2017
  • 2. Moving Average in C  A simple C program to transform input data to output data. (Time-series data)  Purpose: Demonstration of C programming.  Audience: Aspiring C or C++ Developers.  Model: A simple signal processing example.  Features: data types, control flow, floating point numbers, program input and output.
  • 4. Data Types  0,1 – Boolean constants (False,True)  int – Signed integer  unsigned int – Unsigned integer  double – Floating point (real) number  double x[t], y[t] – Arrays of data
  • 5. C Language Features  main() function  Program input - scanf()  Program output - printf()  Control flow – A simple “while(True)“ loop  Blocks of code – Bound by “{“ and “}“  Data types – assignment (equals sign “=“)  Floating point numbers – Average value
  • 8. First Draft of Program
  • 9. Input and Output of Floating Point Program Statements puts("Moving Average"); /* output */ puts("Enter sample"); /* output */ scanf("%lf", &value_in); /* input */ printf("Input value %fn", value_in); Terminal Window: $ ./MovingAvg Moving Average Enter sample 12.34 Input value 12.340000
  • 10. Calculate Average of Three Numbers #define SAMPLES 3 double x[SAMPLES]; double value_in, avg; int i; int main(void) { puts("Moving Average"); /* output */ printf("Enter %d samples:n", SAMPLES); /* output */ for(i=0; i<SAMPLES; i++) { scanf("%lf", &value_in); /* input */ x[2]=x[1]; x[1]=x[0]; x[0]=value_in; avg = (x[0]+x[1]+x[2])/3.0; printf("Average %fn", avg); }
  • 11. Calculate Average – Terminal Window  $ ./MovingAvg  Moving Average  Enter 3 samples:  1.0  Average 0.333333  2.0  Average 1.000000  4.0  Average 2.333333
  • 12. Shift Data and Calculate Average
  • 13. Shift Data and Calculate Average (Detail)
  • 14. Shift and Calculate – Terminal Window  $ ./MovingAvg  Moving Average, Window Size 3  Enter many samples:  2.0  x 0.000000, y 0.666667  2.0  x 2.000000, y 1.333333  2.0  x 2.000000, y 2.000000  0.0  x 2.000000, y 1.333333  0.0  x 0.000000, y 0.666667  0.0  x 0.000000, y 0.000000
  • 15. Your Questions or Comments? Clip art from www.123rf.com
  • 16. Coding Considerations  Develop in your favourite IDE  Fix compiler errors and warnings  Use Debugger to step through code  Make code modular – Use functions  Port program from C to C++  Use OOP features of C++  Use modern containers and iterators  Try different compilers or even languages
  • 17. Application Considerations  Applications: Read about FIR Filters  Optimisation: Avoid shifting the data  Optimisation: Replace double with int  Generate test data using Trig functions  Generate noisy test data using rand()  Use filter to improve Signal/Noise ratio  Frequency response of Low pass filter  Plot graphs to visualise Filter operation