Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Removing peaks from raw data
Replies: 3   Last Post: Sep 24, 2012 5:10 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Greg Heath

Posts: 214
Registered: 12/13/04
Re: Removing peaks from raw data
Posted: Sep 24, 2012 5:10 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Sep 19, 7:50 am, "Chridert " <chrisvdpl...@upcmail.nl> wrote:
> I am currently working on a script that removes the noise (peaks) from a set of raw data, so say you have a matrix:
>
> 1  2  3
> 4 15 6
> 7  8  9
>
> The script will detect a peak at [2,2] (which is 15) and will replace it with a value which is the mean of the surrounding values (2,6,4 and 8)
>
> The script looks like this:
>
> for i=1:360
> for j=1:180
>     %% Correct corners
>     if i<2 && j<2
>            if data_5(i,j)>mean([data_5(i+1,j) data_5(i,j+1)])+(0.05*mean([data_5(i+1,j) data_5(i,j+1)]))
>            data_5(i,j)=mean([data_5(i+1,j) data_5(i,j+1)]);
>            end
>            if data_5(i,j)<mean([data_5(i+1,j) data_5(i,j+1)])-(0.05*mean([data_5(i+1,j) data_5(i,j+1)]))
>            data_5(i,j)=mean([data_5(i+1,j) data_5(i,j+1)]);
>            end
>     end
>
>     if i<2 && j>179
>            if data_5(i,j)>mean([data_5(i+1,j) data_5(i,j-1)])+(0.05*mean([data_5(i+1,j) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i+1,j) data_5(i,j-1)]);
>            end
>            if data_5(i,j)<mean([data_5(i+1,j) data_5(i,j-1)])-(0.05*mean([data_5(i+1,j) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i+1,j) data_5(i,j-1)]);
>            end
>     end
>
>     if i>359 && j<2
>            if data_5(i,j)>mean([data_5(i-1,j) data_5(i,j+1)])+(0.05*mean([data_5(i-1,j) data_5(i,j+1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i,j+1)]);
>            end
>            if data_5(i,j)<mean([data_5(i-1,j) data_5(i,j+1)])-(0.05*mean([data_5(i-1,j) data_5(i,j+1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i,j+1)]);
>            end
>     end
>
>     if i>359 && j>179
>            if data_5(i,j)>mean([data_5(i-1,j) data_5(i,j-1)])+(0.05*mean([data_5(i-1,j) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i,j-1)]);
>            end
>            if data_5(i,j)<mean([data_5(i-1,j) data_5(i,j-1)])-(0.05*mean([data_5(i-1,j) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i,j-1)]);
>            end
>     end
>     %% Correct sides of matrix
>
>     if i<2 && j>1 && j<180
>            if data_5(i,j)>mean([data_5(i+1,j) data_5(i,j+1) data_5(i,j-1)])+(0.05*mean([data_5(i+1,j) data_5(i,j+1) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i+1,j) data_5(i,j+1) data_5(i,j-1)]);
>            end
>            if data_5(i,j)<mean([data_5(i+1,j) data_5(i,j+1) data_5(i,j-1)])-(0.05*mean([data_5(i+1,j) data_5(i,j+1) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i+1,j) data_5(i,j+1) data_5(i,j-1)]);
>            end
>     end
>
>     if i>359 && j>1 && j<180
>            if data_5(i,j)>mean([data_5(i-1,j) data_5(i,j+1) data_5(i,j-1)])+(0.05*mean([data_5(i-1,j) data_5(i,j+1) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i,j+1) data_5(i,j-1)]);
>            end
>            if data_5(i,j)<mean([data_5(i-1,j) data_5(i,j+1) data_5(i,j-1)])-(0.05*mean([data_5(i-1,j) data_5(i,j+1) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i,j+1) data_5(i,j-1)]);
>            end
>     end
>
>     if i>1 && i<360 && j<2
>            if data_5(i,j)>mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j+1)])+(0.05*mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j+1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j+1)]);
>            end
>            if data_5(i,j)<mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j+1)])-(0.05*mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j+1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j+1)]);
>            end
>     end
>
>     if i>1 && i<360 && j>159
>            if data_5(i,j)>mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1)])+(0.05*mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1)]);
>            end
>            if data_5(i,j)<mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1)])-(0.05*mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1)]);
>            end
>     end
>     %% Correct middle of matrix
>
>     if i>1 && i<360 && j>1 && j<180
>            if data_5(i,j)>mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1) data_5(i,j+1)])+(0.05*mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1) data_5(i,j+1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1) data_5(i,j+1)]);
>            end
>            if data_5(i,j)<mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1) data_5(i,j+1)])-(0.05*mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1) data_5(i,j+1)]))
>            data_5(i,j)=mean([data_5(i-1,j) data_5(i+1,j) data_5(i,j-1) data_5(i,j+1)]);
>            end
>     end
>
> end
> end
>
> This script works fine for peaks which are not adjacent to other peaks, however, when plotting the set of data with surf it will still contain peaks because the peaks adjacent to other peaks will still have a higher mean value because of the value of the other peak. Is there an option to skip the adjacent peaks and find the next value which is not a peak, or is this not possible with this code?
>
> Thanks in forward


I think I'm going blind. You must love to type. Why not use short
variable names and factors 0.95 and 1.05:?

x = data_5;
% Corner Matrix size = [4 4 ]
cx = [ x( 1:2 , (1,2,end-1,end)) ; x( end-1:end , (1,2,end-1,end)) ];
% TopBottom Matrix size = [ 4 180 ]
tbx = ...
% Sides Matrix size = [ 360 4 ].
sx = ...

Just a thought,

Greg




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.