1D Array Manipulation and Visualization through Signal and Audio Processing

Richard Blackmon, Elon University,

Author Profile

Summary

This MATLAB activity is designed for first-year engineering students, many of whom have little or no programming experience. It introduces the fundamentals of 1D arrays, indexing, and plotting while helping students connect code to real-world systems. Students generate and visualize sine waves to explore how mathematical functions represent oscillations found in sound, vibration, and alternating current. They also use logical indexing to find peaks in their data, giving them an opportunity to assess data for information such as heartbeats in ECG traces, steps in pedometers, or beats in music.

This activity comes after students have practiced creating variables and exploring variable classes, learning basic MATLAB operators and functions, and building their own functions. It gives them their first opportunity to apply those skills to a system they can observe and interpret. By plotting and listening to generated signals and short audio clips, students develop an intuitive sense of how numerical arrays can represent real-world data. This experience builds a foundation for future courses in biomedical instrumentation, vibration analysis, and signal processing.

The activity encourages discovery and curiosity while giving students a tangible connection to what they code. By hearing the results of their work, students recognize that programming is not only about writing correct syntax but also about modeling and understanding real-world behavior.

Keywords

MATLAB, Engineering Computing, Signal Processing, Signal Analysis, Audio Processing, Array Manipulation, Logical Indexing, Peak Detection, Amplitude Modulation, Data Plotting and Visualization, Problem-Solving Skills, Introductory Programming, Undergraduate Engineering Education, First-Year Engineering, Hands-On Activity

Share your modifications and improvements to this activity through the Community Contribution Tool »

Learning Goals

Conceptual

  • Understand how 1D arrays can represent real-world data, such as sound or motion.
  • Recognize how sine waves describe oscillatory behavior found in systems like audio signals, vibration, and alternating current.
  • Identify how peak detection relates to interpreting physical measurements such as heartbeats, steps, or beats in music.
  • Understand how sampling frequency and array length relate to physical time and signal duration.

Computational (MATLAB Skills)

  • Create and manipulate 1D arrays using array operations and logical indexing.
  • Generate and plot sine waves using MATLAB functions and format graphs with titles, labels, and subplots.
  • Apply array operations to observe how changes affect waveform behavior, including amplitude and frequency.
  • Import and process audio data to connect abstract array manipulation to real-world signals.
  • Perform amplitude modulation using a secondary waveform to explore the effect on sound.
  • Write and test user-defined functions to perform array manipulations and signal operations.

Context for Use

This activity is part of Engineering Computing with MATLAB, a first-year, 2SH course required for all engineering majors (Note: Courses at our institution are typically 4SH). This course uses a quasi-flipped model, where students do their initial learning by completing reading and assignments in the online MATLAB ZyBook (multiple versions are available to adopt). The ZyBook includes interactive demos, multiple choice questions, and coding activities within the book.

The assignment is designed for students who may have little or no prior programming experience, and may be taking this class in their first semester of their first year. The course uses a hands-on, problem-based format where most class time is spent coding individually or in small groups, with the instructor available for real-time guidance. Typical class sizes range from 12 to 24 students. The activity is typically completed by students in-class over 2-3 class periods toward the middle of the semester (may happen earlier and for fewer periods for full-credit courses). Students complete the activity individually but are encouraged to discuss their approach with peers as they troubleshoot and compare results. An introduction to sinusoids may be necessary.

Description and Teaching Materials

This activity introduces students to array-based computation and plotting through the creation and analysis of signals. Students first generate and visualize simple sine waves, learning how sampling frequency, signal frequency, and duration relate to the number of array elements and the resulting waveform. They use logical indexing to identify peaks in the signal, reinforcing their understanding of array operations and data relationships.

Students also practice using the plot function to format graphs, including adjusting line thickness, marker style, titles, and axis labels. These expectations help students develop precision and clarity in presenting computational results, a skill that carries through later problem sets and projects.

After working with simple sine waves, students apply these skills to a short audio clip. They import a song file and modify it through array manipulations that adjust speed, amplitude, and playback direction. In the final section, they use a low-frequency sine wave to modulate the song's volume, exploring how mathematical operations can alter a sound's behavior. Throughout the activity, students create labeled plots of their results to demonstrate comprehension.

Recommended point allocations are provided for each section to guide grading consistency. Students earn full credit for producing correct plots, functional code, and well-commented scripts, and they lose points for missing required components or incorrect implementation. The activity document includes clear formatting and submission instructions, while the provided solution script can be used by instructors for demonstration or grading reference. Instructors may choose to provide a shared audio file for consistency across submissions, but it may be more engaging for students to allow them to use an audio file of their choosing.

Problem Set - Plotting and Audio.docx (Microsoft Word 2007 (.docx) 19kB Nov5 25)

829934__attiaphonatics__music-beats-10.mp3 (MP3 Audio 416kB Nov5 25)

Teaching Notes and Tips

Students who are new to MATLAB often struggle early with syntax errors, mismatched array sizes, and unfamiliar error messages. Real-time feedback is helpful, so walking through a short example at the start of class, such as generating and plotting a sine wave, helps prevent repeated troubleshooting later.

Students may also need explicit instruction on sinusoids and sampling frequency before beginning the assignment, since these concepts are new to many first-year students. The MATLAB zyBook used in the course includes instruction on both audio processing and sine waves, which can be referenced to reinforce these ideas.

Encourage students to use MATLAB's workspace and variable inspector to verify array lengths and the relationship between time and frequency. This visual confirmation often helps them understand how sampling frequency and duration control the appearance of the plot.

When students begin working with the audio portion, verify that they define both the sampling frequency and number of samples correctly. They may need to adjust the starting point of their clipped array to align with where the song begins. Small indexing mistakes can cause misalignment or truncated playback.

It is recommended that students select their own audio file for this assignment. Many have commented that using one of their favorite songs made the activity more enjoyable and increased their engagement.


Assessment

The tasks in the problem set are targeted and specific with clearly defined expected outcomes. Students are assessed on whether they meet the requirements for each task, including correct code execution and properly formatted plots. Partial credit is awarded when students demonstrate conceptual understanding in code comments or explanations, even if the code does not run successfully. Students are not awarded credit for using conditional statements or loops, as the goal is to strengthen their understanding of array-based operations rather than control flow.

In addition to code accuracy, students' written reflections are used to assess their ability to connect programming skills to real-world engineering applications and to explain how their computational work represents physical systems.

References and Resources

Zybook: Introduction to MATLAB with zyLabs from learn.zybooks.com