need help with the question

This code is not working i am using this to calulate the amplitude but i am getting this error
Index exceeds matrix dimensions.
Error in t31 (line 11)
F1=Fmag(N/2+1:N);
l
load('data.mat');
dt=t(2)-t(1);% t vector has equally spaced t so this seprates t values
N=length(t);
F=fft(f,N); %fast fourier transform of f/N
Fshifted=fftshift(F);%place 0 frequency in the centre
Fmag=norm(Fshifted);%magnitude of fshifted
nu_NY=1/dt/2;%nquist frequency
nu=linspace(0,nu_NY,N/2+1);%spectrum of frequncy vals associated with FFT frequencies
%adding postive and negative frequncies
F1=Fmag(N/2+1:N);
F2=Fmag(N/2:-1:1);
a=[F1,0]+[0,F2];
%plotting amplitued vs assoicated frequencies
plot(a,nu)

4 Kommentare

per isakson
per isakson am 16 Apr. 2019
Bearbeitet: per isakson am 16 Apr. 2019
Which is line 11?
I cannot spot t31 in your code.
What does data.mat contain?
dulanga
dulanga am 16 Apr. 2019
Bearbeitet: dulanga am 16 Apr. 2019
t31 is the m file name
Index exceeds matrix dimensions.
Error in t31 (line 11)
is F1=Fmag(N/2+1:N);
Data mat contain 1*2000 vector arrays of frequency and time
per isakson
per isakson am 16 Apr. 2019
Bearbeitet: per isakson am 16 Apr. 2019
Should it be indexing
F1=Fmag(N/2+1:N);
as in the error message or a multiplication
F1=Fmag*(N/2+1:N);
as in the code ???
dulanga
dulanga am 16 Apr. 2019
hmm i think i am wrong should be indexing but it doesnt work in my case

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 16 Apr. 2019

0 Stimmen

f is a vector. You fft it asking for an output the same length as it is, so F is a vector. fftshift of that is a vector. You then norm() that vector and assign the result to Fmag . norm() of a vector gives a scalar. Then on line 11, Fmag(N/2+1:N) is an attempt to index the scalar at a location that is not 1.

3 Kommentare

dulanga
dulanga am 16 Apr. 2019
noted now however the graph i get is very weird it should have 4 peaks as the question wants me to find the maximum amplitude
Walter Roberson
Walter Roberson am 16 Apr. 2019
We do not know what change you made to the code.
dulanga
dulanga am 16 Apr. 2019
this is my latest code i do get a plot however the graph below is what i get which is not correct as i should get 4 peaks. The chnage was i multiplied the Fmag by the vector.
F1=Fmag*((N/2)+1:N);
Capture.JPG
load('data.mat');
dt=t(2)-t(1);% t vector has equally spaced t so this seprates t values
N=length(t);
F=fft(f/N); %fast fourier transform of f/N
Fshifted=fftshift(F);%place 0 frequency in the centre
Fmag=norm(Fshifted);%magnitude of fshifted
nu_NY=1/dt/2;%nquist frequency
nu=linspace(0,nu_NY,(N/2)+1);%spectrum of frequncy vals associated with FFT frequencies
%adding postive and negative frequncies
F1=Fmag*((N/2)+1:N);
F2=Fmag*(N/2:-1:1);
a=[F1,0]+[0,F2];
%plotting amplitued vs assoicated frequencies
plot(a,nu)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 16 Apr. 2019

Bearbeitet:

am 16 Apr. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by