MATLAB: Error using plot, vectors must be the same length

error using plot

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?

Best Answer

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.
Related Question