Calculating the instantaneous frequency at the end of the data-vector.
5 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I do have a question on calculating the instantaneous frequency. To more specific, I do not understand the behavior of the instantaneous frequency, near the end of the vector you calculate it on.
After generating a chirp signal increasing form 0Hz to 45Hz over 30s, sampling frequency is 128Hz, I calculate the instantaneous frequencies of that signal in the intervals [0s|10s], [0s|20s] and [0s|30s]. Then I plot the results, as you see in the following image:

I do provide the source code for generating the plot yourself at the end of this post.
My questions are now:
- What generates that 'wiggling' in the calculations of the instantaneous frequency?
- Why does it always appear at the end of the interval it is calculated on? (There is also some 'wiggling' at the beginning but this is not that strong, by far.)
- And how to overcome it?
For calculating the instantaneous frequencies I used this formula which is also used on an example provided by MATLAB.
z = hilbert(y);
instfreq = Fs/(2*pi)*diff(unwrap(angle(z)));
, where 'y' is the real discrete input signal and 'z' its analytic signal.
As far as I understand the methods, employed by the calculation, they always only look at two neighboring entries of the vector, and not more.
- diff(), takes the difference between to neighboring entries.
- unwrap(), looks if a phase jump between to neighboring entries occures.
- angle(), calculates the angle between the real and imaginary part of one entry.
So where does that 'wiggling' come from, and why is it dependent on the length of the vector I look at, as you see, because the input-signal itself was not changed, but just evaluated over different intervals?!
Here is the source code, to check it for yourself:
I generated three chirp-signals, all ranging from 0Hz and getting to 45Hz at 30s. Sampling frequency is 128Hz.
fs = 128; % sampling frequency
f0 = 0; % Starting frequency of Chrip Signal at time t0
f1 = 45; % Frequency of Chirp Signal at time t1
t1 = 30; % Point in time [s] when f1 is reached
signallength_1 = 10; %Length of first signal [s]
signallength_2 = 20; %Length of second signal [s]
signallength_3 = 30; %Length of third signal [s]
timevector1 = 0 : 1/fs : signallength_1 - (1/fs); % Timevector1
timevector2 = 0 : 1/fs : signallength_2 - (1/fs); % Timevector2
timevector3 = 0 : 1/fs : signallength_3 - (1/fs); % Timevector3
From that, I generate three analytic signals (via the Hilber-Transformation):
chirp_signal1 = chirp(timevector1,f0,t1,f1); % Generate linear increasing chirp signal1
analytic1 = hilbert(chirp_signal1); % get analytic signal1
chirp_signal2 = chirp(timevector2,f0,t1,f1); % Generate linear increasing chirp signal2
analytic2 = hilbert(chirp_signal2); % get analytic signal2
chirp_signal3 = chirp(timevector3,f0,t1,f1); % Generate linear increasing chirp signal3
analytic3 = hilbert(chirp_signal3); % get analytic signal3
factor = fs/(2*pi);
i_freq1 = factor * diff(unwrap(angle(analytic1))); % Get instantaneous frequency1
i_freq1 = [0 i_freq1]; % Insert leading 0 to maintain size
i_freq2 = factor * diff(unwrap(angle(analytic2))); % Get instantaneous frequency2
i_freq2 = [0 i_freq2]; % Insert leading 0 to maintain size
i_freq3 = factor * diff(unwrap(angle(analytic3))); % Get instantaneous frequency3
i_freq3 = [0 i_freq3]; % Insert leading 0 to maintain size
And finally I plot them:
figure();
plot(timevector1,i_freq1);
hold on;
plot(timevector2,i_freq2);
plot(timevector3,i_freq3);
legend('Instantaneous Frequency 1','Instantaneous Frequency 2','Instantaneous Frequency 3');
xlabel('Time [s]');
ylabel('Frequency [Hz]');
I would be really thankful for advice, especially on how to overcome this problem.
Kind Regards Patrick
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!