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.

 Accepted 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);

6 Comments

garima sharma
garima sharma on 11 Jan 2021
Edited: garima sharma on 11 Jan 2021
thanks for prompt reply.
kindly note, I have edited my ques instead of 5Hz start freq., its 0.5Hz at start freq. the plot of recorded data is attached.
yes , Its similar to linear sine sweep with step of 0.5Hz.
I am changing the freq of a signal after each 6cycle. I mean at 0.5Hz start freq , i have 6 cycle and next at 1Hz 6cycle, then 1.5Hz has 6cycle and so on at 30Hz i have 6cycle.
how can i find Acceleration Vs Freq. data from this signal?
I imagine you have solved it long ago, but for what it's worth, you can just stitch the y values together:
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 long 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
ally = [];
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);
ally = [ally, y];
plot(ally, '-');
% hold on;
drawnow;
end
grid on;
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);
Thank you ! but I want to find FFT of this signal, I tried to find by taking 6 cycles of each freq then how to add all ffts since resoltion is varying for each block of fft
So go ahead. Did you try something simple like:
fty = fft(y);
yes but its not working,
even i cut every 6 cycle data and find fft for each freq. now, problem is how to merge data since each fft has different resolution.
If you want the same resolution for all of them, then just zero out the time domain signal wherever you don't want it to get just those signal. But of course you'll get the fft of the signal (which is a delta function) convolved with a sinc function since you're cropping it with a rect function. So the overall fft signal will be a sinc function, with a phase shift of course.
There should be no problem with all of them together - you should basically get separated spikes - one for each frequency. Not sure why you wanted to concatenate them, then separate them again anyway.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!