Clean Wave File Impulse Noise with Matlab

  • Context: MATLAB 
  • Thread starter Thread starter JohnSimpson
  • Start date Start date
  • Tags Tags
    cleaning Matlab Noise
Click For Summary

Discussion Overview

The discussion focuses on methods to clean impulse noise from a two-channel wave file using MATLAB. Participants explore techniques for improving the efficiency of the code used to filter out noise based on specified trigger levels.

Discussion Character

  • Technical explanation
  • Mathematical reasoning

Main Points Raised

  • One participant shares a for loop approach to remove points above trigger levels from both channels but notes that it is very slow.
  • Another participant suggests using masking to create a new array with the filtered results, proposing a vectorized solution that improves speed.
  • A later reply confirms the vectorized approach significantly increases performance.
  • Another participant asks how to modify the code to set values above the trigger levels to zero instead of removing them.
  • A subsequent response provides a vectorized solution for setting values to zero based on the trigger levels.

Areas of Agreement / Disagreement

Participants generally agree on the effectiveness of vectorization for improving performance, with multiple approaches discussed for handling impulse noise, but no consensus on a single best method.

Contextual Notes

Some limitations may include the specific definitions of "impulse noise" and "trigger levels," as well as the potential impact of the chosen method on the overall signal integrity.

Who May Find This Useful

Individuals interested in signal processing, particularly those working with MATLAB for audio or wave file analysis, may find the techniques discussed beneficial.

JohnSimpson
Messages
89
Reaction score
0
I'm attempting to clean impulse noise from a wave file in matlab. the file is two channels, about 7 million points in each channel. What I wish to do is keep points, that are below my trigger levels, and delete points (in both channels simultaneously) that are above the trigger levels for either channel. Code is below

for x = 1:1:lnth
if abs(sig(i,1)) > level1 || abs(sig(i,2)) > level2
sig(i,:) = [];
else
i=i+1;
end
end

The code works and does what I want it to. The problem is that its very, very slow. Is there a way I can vectorize the code to make it faster? Or does anyone have any suggestions for a smarter algorithm (I've had some ideas, but havn't bothered to code any of them)

Thanks!
 
Physics news on Phys.org
Try masking the indices instead. If you wanted to copy the massaged results into a new array, for instance, do this:

newsig = sig(abs(sig(:,1)) <= level1 & abs(sig(:,2)) <= level2,:)

Should be faster than your for loop.
 
thank you! SOOO much faster now.
 
marcusl, i sent you a msg, get back to me when you can, thanks ^_^
 
I'll post it here if someone else could help instead

How would I write vectorized code to have the signal value in both channels be set to zero if it exceeds the limits like before, instead of "removing" the values that were above the trigger values
 
This will do it:

sig(abs(sig(:,1)) > level1 | abs(sig(:,2)) > level2,:) = 0;
 
thanks a lot, i think I'm starting to catch on.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K