**You are now following this question**

- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.

# convert the time domain signal into frequency domain signal

11 views (last 30 days)

Show older comments

neamah al-naffakh
on 6 Sep 2016

Commented: neamah al-naffakh
on 5 May 2017

I have divided into two part in order to make the topic readable and useful and I'd like to thank Mr Star Strider for his useful answer and support

Ok, let carry on

I have the acceleration data of 3 axes(x, y, and z) and it's represented in time domain signal.

There are about 10500 records (data points or samples)in the file for each axis and I have divided these records into segments ( each segment contains 256 data points.

now, I'd like to convert each segment in the time domain into frequency domain .

As we know this can be done using FFT function

One of the limitations of using the FFT function is that the number of data points in the segment must be a power of two. and I have already fixed the size of each segment into 256( 2 to the power 8)

i have used this code,

% FD_Signal_X{nn,1}=fft(X_Segments_256{nn});

Note, NN is the number of segments, X_Segments_256 contains the data of X axes of each segment, which is 256

my question is

1- I have used this code to calculate the Energy of the frequency domain signal,

FD_Signal_X{nn,1}=fft(X_Segments_256{nn});

Energy_X{nn,1} = (FD_Signal_X{nn}).^2;

or this one is correct?

FD_Signal_X{nn,1}=fft(X_Segments_256{nn});

Magnitude_X {nn,1} = abs(FD_Signal_X{nn});

Energy_X{nn,1} = (Magnitude_X{nn}).^2;

With my respect

##### 0 Comments

### Accepted Answer

Star Strider
on 6 Sep 2016

The second is correct.

The first squares a complex signal, so both the real an imaginary parts of the signal are squared, producing a complex result. I do not believe that is what you want. I would not use it.

The second squares the absolute value of the complex signal, producing a real result. That calculates the power in your signal, essentially the power spectral density of your signal.

The energy of your signal at each frequency is the absolute value of the Fourier transform of your signal. The power at each frequency is the square of the energy.

##### 32 Comments

neamah al-naffakh
on 6 Sep 2016

hi Sir, thanks for your answer.

but I am wondering, why the values of the energy for one segment are vary

please see the attached file.

Star Strider
on 6 Sep 2016

My pleasure.

That file contains a single column of real numbers. If you calculated ‘energy’ according to your first method and then only took the real part, you discarded half your data.

You must calculate ‘energy’ as the absolute value.

The correct assignments in your code are actually:

FD_Signal_X{nn,1}=fft(X_Segments_256{nn});

Energy_X {nn,1} = abs(FD_Signal_X{nn});

Power_X{nn,1} = (Energy_X{nn}).^2;

neamah al-naffakh
on 6 Sep 2016

Hi sir, yeah i did that and the file contains the energy result after using the second methods

% FD_Signal_X{nn,1}=fft(X_Segments_256{nn});

Energy_X {nn,1} = abs(FD_Signal_X{nn});

Power_X{nn,1} = (Energy_X{nn}).^2;

but I am wondering, why the resulted Power values( 256 values) are vary .

for example , second record

(66075.73076)

and the records from 3-16 are

3.958173265

3.509642181

0.842873586

1.656928337

3.429357141

6.101991622

30.46589762

45.96662923

4.680624111

3.558046835

0.798304291

0.351307661

4.405742221

31.22155305

then again records 17 is so high

632.715222

with my respect

Star Strider
on 6 Sep 2016

It is necessary to calculate the frequency vector as well. See the R2015a documentation for fft, particularly the code between the first two (top two) plot figures. The linspace call creates the frequency vector.

It is not at all unusual for signals with the sort of periodicity your signals have (in the time-domain plots in your previous Question) to have some frequencies with significant amplitude, or energy, and power, and for other frequencies to have little energy and power. The Fourier transform of your signal should have some predominant frequencies.

neamah al-naffakh
on 6 Sep 2016

Hi Sir, thanks for your kind and quick answers.

To be honest, I don't understand this part, I tried my best with that part before but I don't get it .

could you help me to calculate the frequency vector (including some comments in the code like the last time) and explain why It is necessary to calculate the frequency vector ( where we are going to use it)

Star Strider
on 6 Sep 2016

My pleasure.

The frequency vector is important. See the R2015a version of fft, particularly the code between the first two plot figures.

The frequency vector in that documentation is calculated as:

f = Fs/2*linspace(0,1,NFFT/2+1);

where ‘Fs’ is the sampling frequency of your signal, and ‘NFFT’ is the length of the vector used to calculate the Fourier transform of your signal.

neamah al-naffakh
on 6 Sep 2016

Ok sir, many thanks for your comment .

NFFT=256;

Fss=30;

FD_Signal_X{nn,1}=fft(X_Segments_256{nn},NFFT)/L;

f = Fss/2*linspace(0,1,NFFT/2+1);

Magnitude_X {nn,1} = abs(FD_Signal_X{nn});

Energy_X{nn,1} = (Magnitude_X{nn}).^2;

now there are some points and, hopefully, I will get the answer from you sir.

1- the length of (X_Segments_256) is 256 therefore, I have assigned NFFT=256, Is that correct?

2- FSS= 30 Because if you remember that we have fixed it to 30 in the previous topic.

3- for My signal, what should I assign to L, as in the example L has assigned to 1000 and they said it's the Lenght of the signal?

4- as you see in the code, we have calculated Frequency vector but we haven't use it yet! so why we calculate it ?

Kind regards and many thanks for your full support

Star Strider
on 6 Sep 2016

My pleasure.

1. Correct.

2. I remember that we had to resample it to 30 Hz.

3. In this example, ‘L’ is the length of the signal that you use as the time-domain argument to the fft function (instead of the length of a zero-padded signal), so in your example, ‘L=256’ as I understand your code.

4. The principal reason to calculate the frequency vector is to understand the frequency content of your signal, especially if you are plotting it. In your code, plotting it helps you to be certain you are calculating the Fourier transform correctly. It is always a good idea to check the results of your code as you develop it, so you know that the code to that point is correct.

neamah al-naffakh
on 6 Sep 2016

OMG, How kind and helpfull you are sir .

I will back again after testing the code.

Kind regards.

neamah al-naffakh
on 7 Sep 2016

Hi sir, I have calculated the minimum for each segment in the frequency domain using this code

Minimum_FD(nn,:)=min(Energy_X{nn});

1-I don't know how much these long number ( e.g. 6.342167952642086e-04) represents. therefore, how can I simplify these numbers I want the output the form of 4 digits after the don't (e.g. 1.0004) and ignore the remaining.

2- second question, I'd like to calculate the Entropy of the frequency domain signal and I have used this code

Ent_Xx(nn,:) = wentropy(Energy_X{nn},'shannon');

kind regards.

Star Strider
on 7 Sep 2016

1. The format of your data is controlled by the format function. In the Command Window, type:

doc format

for details of its use. I believe it applies to the data browser as well, but I can’t be certain.

2. You need to discuss the entropy calculation with your professor. As I recall, Shannon entropy is a measure of the information in a signal. I cannot tell if that is appropriate to your research. See the Wikipedia article on Entropy, specifically with respect to Information theory for a description.

neamah al-naffakh
on 10 Sep 2016

hi sir, thank you so much.

Sir, I tried to calculate spectral centroid for the segment named in my code (X2_Segments_256)

the length or data points in X2_Segments_256=256

I don't understand these points in the code

% - windowLength: the length of the window analysis (in number of samples)

% - step: the step of the window analysis (in number of samples)

Could you please re-write the code for me with your comments! please, I want some explanation for the each step in the code

kind regards.

Star Strider
on 10 Sep 2016

My pleasure.

I would help you with it if it were my code.

It isn’t.

Please contact the author for help with it.

neamah al-naffakh
on 10 Sep 2016

Thank you so much.

sir, do you know how to calculate the spectral centroid of a Signal?

Regards.

Star Strider
on 10 Sep 2016

My pleasure.

I’ve never needed to calculate it in my work with signal processing. The Wikipedia article on Spectral centroid indicates that it is the sum of the amplitude at each frequency multiplied by each frequency, divided by the sum of the frequencies. It would seem to be a relatively straightforward calculation.

neamah al-naffakh
on 11 Sep 2016

thank you so much Sir, I will try to follow your guidelines and I will let you know soon.

by the way Sir, I know you referred my to some references regarding (MFCC and BFCC) and I know the code is already written. However, please don't forget me as I need your help with them.

neamah al-naffakh
on 22 Sep 2016

Hi sir,

I have N number of users, each one has set of samples (features) that are going to be used for authentication.

However, as we know not all features that have been calculated are useful as some of them might be influenced the accuracy. Hence, I want to select the best features that are discriminative (unique) for each user.

For example, each feature belongs to User 1(i.e. ' Muna-SD.mat'), I have calculated the Standard deviation and the mean value; and the procedure has repeated for User2 (' Aisa-SD.mat'). i have written this code.

load('Muna-SD.mat' );

stdev_Acc_Max_X_U1=std(feature_vector (:,1));

stdev_Acc_Max_Y_U1=std(feature_vector (:,2));

stdev_Acc_Max_Z_U1=std(feature_vector (:,3));

Avg_Acc_X_U1=mean(feature_vector (:,1));

Avg_Acc_Y_U1=mean(feature_vector (:,2));

Avg_Acc_Z_U1=mean(feature_vector (:,3));

load('Aisa-SD.mat' );

stdev_Acc_Max_X_U2=std(feature_vector (:,1));

stdev_Acc_Max_Y_U2=std(feature_vector (:,2));

stdev_Acc_Max_Z_U2=std(feature_vector (:,3));

Avg_Acc_X_U2=mean(feature_vector (:,1));

Avg_Acc_Y_U2=mean(feature_vector (:,2));

Avg_Acc_Z_U2=mean(feature_vector (:,3));

- I have attached the Muna-SD.mat and Aisa-SD.mat*

in order to see which feature are useful, I want to draw features in a graph

could you help me to draw the standard deviation of each single feature for all users in one graph?

x-axis represents users and Y-axis represents the mean.

kind regards.

Star Strider
on 22 Sep 2016

We are now into classification, and while I have done it, I have not done it at all recently. If you want to do dimension reduction in your data, see the documentation for pca, princomp and related functions for the function best suited to your data and application.

There are several ways to do classification, including neural networks. I would begin the classification with the classify function, that does linear discriminant analysis. The classification functions will determine what characteristics of your feature vectors are important for the classification, and what can be ignored. That is the reason to do the pca analysis first.

Classification problems are out of my areas of recent expertise. This is probably best considered as a new Question, where those with specific expertise in classification can see it.

neamah al-naffakh
on 22 Sep 2016

Hi sir,

no i am not into classification yet! i only want to draw each single feature for all user in one single graph to see how far each single feature for User1 from user2

kind regards

Star Strider
on 22 Sep 2016

You need to determine the useful features with pca or related functions. You cannot do this reliably by looking at a plot of it.

I am not certain what you want to plot. Consider the errorbar plot if you want to plot specific means and standard deviations.

neamah al-naffakh
on 23 Sep 2016

Hi Sir,

ok let me explain it in more details.

suppose we have 100 features for each user ( e.g. Max, Min, etc)

For each one of the above features, i have 35 values (e.g. 35 samples or values of Max Feature ).

Therefore, before sending all features to any classification algorithem, I need to identify which feature is useful.

in order to select the optimal features, each single feature should go through two tests ( similarity of the user's samples (ideally the similarity score should be small as much as possible), and the dissimilarity (uniqueness) of the user's samples from imposters (ideally the dissimilarity score should be large as much as possible) .

1- the first test ( similarity test) is make sure that the multi-samples of one feature (e.g. Max) for the same user (e.g. user1) are very close to each other.

This can be achieved by calculating the standard deviation for the user's samples in order to see how similar the user's samples of that feature is ( e.g. calculate the standard deviation of the 35 samples of Max feature and as i meantioned above the , ideally the output should be small.

2- the second test ( dissimilarity test ) is to make sure that the (Max feature) of other users (i.e. Imposters or user2, user3, etc) are far enough from the ( Max) feature of user1.

This can be acheived by calcuting the Mean (e.g. mean of 35 samples of the Max feature), if the Mean output of other users (imposters) are far enough from user1, that means this feature (i.e. max ) is good to be used for authentication because it meet the requirments of the first and second tests.

After i calculted the standard deviation of ( 35 Max samples) and the Mean of ( 35 Max samples) for each user, my advisor suggested to represent them in graph to check if there is overlap between the feature of User1 and the remaining users.

I hope you get what i mean !

kind regards.

Star Strider
on 23 Sep 2016

That is the reason I suggest that you begin with the pca function or its friends.

Star Strider
on 23 Sep 2016

I would first consult with a statistician at your university on how best to approach this.

neamah al-naffakh
on 23 Dec 2016

Dear Star Strider, I'm back again and hopefully you are ok.

Dear Sir, could you help me with this question please?

Really appreciate your help and support.

Merry Christmas

Star Strider
on 23 Dec 2016

My pleasure.

I’m sorry, but I can’t help with your other Question. I’m not even certain what you’re doing.

Merry Christmas to you too!

neamah al-naffakh
on 5 May 2017

### More Answers (0)

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!**An Error Occurred**

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.