frequency obtained by cftool is 10 times less than what I should get

1 view (last 30 days)
Hi everyone, I am using fourier series for one of my application. I was getting wrong result, so I decided to check the fit(t,variable,'fourier1') for small application. I used the following code to generate a cos wave
%%Angular Frequency
omega=0.65;
%%Time specifications:
Fs = 10; % samples per second
dt = 1/Fs; % seconds per sample
StopTime =200*omega/pi; % seconds
t = (0:dt:StopTime-dt)'; % seconds
%%Sine wave:
x = cos(omega*t);
% Plot the signal versus time:
figure;
plot(t,x);
I used this cos wave in cftool and fit function. both gave me results as in figure.
as you can see, in result I got w=omega=0.065 whereas The original signal was having angular frequency as 0.65;
I have tried this for other frequency too and result is always 10 times less. What am i doing wrong ?
  2 Comments
David Goodmanson
David Goodmanson on 15 May 2017
Hi Kunal, I don't have access to cftool but this gives the impression that some part of the calculation is not getting the message that your time array has spacing of 1e-1. If it were assumed instead that the spacing is 1, then the calculated omega is down by a factor of 10. If you change Fs to 20, does the answer change by that same factor?
Kunal Tiwari
Kunal Tiwari on 15 May 2017
@David, You nailed it. Changing Fs to 20 made the w reduce by half. I changed Fs to 1 and I got expected result. I was making the mistake of letting matlab assume the sampling frequency. Thanks.

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 14 May 2017
Decent starting values are critical to finding a good estimate. If you provide no starting values at all, then you get an arbitrary result, often something that will not make you happy.
  1 Comment
Kunal Tiwari
Kunal Tiwari on 14 May 2017
But does that mean matlab does not use traditional fourier series formulas ?
Actually my application involves equating the coefficients (a0,a1,b1) for getting estimations. So do you think it's better to try and implement these formulas over trying to use fit function ?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!