MATLAB: Linear swept sine wave

chirp signalfftlinear sweep sine

Hi,
I am trying to obtain the frequency response of a linear swept sine wave using Matlab. I have constant amplitude 1V sine signal from 0.5Hz to 30 Hz with a sampling of 1024Hz. Here frequency is increasing with a step of 0.5Hz and each frequency has 6cycle.
I am using Matlab to take the Fourier transform of the recorded signal. I am trying to plot this function from frequency 0.5Hz to 30 Hzbut FFT appears to noise only.
Could anybody tell me how to take FFT of linear swept sine wave?
I would be grateful for any hint on this.
Thanks in advance.

Best Answer

I'm not sure if
  1. you're changing the frequency in the signal, like a chirp signal, or
  2. if you just want to add all those 6 periods together, or
  3. if you just want to analyze each signal one at a time.
Which case is it? But here is a start:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fprintf('Beginning to run %s.m ...\n', mfilename);
% I have constant amplitude 1V sine signal from 5 Hz to 30 Hz
% with a sampling of 1024Hz. Here frequency is increasing with
% a step of 0.5 Hz and each frequency has 6 cycles.
% Make x axis:
dt = 1/1024;
% Longest period is for 5 Hz (.2 seconds)
% so 6 cycles would be 6 * 0.2 = 1.2 seconds.
x = 0 : dt : 1.2;
omega = 5 : 30
for k = 1 : length(omega)
thisOmega = omega(k);
thisPeriod = 1 / thisOmega;
fprintf('Omega = %.1f. Period = %.4f\n', thisOmega, thisPeriod);
% Determine where 6 cycles end
lastIndex = find(x <= 6 * thisPeriod, 1, 'last'); % For you to figure out.
thisx = x(1 : lastIndex);
y = sin(2 * pi * thisOmega * thisx);
plot(thisx, y, '-');
legendStrings{k} = sprintf('Omega = %.1f', thisOmega);
hold on;
drawnow;
end
grid on;
legend(legendStrings);
fontSize = 20
title('6 periods of several frequencies', 'FontSize', fontSize);
ylabel('Amplitude', 'FontSize', fontSize);
xlabel('Time in Seconds', 'FontSize', fontSize);
g = gcf;
g.WindowState = 'maximized';
fprintf('Done running %s.m.\n', mfilename);