# DFT for different data lengths

I have a sinusoidal signal that is sampled at $f_s=10$ Hz. I am asked to find the absolute value of the DFT for different data lengths (1 sec., 2 sec. etc.)

I do not understand where will I use the information about the data lengths.

Does the question want me to change the time vector for each attempt? as such:

** original time vector **

f=10;         % sampling freq
t=0:1/f:5;


rendering

x = cos(2*pi*3*t)


** time vector for each attempt **

t1=0:1/f:f*1; % data length = 1 sec
t2=0:1/f:f*2; % data length = 2 sec


thus rendering

x1 = cos(2*pi*3*t1);
x2 = cos(2*pi*3*t2);


and the rest would be how we usually get the FFT.

Did I understand the request correctly or not?

----Edit ------

The question is specifically for matlab simulation:

• In t1=0:1/f:f*1, you are mixing times (1/f) and frequencies (f*1). Use times for everything: t1 = 0:1/f:1 for samples going from 0 to 1 second. Feb 6, 2017 at 16:31

The information about the frequency of the sine seems to be missing. This could be an hint for you to compute the DFT exactly (not with Matlab simulation), for a given frequency $f$ and a number $s$ of seconds. Since the sampling frequency $f_0$ gives a integer multiple of samples inside one second, you should be able to find manageable formulas.

As commented by @Juancho, there is a lack of homogeneity in your time base: a frequency times a duration in seconds is not homogeneous to a time (it is unitless). A flexible solution is:

fs=10; % sampling freq
lFreq = [3 3.5 4]; % list of frequencies
lDuration = [1 2 4 10]'; % list of durations

for iDuration = 1:length(lDuration)
timeBase = [0:1/fs:lDuration(iDuration)]';
dataCosine = cos(timeBase*lFreq*2*pi); % Three cosines
data = sum(dataCosine,2); % sum the three cosine components
figure(iDuration)
plot(timeBase,data,'x-');
ylabel('Amplitude (a.u.)')
xlabel('Time (seconds)')
title(['Duration: ',num2str(lDuration(iDuration)),' s'])
grid on
end

• Hi, thank you. But the question is meant to be for matlab. I'm not sure how to incorporate the different "data lengths" into the solution. Was my attempt correct? Feb 7, 2017 at 6:47
• Not really, $f*1$ is a number of samples, not a length in seconds Feb 7, 2017 at 7:08