Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Basic Audio Signal Processing in Octave: Mathematical Operations and Frequency Analysis

Tech 1

Two signals, S1(t) and S2(t), can be combined through addition to produce a resultant signal R(t), where the value at any point in time is the sum of the individual signal values at that instant:

R(t) = S1(t) + S2(t)

This operation can be implemented and visualized using GNU Octave. To demonstrate, two sinusoidal signals with different frequencies are generated and then summed.

Generating Sinusoidal Signals at 440 Hz and 880 Hz

First, create two audio files containing cosine waves at 440 Hz and 880 Hz respectively:

sig1 = 'cos440.ogg';
sig2 = 'cos880.ogg';
fs = 44100;                    % Sampling frequency in Hz
t = 0:1/fs:0.02;               % Time vector for 20 milliseconds
w1 = 2 * pi * 440 * t;         % Angular frequency for 440 Hz
w2 = 2 * pi * 880 * t;         % Angular frequency for 880 Hz

audiowrite(sig1, cos(w1), fs);
audiowrite(sig2, cos(w2), fs);

Visualizing the Individual Signals

After generating the audio files, read and plot the waveforms to observe their characteristics.

Plotting the 440 Hz signal:

[y1, fs] = audioread(sig1);
plot(y1);
xlabel('Sample Index');
ylabel('Amplitude');
title('Cosine Wave at 440 Hz');

Similarly, for the 880 Hz signal:

[y2, fs] = audioread(sig2);
plot(y2);
xlabel('Sample Index');
ylabel('Amplitude');
title('Cosine Wave at 880 Hz');

The higher frequency of 880 Hz will exhibit twice the number of oscillations within the same time window compared to the 440 Hz signal.

Combining Signals Through Addition

To analyze the effeect of superposition, load both signals and compute their sum:

[y1, fs] = audioread(sig1);
[y2, fs] = audioread(sig2);

% Ensure both signals have the same length
min_len = min(length(y1), length(y2));
y1 = y1(1:min_len);
y2 = y2(1:min_len);

resultant = y1 + y2;

plot(resultant);
xlabel('Sample Index');
ylabel('Amplitude');
title('Sum of 440 Hz and 880 Hz Cosine Waves');

The resulting waveform displays constructive and destructive interference patterns due to the phase relationships between the two frequencies.

Scaling Signals (Amplitude Multiplication)

Another fundamental operation is scaling a signal by a constant factor. For instance, amplifying a signal by a factor of 1.5:

scaled_signal = 1.5 * y1;
audiowrite('amplified_cos440.ogg', scaled_signal, fs);

Care must be taken to avoid clipping, which occurs when the amplitude exceeds the valid range [-1, 1] for audio output.

Applying Nonlinear Transformations

Element-wise mathematical functions such as sin, exp, or abs can also be applied to modify the signal shape. For example, taking the absolute value doubles the perceived frequency:

rectified = abs(y1);
plot(rectified);
xlabel('Sample Index');
ylabel('Amplitude');
title('Full-Wave Rectified 440 Hz Signal');

This transforms the cosine wave into a series of unidirectional pulses, effectively doubling its frequency content.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.