Calculating frequency of a sine wave with varying frequency

7 views (last 30 days)
I have a sine wave with a varying frequency. I would like to plot the frequency over time.
My approach was to find all values >0 and set them to 1, and all other values to 0.
Now I have a vector, for example:
A = [1 1 1 1 0 0 1 1 1 0 0 0 0 1 0 0]
If I could sum all groups of ones and put the result in another vector I could calculate the frequency because I know how many sample points I have per time unit.
In short, what I would like to do is to sum all groups of ones separately and put them in a vector in the correct order, as the groups appear.
So the result for vector A above would be:
B = [4 3 1]
i.e. the sum of the first group of ones is 4, there are four ones. The second group has 3, and the last group has 1.
Thank you for you time.
kind regards,

Accepted Answer

Amer
Amer on 8 May 2014
Thank you,
I have a sine wave similar to this one,
How can I then plot the changing frequency? I would like to plot it over time.

More Answers (1)

Carlos
Carlos on 8 May 2014

Community Treasure Hunt

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

Start Hunting!