SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Unit 3 phase controlled converters
Unit 3 phase controlled convertersUnit 3 phase controlled converters
Unit 3 phase controlled convertersEr.Meraj Akhtar
 
Switch mode power supply
Switch mode power supplySwitch mode power supply
Switch mode power supplyAnish Das
 
Ch18 "Case Study 3: DC-DC Power Converter"
Ch18 "Case Study 3: DC-DC Power Converter"Ch18 "Case Study 3: DC-DC Power Converter"
Ch18 "Case Study 3: DC-DC Power Converter"Aya Mahmoud
 
Chapter 4 time domain analysis
Chapter 4 time domain analysisChapter 4 time domain analysis
Chapter 4 time domain analysisBin Biny Bino
 
Lab 7 Report Voltage Comparators and Schmitt Triggers
Lab 7 Report Voltage Comparators and Schmitt TriggersLab 7 Report Voltage Comparators and Schmitt Triggers
Lab 7 Report Voltage Comparators and Schmitt TriggersKatrina Little
 
Lecture note macine & drives (power electronic converter)
Lecture note macine & drives (power electronic converter)Lecture note macine & drives (power electronic converter)
Lecture note macine & drives (power electronic converter)Faiz Mansur
 
Operational Amplifiers And Logic Gates
Operational Amplifiers And Logic GatesOperational Amplifiers And Logic Gates
Operational Amplifiers And Logic Gatesdheva B
 
Introduction to embedded systems
Introduction to embedded systemsIntroduction to embedded systems
Introduction to embedded systemsApurva Zope
 
Plc scada details and comparison
Plc scada details and comparisonPlc scada details and comparison
Plc scada details and comparisontamannataneja
 
Mathematical Modelling of Control Systems
Mathematical Modelling of Control SystemsMathematical Modelling of Control Systems
Mathematical Modelling of Control SystemsDivyanshu Rai
 
Classical and Modern Control Theory
Classical and Modern Control TheoryClassical and Modern Control Theory
Classical and Modern Control TheoryQazi Ejaz
 
ANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORAnil Yadav
 
"Black Box for a Car" report
"Black Box for a Car" report"Black Box for a Car" report
"Black Box for a Car" reportsubrat manna
 
Microcontroller based Electronic Eye Controlled security System
Microcontroller based Electronic Eye Controlled security SystemMicrocontroller based Electronic Eye Controlled security System
Microcontroller based Electronic Eye Controlled security SystemEdgefxkits & Solutions
 
Speed Control of DC Motor using Microcontroller
Speed Control of DC Motor using MicrocontrollerSpeed Control of DC Motor using Microcontroller
Speed Control of DC Motor using MicrocontrollerSudip Mondal
 
Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200Ahmed Elsayed
 
block diagram reduction solved problems
block diagram reduction solved problemsblock diagram reduction solved problems
block diagram reduction solved problemsAmeya Nijasure
 

Was ist angesagt? (20)

Unit 3 phase controlled converters
Unit 3 phase controlled convertersUnit 3 phase controlled converters
Unit 3 phase controlled converters
 
AC AC converters
AC AC convertersAC AC converters
AC AC converters
 
Boost converter
Boost converterBoost converter
Boost converter
 
Switch mode power supply
Switch mode power supplySwitch mode power supply
Switch mode power supply
 
Ch18 "Case Study 3: DC-DC Power Converter"
Ch18 "Case Study 3: DC-DC Power Converter"Ch18 "Case Study 3: DC-DC Power Converter"
Ch18 "Case Study 3: DC-DC Power Converter"
 
Chapter 4 time domain analysis
Chapter 4 time domain analysisChapter 4 time domain analysis
Chapter 4 time domain analysis
 
Lab 7 Report Voltage Comparators and Schmitt Triggers
Lab 7 Report Voltage Comparators and Schmitt TriggersLab 7 Report Voltage Comparators and Schmitt Triggers
Lab 7 Report Voltage Comparators and Schmitt Triggers
 
Lecture note macine & drives (power electronic converter)
Lecture note macine & drives (power electronic converter)Lecture note macine & drives (power electronic converter)
Lecture note macine & drives (power electronic converter)
 
Operational Amplifiers And Logic Gates
Operational Amplifiers And Logic GatesOperational Amplifiers And Logic Gates
Operational Amplifiers And Logic Gates
 
Introduction to embedded systems
Introduction to embedded systemsIntroduction to embedded systems
Introduction to embedded systems
 
Plc scada details and comparison
Plc scada details and comparisonPlc scada details and comparison
Plc scada details and comparison
 
Mathematical Modelling of Control Systems
Mathematical Modelling of Control SystemsMathematical Modelling of Control Systems
Mathematical Modelling of Control Systems
 
Classical and Modern Control Theory
Classical and Modern Control TheoryClassical and Modern Control Theory
Classical and Modern Control Theory
 
ANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTORANALOG TO DIGITAL CONVERTOR
ANALOG TO DIGITAL CONVERTOR
 
"Black Box for a Car" report
"Black Box for a Car" report"Black Box for a Car" report
"Black Box for a Car" report
 
Microcontroller based Electronic Eye Controlled security System
Microcontroller based Electronic Eye Controlled security SystemMicrocontroller based Electronic Eye Controlled security System
Microcontroller based Electronic Eye Controlled security System
 
Speed Control of DC Motor using Microcontroller
Speed Control of DC Motor using MicrocontrollerSpeed Control of DC Motor using Microcontroller
Speed Control of DC Motor using Microcontroller
 
Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200Programmable logic controller - Siemens S7-1200
Programmable logic controller - Siemens S7-1200
 
block diagram reduction solved problems
block diagram reduction solved problemsblock diagram reduction solved problems
block diagram reduction solved problems
 
ADC and DAC Best Ever Pers
ADC and DAC Best Ever PersADC and DAC Best Ever Pers
ADC and DAC Best Ever Pers
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
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
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
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.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
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
 

Kürzlich hochgeladen (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
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...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
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 ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
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
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
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
 

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