Error Using Plot for a Derived Fourier Transform Signal

4 ビュー (過去 30 日間)
Mohammed Alsubhi
Mohammed Alsubhi 2020 年 8 月 4 日
コメント済み: Sriram Tadavarty 2020 年 8 月 4 日
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

採用された回答

Sriram Tadavarty
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 件のコメント
Mohammed Alsubhi
Mohammed Alsubhi 2020 年 8 月 4 日
Thank you!
Sriram Tadavarty
Sriram Tadavarty 2020 年 8 月 4 日
Hope it helped.
Feel free to accept the answer, if it helped.
Regards,
Sriram

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by