Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Threshold

Subject: Threshold

From: MahdiH

Date: 19 Jul, 2013 22:42:10

Message: 1 of 18

Hi Guys

well, What I would like to find is output signal after applying some threshold which is in my case equal to 3*sigma,
I was anticipating to get my signal back after applying the mentioned threshold but I did not get any thing except empty matrix, Any interpretation please?

Thanks in Advance

The code:
Fs = 1000; t = 0:1/Fs:.296;
x=(sin(2*pi*10*t)+2*cos(2*pi*6*t)+sin(2*pi*20*t)).*cos(2*pi*40*t);
y=awgn(x,10);
y1=var(y)
thr=3*sqrt(y1)
r = logical(y1 > thr);
Output = y1(r)

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 10:10:14

Message: 2 of 18

For starters your threshold is higher than max(y), so none of your data exceeds the threshold. Maybe you need to lower the threshold or think about whether you want all points below or above the threshold.

Subject: Threshold

From: MahdiH

Date: 20 Jul, 2013 10:22:10

Message: 3 of 18

"Chris " <cfweise@yahoo.com> wrote in message <ksdnm6$n9k$1@newscl01ah.mathworks.com>...
> For starters your threshold is higher than max(y), so none of your data exceeds the threshold. Maybe you need to lower the threshold or think about whether you want all points below or above the threshold.

Yes Chris , That's correct , I've decreased the Threshold but I have one more problem, When I would like plot the thresholded output I get one single point, How can I plot the whole thresholded Signal?

Best of Regards

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 10:28:13

Message: 4 of 18

I think you are mixing up y and y1.

Does the following work?:

Fs = 1000; t = 0:1/Fs:.296;
x=(sin(2*pi*10*t)+2*cos(2*pi*6*t)+sin(2*pi*20*t)).*cos(2*pi*40*t);
y=awgn(x,10);
y1=var(y)
thr=sqrt(y1)
r = y > thr;
Output = y.*r;


figure
hold on
plot(t,y)
plot(t,Output,'r')

Subject: Threshold

From: MahdiH

Date: 20 Jul, 2013 10:42:10

Message: 5 of 18

"Chris " <cfweise@yahoo.com> wrote in message <ksdont$p9n$1@newscl01ah.mathworks.com>...
> I think you are mixing up y and y1.
>
> Does the following work?:
>
> Fs = 1000; t = 0:1/Fs:.296;
> x=(sin(2*pi*10*t)+2*cos(2*pi*6*t)+sin(2*pi*20*t)).*cos(2*pi*40*t);
> y=awgn(x,10);
> y1=var(y)
> thr=sqrt(y1)
> r = y > thr;
> Output = y.*r;
>
>
> figure
> hold on
> plot(t,y)
> plot(t,Output,'r')

That's great Chris, appreciated your valuable comment, Accept my deep greetings.

Sincerely

Subject: Threshold

From: MahdiH

Date: 20 Jul, 2013 12:54:10

Message: 6 of 18

Dear Chris

The code below calculate the IMF( Intrinsic Mode Functions) through EMD tool, Once you run the code you will get several figures represent IMFs of the input signal.

The Question simply is:

I would like to evaluate these IMFs individually, i.e , would like to collect IMF1 and manipulate it alone and so for other IMFs.
I have written in the Prompt window of Matlab (imf) but did not recognized it.

Thanks in Advance

function emd2013()
t=0:0.001:1;
x=(sin(2*pi*10*t)+2*cos(2*pi*6*t)+sin(2*pi*20*t)).*cos(2*pi*40*t);

xo=x;
N = length(x);
figure,subplot(2,1,1),plot(t,x);subplot(2,1,2);
for i=1:8
    x=xo;
    SD=1;
    while SD>0.3
        [max k1] = findpeaks(x);
        maxenv=spline([0 k1 N+1], [0 max 0], 1:N);
        %maxenv=interpft(max,N); Not equally spaced
        [min k2] = findpeaks(-x);
        minenv=spline([0 k2 N+1], [0 -min 0], 1:N);
        %minenv=interpft(-min,N);
        m=(minenv+maxenv)/2;
        prev=x; x=x-m;
        SD=sum(((prev-x).^2)./(prev.^2+eps));
    end
    %subplot(2,1,1),hold;plot(t(k1),xo(k1),'b*');plot(t(k2),xo(k2),'r*');
    imf(i,:)=x;
    xo=xo-x;
    figure,subplot(2,1,1),plot(t,x);subplot(2,1,2);
end
figure,subplot(2,1,1),plot(t,xo);subplot(2,1,2);
  

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 14:26:23

Message: 7 of 18

You have at least two choices:

(1) add the directory in which you saved the function to the matlab search path, for instance with

addpath('directory')

(2) change the active directory in matlab to the directory containing your function:

cd('directory')

Once you take one of these steps your function should execute from the command line.

Subject: Threshold

From: MahdiH

Date: 20 Jul, 2013 14:41:11

Message: 8 of 18

Thanks for response
I have no problem in running my function from prompt window, What I want to do is finding imf(i,:) , for different values of i , I mean when I write for instance imf(2,:) i donot get it's corresponded value.

I need really to get these IMFs as a data that can be stored , not only in term of figures.

This is what I got after writing imf(2,:) in prompt window:

>> imf(2,:)
??? Undefined variable imf.


Best of regards

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 15:23:11

Message: 9 of 18

Sorry - I missed your question previously

I don't have the toolbox with imf/emd myself but there are some available in matlab central:

http://www.mathworks.com/matlabcentral/fileexchange/21409-empirical-mode-decomposition
http://www.mathworks.com/matlabcentral/fileexchange/37226-imf-for-bearing-fault-diagnosis
http://www.mathworks.com/matlabcentral/fileexchange/19681-hilbert-huang-transform

You will also need:
Spline Toolbox
Signal Processing Toolbox

Subject: Threshold

From: MahdiH

Date: 20 Jul, 2013 15:37:11

Message: 10 of 18

Hi Chris

My code is working well, and it's simple enough,

My question is :

In my code (at the end of the code) the value of imf(i,:)=x , it is calculated and plotted as u see if u run the code, what I want is the vector imf(i,:) , how can I get it not as a plot but as a data(vector)

Thx for your response

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 15:50:14

Message: 11 of 18

If I understand correctly you want the value of imf in your workspace. Then it has to be returned by the function, for instance as follows:

function imf=emd2013();

% ... your original function

Subject: Threshold

From: MahdiH

Date: 20 Jul, 2013 16:13:10

Message: 12 of 18

Hi Chris

I have changed the code as u told me, but still not able to get the IMF that I want (in workspace).

Let me put it in this way:

The code generate 8 IMFs according to the i loop plus some residue , I want to store these IMF in order to process them later in some different approaches.

I hope It is more obvious

My Deep appreciation

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 16:42:20

Message: 13 of 18

The function is returning 8 IMFs in a matrix, one per row. Since you are interested in the individual IMF's, try inspecting them individually once the IMF matrix is on your workspace. For instance, try

figure
plot(imf(1,:))
hold on
plot(imf(2,:))

to plot the first two

Subject: Threshold

From: MahdiH

Date: 20 Jul, 2013 17:58:18

Message: 14 of 18

Hi Chris

Thx very much for ur patience

I have cleared the workspace and I got:

ans <8*1001>

which is as u mentioned 8 IMFs , What I did is double click on (ans) in workspace and I have saved the first row as a data with extension .mat

Now, How can I use this data ? I wanna work on it ?

Sincerely

Mahdi

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 18:56:10

Message: 15 of 18

You can for instance loop through the individual IMFs as follows:


for ii=1:size(imf,1)

   x_ii = imf(:,ii);
   
   % ... do something here with x ....

end

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 19:14:08

Message: 16 of 18

If you saved your data as data.mat you can reload it with
load('data.mat')
(from the correct path or dir)
then use matrix imf which should be again on your workspace

Subject: Threshold

From: MahdiH

Date: 20 Jul, 2013 20:40:18

Message: 17 of 18

Many Thanks Chris

Hope every thing going fine.

Accept my Best wishes.

Sincerely

Subject: Threshold

From: Chris

Date: 20 Jul, 2013 20:52:07

Message: 18 of 18

Good luck with the computations!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us