Clean Wave File Impulse Noise with Matlab

In summary, the conversation is about a person trying to clean impulse noise from a wave file in Matlab. They are attempting to keep points below a certain trigger level and delete points above the trigger level in both channels. The provided code works, but it is slow, so they are looking for a faster solution. The suggestion is to use masking indices instead of a for loop. There is also a request for help in writing vectorized code to set the signal value in both channels to zero if it exceeds the limits.
  • #1
JohnSimpson
92
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 algorithim (I've had some ideas, but havn't bothered to code any of them)

Thanks!
 
Physics news on Phys.org
  • #2
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.
 
  • #3
thank you! SOOO much faster now.
 
  • #4
marcusl, i sent you a msg, get back to me when you can, thanks ^_^
 
  • #5
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
 
  • #6
This will do it:

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

Related to Clean Wave File Impulse Noise with Matlab

1. How can I use Matlab to clean wave file impulse noise?

To clean wave file impulse noise with Matlab, you can use the medfilt1 function to apply a median filter to the signal. This filter removes outliers and reduces the effect of impulse noise on the signal. You can also use the findpeaks function to identify and remove any spikes in the signal that may be caused by impulse noise.

2. What is the impact of impulse noise on a wave file?

Impulse noise, also known as spike noise, can cause sudden and extreme changes in a wave file signal. This can result in distorted or inaccurate data, making it difficult to analyze and interpret. In some cases, impulse noise can even corrupt the entire wave file.

3. How do I know if my wave file has impulse noise?

You can use the plot function in Matlab to visualize the wave file and look for any sudden spikes or outliers in the data. Alternatively, you can use the std function to calculate the standard deviation of the signal and see if it is significantly higher than expected. A high standard deviation can be an indication of impulse noise in the wave file.

4. Can I remove impulse noise without losing data?

While removing impulse noise can improve the overall quality of a wave file, it is important to note that this process can also result in some loss of data. The median filter, for example, may smooth out some of the signal's details. However, using the appropriate filter parameters and techniques can help minimize data loss while still effectively removing impulse noise.

5. Are there other methods besides using Matlab to clean wave file impulse noise?

Yes, there are various software tools and programming languages that can be used to clean wave file impulse noise, such as Python, R, and Adobe Audition. Some audio editing software also have built-in noise reduction features that can help remove impulse noise from wave files. However, Matlab is a popular choice among scientists and engineers due to its powerful signal processing capabilities and user-friendly interface.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
774
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top