Error Using Plot for a Derived Fourier Transform Signal
1 次查看(过去 30 天)
显示 更早的评论
I derived the Fourier Transform of a signal analytically, and I am trying to plot its magnitude with respect to frequency. However, I keep getting the following error "Vectors must be the same length". I tried using linspace but I am not sure if I implemented it correctly.
clc;
BW=3000;
Fs=2*BW;
Ts=1/fs;
Tend=3;
Tend=ceil(Tend/Ts)*Ts;
N=(Tend/Ts)+1;
To=N*Ts;
Fo=1/To;
t=(0:Ts:(N-1)*Ts);
Freq=(-Fs/2:Fo:Fs/2-Fo);
G1=3*10^-3.*sinc(pi*f/1000).^2.*exp(-1i*pi*f/125);
G2=3*10^-3.*sinc(pi*f/2000).^2.*exp(-1i*pi*f/225);
Gf_Derived=(G1-G2);
figure(1)
plot(Freq,abs(Gf_Derived),'Linewidth',2)
grid on
0 个评论
采纳的回答
Sriram Tadavarty
2020-8-4
Hi Mohammed,
The code that is provided as some variable issues. I tried to correct and placed the code here, based on what u r trying to do.
The error you observe is due to the length of Freq and Gf_Derived, not being the same. In order to use plot, both the input lengths Freq and Gf_Derived must be the same.
Look over the modified code below:
clc;
BW=3000;
Fs=2*BW;
Ts=1/Fs;
Tend=3;
Tend=ceil(Tend/Ts)*Ts;
N=(Tend/Ts)+1;
To=N*Ts;
Fo=1/To;
t=(0:Ts:(N-1)*Ts);
Freq=(-Fs/2:Fo:Fs/2-Fo);
G1=3*10^-3.*sinc(pi*Freq/1000).^2.*exp(-1i*pi*Freq/125);
G2=3*10^-3.*sinc(pi*Freq/2000).^2.*exp(-1i*pi*Freq/225);
Gf_Derived=(G1-G2);
figure(1)
plot(Freq,abs(Gf_Derived),'Linewidth',2)
grid on
Hope this helps.
Regards,
Sriram
2 个评论
Sriram Tadavarty
2020-8-4
Hope it helped.
Feel free to accept the answer, if it helped.
Regards,
Sriram
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Transforms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!