HELP! Error using plot Vectors must be the same length. Error in Doc (line 94) plot(t, y);
Hello everyone!! I’m trying to plot: x,y,X,Y. But when my matlab try to plot y, the following error appears: Error using plot Vectors must be the same length. Error in doc (lne 94) plot(t, y);
Please fell free to check the code below:
Fs = 5000;
T = 1/Fs;
t = 0:T:1-T;
NFFT = 2^nextpow2(length(t));
x = cos(2*pi*100*t) + cos(2*pi*500*t) + cos(2*pi*1000*t);
[X, f, ~] = fftm(x, Fs, NFFT);
H = double(f <= 600);
Y = X .* H;
y = ifft(Y);
figure;
subplot(2,1,1);
plot(t, x);
title(‘x(t)’);
xlabel(‘Time(s)’);
ylabel(‘Amp’);
subplot(2,1,2);
plot(t, y);
title(‘y(t)’);
xlabel(‘Time(s)’);
ylabel(‘Amp’);
figure;
subplot(2,1,1);
plot(f, abs(X));
title(‘X(omega)’);
xlabel(‘Freq(Hz)’);
ylabel(‘Mag’);
subplot(2,1,2);
plot(f, abs(Y));
title(‘Y(omega)’);
xlabel(‘Freq(Hz)’);
ylabel(‘Mag’);
Oh, the following function fftm in line 6, is a function downloaded by me, it’s a fft function modified, and you can see it below:
% Modified fft algorithm
%
% This function estimates the fft of a signal x using the Fs sampling
% frequency, NFFT bins, and returns the frequencies values along with the spectrum X.
%
% [X,f] = fftm(x,Fs,NFFT)
%
% Example:
% Fs = 1e3;
% t = 0:0.001:1-0.001;
% x = cos(2*pi*100*t)+sin(2*pi*202.5*t);
% [X,f]=fftm(x,Fs,2000);
% plot(f,abs(X));
% http://www.mathworks.com/help/signal/ug/amplitude-estimation-and-zero-padding.html
% http://www.mathworks.com/help/signal/ug/psd-estimate-using-fft.html
function [xdft,f, psdx] = fftm(x,Fs,NFFT)
L = length(x);
if nargin < 3
NFFT = 2^nextpow2(L);
end
xdft = fft(x,NFFT);
xdft = xdft(1:length(xdft)/2+1);
psdx = (1/(Fs*L)).*abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
psdx = 10*log10(psdx);
xdft = 1/L.*xdft;
xdft(2:end-1) = 2*xdft(2:end-1);
f = 0:Fs/NFFT:Fs/2;Hello everyone!! I’m trying to plot: x,y,X,Y. But when my matlab try to plot y, the following error appears: Error using plot Vectors must be the same length. Error in doc (lne 94) plot(t, y);
Please fell free to check the code below:
Fs = 5000;
T = 1/Fs;
t = 0:T:1-T;
NFFT = 2^nextpow2(length(t));
x = cos(2*pi*100*t) + cos(2*pi*500*t) + cos(2*pi*1000*t);
[X, f, ~] = fftm(x, Fs, NFFT);
H = double(f <= 600);
Y = X .* H;
y = ifft(Y);
figure;
subplot(2,1,1);
plot(t, x);
title(‘x(t)’);
xlabel(‘Time(s)’);
ylabel(‘Amp’);
subplot(2,1,2);
plot(t, y);
title(‘y(t)’);
xlabel(‘Time(s)’);
ylabel(‘Amp’);
figure;
subplot(2,1,1);
plot(f, abs(X));
title(‘X(omega)’);
xlabel(‘Freq(Hz)’);
ylabel(‘Mag’);
subplot(2,1,2);
plot(f, abs(Y));
title(‘Y(omega)’);
xlabel(‘Freq(Hz)’);
ylabel(‘Mag’);
Oh, the following function fftm in line 6, is a function downloaded by me, it’s a fft function modified, and you can see it below:
% Modified fft algorithm
%
% This function estimates the fft of a signal x using the Fs sampling
% frequency, NFFT bins, and returns the frequencies values along with the spectrum X.
%
% [X,f] = fftm(x,Fs,NFFT)
%
% Example:
% Fs = 1e3;
% t = 0:0.001:1-0.001;
% x = cos(2*pi*100*t)+sin(2*pi*202.5*t);
% [X,f]=fftm(x,Fs,2000);
% plot(f,abs(X));
% http://www.mathworks.com/help/signal/ug/amplitude-estimation-and-zero-padding.html
% http://www.mathworks.com/help/signal/ug/psd-estimate-using-fft.html
function [xdft,f, psdx] = fftm(x,Fs,NFFT)
L = length(x);
if nargin < 3
NFFT = 2^nextpow2(L);
end
xdft = fft(x,NFFT);
xdft = xdft(1:length(xdft)/2+1);
psdx = (1/(Fs*L)).*abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
psdx = 10*log10(psdx);
xdft = 1/L.*xdft;
xdft(2:end-1) = 2*xdft(2:end-1);
f = 0:Fs/NFFT:Fs/2; Hello everyone!! I’m trying to plot: x,y,X,Y. But when my matlab try to plot y, the following error appears: Error using plot Vectors must be the same length. Error in doc (lne 94) plot(t, y);
Please fell free to check the code below:
Fs = 5000;
T = 1/Fs;
t = 0:T:1-T;
NFFT = 2^nextpow2(length(t));
x = cos(2*pi*100*t) + cos(2*pi*500*t) + cos(2*pi*1000*t);
[X, f, ~] = fftm(x, Fs, NFFT);
H = double(f <= 600);
Y = X .* H;
y = ifft(Y);
figure;
subplot(2,1,1);
plot(t, x);
title(‘x(t)’);
xlabel(‘Time(s)’);
ylabel(‘Amp’);
subplot(2,1,2);
plot(t, y);
title(‘y(t)’);
xlabel(‘Time(s)’);
ylabel(‘Amp’);
figure;
subplot(2,1,1);
plot(f, abs(X));
title(‘X(omega)’);
xlabel(‘Freq(Hz)’);
ylabel(‘Mag’);
subplot(2,1,2);
plot(f, abs(Y));
title(‘Y(omega)’);
xlabel(‘Freq(Hz)’);
ylabel(‘Mag’);
Oh, the following function fftm in line 6, is a function downloaded by me, it’s a fft function modified, and you can see it below:
% Modified fft algorithm
%
% This function estimates the fft of a signal x using the Fs sampling
% frequency, NFFT bins, and returns the frequencies values along with the spectrum X.
%
% [X,f] = fftm(x,Fs,NFFT)
%
% Example:
% Fs = 1e3;
% t = 0:0.001:1-0.001;
% x = cos(2*pi*100*t)+sin(2*pi*202.5*t);
% [X,f]=fftm(x,Fs,2000);
% plot(f,abs(X));
% http://www.mathworks.com/help/signal/ug/amplitude-estimation-and-zero-padding.html
% http://www.mathworks.com/help/signal/ug/psd-estimate-using-fft.html
function [xdft,f, psdx] = fftm(x,Fs,NFFT)
L = length(x);
if nargin < 3
NFFT = 2^nextpow2(L);
end
xdft = fft(x,NFFT);
xdft = xdft(1:length(xdft)/2+1);
psdx = (1/(Fs*L)).*abs(xdft).^2;
psdx(2:end-1) = 2*psdx(2:end-1);
psdx = 10*log10(psdx);
xdft = 1/L.*xdft;
xdft(2:end-1) = 2*xdft(2:end-1);
f = 0:Fs/NFFT:Fs/2; vector, vectors must be the same length, error, matlab, vectors error, plot, plot error, fourier MATLAB Answers — New Questions