0

I want to find instantaneous frequency over a window of a signal. I am taking a small part of the signal and trying to find the instantaneous frequency in that window. But that frequency is not matching with the actual frequency of the signal. Below is my code.

close all; clear all; clc

fs = 25000;
T = 0.5;
t = 0:1/fs:T;
n = length(t);

m = floor(n/4);
f1 = 100;
z1 = cos(2*pi*f1*t(1:m));

f1 = 200;
z2 = cos(2*pi*f1*t(1:m));

f1 = 300;
z3 = cos(2*pi*f1*t(1:m));

f1 = 400;
z4 = cos(2*pi*f1*t(1:(n-3*m)));

z = [z1 z2 z3 z4];

window = 100;
wStart = 1;
wEnd = wStart + window;
freqs = [];

while wEnd < length(z)
    x = z(wStart:wEnd);
    y = t(wStart:wEnd);

    h=hilbert(x);   
    unrolled_phase = unwrap(angle(h));

    dx = diff(unrolled_phase);
    dy = diff(y);
    p = dx./dy;
    inst_freq = p/(2*pi) + 2*pi;
    freqs = [freqs inst_freq];

    wStart = wEnd;
    wEnd = wStart + window;
end

The plot of 'freqs' is this: plot(freqs)

I think there is something wrong with the way I am calculating the frequencies but I am not sure. Can anyone please help? I need to get the frequencies only as 100,200,300 and 400 as evident from the code. All I want to do is find the beginning point(time) of each frequency

BaluRaman
  • 265
  • 5
  • 16
  • Your hilbert function is not working as well as you think it should be working. Try using a lower sample rate (maybe 801 Hz) and smoothing the result with an averaging filter – Joe Serrano Mar 24 '14 at 18:20
  • The reason the hilbert transform isn't working as well as you would like it that while the hilbert transform of a sinusoid has constant magnitude and constant phase change, this signal consists of sinusoid segments, so there is a transient in the hilbert transform. – Joe Serrano Mar 24 '14 at 21:04

1 Answers1

0

The first, theoretical answer, is that a signal is really a combination of several frequencies. Also, if you are decomposing a signal into ranges of 100 Hz with bins of 100Hz, 200Hz, 300Hz, etc. then you will NOT be able to recreate the signal into exactly the same signal that was transformed. That is, an inverse transform can only use 4 freqs, and will combine in a way such that the input signal and recovered signal do NOT sound the same!

JackCColeman
  • 3,777
  • 1
  • 15
  • 21