Why does a frequency input for a chirp not work?
Show older comments
Hello,
From references I saw that a linear sweep/chirp function creates frequencies which are not the actual frequencies which you can count if you see the output. There are formulas for calculating the right frequency for the input, but I don't understand why this is the case, as for a constant frequency this does work. See my code below for a clarification of my question
t = 0:0.01:5; % Time vector
%% Normal sine wave with 2 Hz
f=2*ones(1,length(t)); % Create a constant frequency vector
figure;
plot_y(t,f); % Plot the sine wave for this constant frequency vector
%% Linear sine wave from 1 to 2 Hz
f0 = 1; % Frequency at t=0
f1 = 4; % Frequency at t=t(end)
f=linspace(1,4,length(t)); % Create a linear frequency vector
hold on;
plot_y(t,f); % Plot the sine wave for this linear frequency vector
% This is how you should calculate a linear frequency for a sweep:
f=f0 + (f1-f0)/(2*t(end)).*t;
fprintf('f0 = %.1f, f1 = %.1f, f(1) = %.1f, f(end) = %.1f \n',f0,f1,f(1),f(end))
%% Plot info
legend('normal','linear')
title('Frequency from 1 to 2 Hz and only 2 Hz')
%% Function to plot (so you can see it is indeed the same way I calculate and plot it)
function plot_y(t,f)
y = sin(2*pi.*f.*t); % Normal sine function, where the frequency can be a function of time
plot(t,y);
end
From the graph you can clearly see that the linear frequency at the end is more than 4 Hz. With the other formula where f(end) = 2.5 Hz, the function works correctly.
Could anyone explain why this is the case? The reason I need to know this is that I also want to use a polyfit to estimate a range of frequencies, which I cannot approximate with an exponential or hyperbolic fit.
Thanks in advance!
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
