フィルターのクリア

Vectors must be the same length.

387 ビュー (過去 30 日間)
Nasser Aljadeed
Nasser Aljadeed 2015 年 9 月 23 日
編集済み: Image Analyst 2021 年 4 月 3 日
Every time I run this code, I get "Error using plot Vectors must be the same length.
Error in ex (line 24) plot(t,abs(Y)) "
Here is my code:
clear
dt = 1/100000;
tstart = 0;
tend = 0.020;
t=[tstart : dt : tend];
xc=25*sin(2*pi*150*t)-15*cos(2*pi*800*t);
T = 0.00025;
n = [tstart/T : tend/T];
x1=25*sin(2*pi*150*n*T)-15*cos(2*pi*800*n*T);
% Quantize Signal
x2=fix(x1);
% Define filter coefficents
A = [1];
B = [1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16];
% Filter the quantize signal
Y = filter(B,A,x2);
figure(1)
subplot(211)
plot(t,abs(Y))
xlabel('Frequency (rad/sec)')
ylabel('Magntidue')
subplot(212)
plot(t,angle(Y))
xlabel('Frequency (rad/sec)')
ylabel('Phase')

回答 (2 件)

the cyclist
the cyclist 2015 年 9 月 23 日
The proximate cause of your problem is that you are trying to make an X-Y plot, where X (your variable "t") has 2001 elements, and Y has 81 elements. So, MATLAB cannot figure out how plot each (X,Y) pair, because the two vectors do not have an equal number of points.
It is not easy for me to figure out what you intended to do.
  2 件のコメント
Nasser Aljadeed
Nasser Aljadeed 2015 年 9 月 23 日
How can I make these vectors have the same dimensions?
So : t =[tstart : dt : tend] has to have the same dimensions as n = [tstart/T : tend/T]?
the cyclist
the cyclist 2015 年 9 月 24 日
編集済み: the cyclist 2015 年 9 月 24 日
Probably the easiest way to ensure an equal number of elements, and uniform spacing, is to use the linspace command to create both vectors.

サインインしてコメントする。


Jae Song
Jae Song 2015 年 9 月 23 日
編集済み: Jae Song 2015 年 9 月 23 日
It looks like the variables xc and t have same size. So if you let x2 = fix(xc) instead of x2 = fix(x1). The plot should work. (I don't know that was your intention or not)
clear
dt = 1/100000;
tstart = 0;
tend = 0.020;
t=[tstart : dt : tend];
xc=25*sin(2*pi*150*t)-15*cos(2*pi*800*t);
T = 0.00025;
n = [tstart/T : tend/T];
x1=25*sin(2*pi*150*n*T)-15*cos(2*pi*800*n*T);
% Quantize Signal
x2=fix(xc);
% Define filter coefficents
A = [1];
B = [1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16];
% Filter the quantize signal
Y = filter(B,A,x2);
figure(1);
subplot(211);
plot(t,abs(Y))
xlabel('Frequency (rad/sec)')
ylabel('Magntidue')
subplot(212)
plot(t,angle(Y))
xlabel('Frequency (rad/sec)')
ylabel('Phase')
  2 件のコメント
saurabh jain
saurabh jain 2021 年 4 月 3 日
編集済み: saurabh jain 2021 年 4 月 3 日
can u help me in this code
Image Analyst
Image Analyst 2021 年 4 月 3 日
編集済み: Image Analyst 2021 年 4 月 3 日
@saurabh jain, probably not since @Jae Song was last here in 2015. But you might read this:
and then post your code (not an image of your code) in a new question so people can fix it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSingle-Rate Filters についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by