Clear Filters
Clear Filters

fft and discrete functions

3 views (last 30 days)
Arquelau
Arquelau on 23 Dec 2016
Edited: Star Strider on 23 Dec 2016
Hi,
I have a vector that contains the time (epoch) of an occurrence (many occurrences per second, for 300 seconds), and I want to determine the frequency of these occurrences, that is, plot its spectrum.
What I have done so far is counted the number of occurrences per second, but its FFT does not give me what I want.
I think that what I really need is a "signal" that is 1 at the times specified in the vector and 0 otherwise (such as stem). The FFT of that signal will give me what I want. But how can I create such a signal? I know the stem function only plots it. How can I have the FFT of that "stem" signal?

Accepted Answer

Star Strider
Star Strider on 23 Dec 2016
You can probably do what you want with a combination of thresholding and logical indexing. The Signal Processing Toolbox findpeaks function could be helpful, and would be what I would use first.
I don’t know what your data are or what counts as an ‘occurrence’, so I cannot be more specific.
  4 Comments
Arquelau
Arquelau on 23 Dec 2016
Edited: Arquelau on 23 Dec 2016
That is absolutely perfect! I appreciate very much your help! Just one last thing: When running on the actual file, I get an error at the line
OccVct([1; round(Intvls(2:end))]) = 1;
The error says
Subscript indices must either be real positive integers or logicals.
Turns out that when running in the actual file,
round(Intvls(2:end))
happens to be
Inf
I tried to understand why, but I couldnt. I did noticed that its value increases really fast as more packet times are added to the vector. Do you know how to solve it?
EDIT: Oh well, I realized now that
MinDPktTimes
is 0 (because there are 2 packets transmitted at nearly the same time?), which causes the division to result in infinit. Adding 0.0001 to its value solved the problem.
Again, I really appreciate your effort and willingness.
Star Strider
Star Strider on 23 Dec 2016
Edited: Star Strider on 23 Dec 2016
My pleasure!
I am not certain where in your vector the Inf value is being calculated. It represents an overflow condition, so it occurs where the packet time is large enough that when divided by the sampling interval, it produces an infinite result. If it occurs at or near the end of the vector, I would replace it with the length of the vector by adding this line just after the ‘Intvls’ calculation assignment:
Intvls(isinf(Intvls)) = max(Intvls(isfinite(Intvls)));
If it occurs earlier in the vector, this will not produce correct data. In that instance, we need to find an alternative solution.
EDIT — If two packets are so close as to cause a nearly infinite result, either this:
MinDPktTimes = min(DPktTimes(DPktTimes > 0)); % Minimum Difference (Becomes Sampling Interval)
or this:
MinDPktTimes = min(DPktTimes(DPktTimes > 1E-8)); % Minimum Difference (Becomes Sampling Interval)
should solve the problem. You may have to tweak the threshold (here 1E-8) to get the result you want.
Another alternative is to sort the ‘DPktTimes’ sampling intervals and choose the first non-zero value as the correct one. With a large vector, this will slow your code.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 23 Dec 2016
Why is the mean frequency simply not the count divided by the observation time? If you have 300 thousand in 300 seconds, they occurred at a rate of one thousand per second. What other information do you need?
  1 Comment
Arquelau
Arquelau on 23 Dec 2016
Edited: Arquelau on 23 Dec 2016
I am trying to determine and identify some patterns in our network, and a simple frequency wouldnt provide us much information for analysis. A frequency spectrum (if applied in some specific packets) will help us identify if and when our netowrk is under attack.
But I appreciate your attention and collaboration on the issue!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!