- 7

- 0

Hey everyone, first of all id just like to clarify this isnt a homework or coursework related problem, its part of my personal MatLab learning for future years. I obtained a nice little siganls and systems question off a friend, it looked fairly simple but ive come across a problem which i cant find a solution to. Here goes...

Investigate the frequency content X(f) of a single 10 Hz sinewave, lasting for a time T_end. Set the sample frequency to be fs=1000, and T_end to be 2. Plot the absolute value of the function X(f) as a against frequency f.

Here is my code for this part.

function [x, t] = sinewave(T_end)

fs = 1000;

ts = 1/fs;

T = T_end;

t = 0:ts:T_end-ts;

f= -fs/2 : 1/T : fs/2-1/T; % sets the frequecncy axis, between -500 and (500-0.5).

x = sin(2.*pi.*f.*t);

X = fft(x);

Y = fftshift(X); % shifts right hand end to its alias below f=0, as graph is periodic this just centers the plot about 0.

stem(f,abs(Y),'k')

xlabel('frquency Hz');

ylabel('Abs(X)');

title('frequency content at T end = 2');

I believe this to be correct, and can explain the results obtained at different T_end values.

The next part of the question is where I get stuck.

Replace the line that defines x(t) with the code,

t1= 0:ts:1.0-ts;

x=0*t;

x(1:length(t1))=sin(2*pi*f*t1);

figure(1)

plot(t,x)

figure(2)

in order to create a pulse of length 1.

When this code is entered i get the standard, Error using ==> times

Matrix dimensions must agree.

Error in ==> sinwav at 9

x(1:length(t1))=sin(2*pi*f*t1);

I know this error occurs due to matrix multiplication, but simply .*'ing does not solve it,

the matrix sizes are apparaently as follows, x[1 x 2000] , t1[1 x 1000], t[1x2000],f[1 x 2000]. And im not actually sure if i should add the .'s and this would change the outcome.

Any comments or information would be greatly appericated, and hopefully this will help others as well.

Many Thanks

Investigate the frequency content X(f) of a single 10 Hz sinewave, lasting for a time T_end. Set the sample frequency to be fs=1000, and T_end to be 2. Plot the absolute value of the function X(f) as a against frequency f.

Here is my code for this part.

function [x, t] = sinewave(T_end)

fs = 1000;

ts = 1/fs;

T = T_end;

t = 0:ts:T_end-ts;

f= -fs/2 : 1/T : fs/2-1/T; % sets the frequecncy axis, between -500 and (500-0.5).

x = sin(2.*pi.*f.*t);

X = fft(x);

Y = fftshift(X); % shifts right hand end to its alias below f=0, as graph is periodic this just centers the plot about 0.

stem(f,abs(Y),'k')

xlabel('frquency Hz');

ylabel('Abs(X)');

title('frequency content at T end = 2');

I believe this to be correct, and can explain the results obtained at different T_end values.

The next part of the question is where I get stuck.

Replace the line that defines x(t) with the code,

t1= 0:ts:1.0-ts;

x=0*t;

x(1:length(t1))=sin(2*pi*f*t1);

figure(1)

plot(t,x)

figure(2)

in order to create a pulse of length 1.

When this code is entered i get the standard, Error using ==> times

Matrix dimensions must agree.

Error in ==> sinwav at 9

x(1:length(t1))=sin(2*pi*f*t1);

I know this error occurs due to matrix multiplication, but simply .*'ing does not solve it,

the matrix sizes are apparaently as follows, x[1 x 2000] , t1[1 x 1000], t[1x2000],f[1 x 2000]. And im not actually sure if i should add the .'s and this would change the outcome.

Any comments or information would be greatly appericated, and hopefully this will help others as well.

Many Thanks

Last edited: