A Python implementation of a pedometer that processes accelerometer data to count steps, similar to how fitness trackers and smartphones work. This project demonstrates real-world signal processing techniques to extract meaningful information from noisy sensor data.
This application takes raw accelerometer data (x,y,z motion readings from phone sensors) and uses signal processing algorithms to detect walking patterns and count steps. It essentially replicates what your phone's built-in step counter does - identifying the characteristic up-and-down bounce of human walking to count each footstep.
- Dual Format Support: Accepts both combined (total acceleration) and separated (user + gravity) data formats
- Signal Processing Pipeline: Filters noise and isolates step patterns using IIR filters
- Smart Step Detection: Uses threshold crossing with hysteresis to avoid counting false steps
- Web Interface: User-friendly upload and analysis interface
- Metrics Calculation: Computes distance traveled, walking time, and accuracy
- Visualization: Generates plots showing the signal processing stages
- Modular Design: Clean, maintainable code structure for easy customization
- Python 3.7+
- pip (Python package manager)
- Clone the repository
git clone https://github.com/yourusername/pedometer.git
cd pedometer- Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Run the application
python app.py- Open your browser
Navigate to
http://localhost:5000
Total acceleration in x,y,z directions:
x1,y1,z1;x2,y2,z2;x3,y3,z3;...
Example:
0.1,-0.98,0.02;0.12,-0.95,0.03;0.11,-0.99,0.01;...
User acceleration and gravitational acceleration separated:
xu1,yu1,zu1|xg1,yg1,zg1;xu2,yu2,zu2|xg2,yg2,zg2;...
pedometer_project/
├── app.py # Flask web application
├── config.py # Configuration settings
├── requirements.txt # Python dependencies
├── core/ # Signal processing algorithms
│ ├── filters.py # IIR filter implementations
│ ├── parser.py # Data format parser
│ ├── processor.py # Signal processor
│ ├── analyzer.py # Step counter
│ └── pipeline.py # Processing pipeline
├── models/ # Data models
│ ├── user.py # User information
│ └── trial.py # Trial metadata
├── utils/ # Utilities
│ ├── file_handler.py # File management
│ └── data_generator.py # Sample data generation
├── templates/ # HTML templates
├── static/ # CSS styles
├── uploads/ # Uploaded data files
└── example_data/ # Sample data
- Parse Data: Convert raw accelerometer data to standard format
- Separate Gravity: Use low-pass filter to extract gravitational component
- Isolate Movement: Calculate dot product to get movement in gravity direction
- Filter Noise: Apply filters to remove high-frequency noise and drift
- Count Steps: Detect peaks using threshold crossing with hysteresis
# 1. Separate gravity from user movement
gravitational_accel = low_pass_filter(total_accel, 0.2_Hz)
user_accel = total_accel - gravitational_accel
# 2. Get movement in gravity direction
bounce_signal = dot_product(user_accel, gravitational_accel)
# 3. Clean the signal
filtered = low_pass_filter(bounce_signal, 5_Hz) # Remove noise
filtered = high_pass_filter(filtered, 1_Hz) # Remove drift
# 4. Count threshold crossings
steps = count_peaks(filtered, threshold=0.09)The application automatically generates a 10-second walking sample:
example_data/walking_data.txt
python -c "from utils.data_generator import generate_example_data; print(generate_example_data())" > test.txt- Sample Rate: 100 Hz
- Duration: 10 seconds
- Expected Steps: ~20 steps (2 steps/second)
Edit config.py:
STEP_THRESHOLD = 0.09 # Increase for less sensitive detectionModify filter coefficients in config.py for different walking patterns or sampling rates.
The modular structure makes it easy to add:
- New filter types in
core/filters.py - Additional metrics in
core/analyzer.py - Different visualizations in
utils/data_generator.py
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This implementation is based on the article "A Pedometer in the Real World" from "500 Lines or Less". It demonstrates:
- Digital Signal Processing: IIR filters for frequency-based signal separation
- Linear Algebra: Dot product for directional movement extraction
- Algorithm Design: Hysteresis for robust peak detection
- Software Engineering: Modular design with separation of concerns
- "Invalid literal for int()": Leave optional fields empty instead of entering invalid values
- "Bad Input" error: Check data format - must be comma and semicolon separated
- No steps detected: Ensure data contains walking motion, not stationary readings
- Too many steps: Adjust
STEP_THRESHOLDinconfig.py
Run with debug output:
app.run(debug=True) # Already enabled by default- Original article: "A Pedometer in the Real World" by Dessy Daskalov
- The Architecture of Open Source Applications (AOSABOOK)
- Signal processing concepts from digital signal processing literature