error using plot, vectors must be the same length

1 visualización (últimos 30 días)
Natasha Haataja
Natasha Haataja el 29 de Nov. de 2020
Comentada: Walter Roberson el 29 de Nov. de 2020
I and a novice at Matlab and in need of help: Here is my code
load('eegbruxism_data.mat');
x = eegbruxism(1,:); %original noisy signal
y = fft(x); %Fourier transform
fv = lowpass(x,60,256);
FV = fft(fv); %Fourier Transform of filtered signal
Fs = 256; %Sampling rate
DP = 288901; %Sample length
xhz = Fs*(0:(DP/2)-1)/DP; %Range to figure out where the cutoff frequency is.
Y = abs(y); %Absolute value because fft is complex number
FVabs = (0:abs(FV)/2);
figure;
plot(Y); %Fourier transform of EEG signal
xlabel("Time in seconds");
ylabel("Voltage");
figure;
plot(xhz,FVabs); % filtered Fourier transform of filtered signal
xlabel("Frequency in Hz");
ylabel("Voltage");
ERROR:
Error using plot
Vectors must be the same length.
Error in redoBME310 (line 20)
plot(xhz,FVabs); % filtered Fourier transform of filtered signal
>> I dont know how to fix this at all. I have researched and just dont get it. Can you please help?

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Nov. de 2020
FV = fft(fv); %Fourier Transform of filtered signal
That's a vector.
FVabs = (0:abs(FV)/2);
That is using the vector as the upper bound of a colon operator. When you use a non-scalar as a bound in a colon operator, the effect is the same as if you had used the first element. So you would have the equivalent of
FVabs = (0:abs(FV(1))/2);
And that is using the data result in FV(1) as the upper bound of the vector FVabs. The data result in the first entry of an fft() is equal to the sum of the input, so that in turn is mathematically
FVabs = (0:abs(sum(fv))/2);
It seems very unlikely that is what you are looking for.
  2 comentarios
Natasha Haataja
Natasha Haataja el 29 de Nov. de 2020
Sorry I originallly had:
FVabs = abs(FV)
I dont know how to make FVabs have the same length as xhz. so if I have
xhz= Fs*(0:(DP/2)-1)/DP; and FVabs= abs(FV)
how do i make these 2 have the same length?
Walter Roberson
Walter Roberson el 29 de Nov. de 2020
Those should not have the same length. Your xhz is a one-sided calculation, but the output of fft() is a two-sided calculation. You should read the first example for fft() which shows calculating the frequencies for what they plot.
You also appear to be confusing time and frequency.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by