Error Using Plot for a Derived Fourier Transform Signal

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Sriram Tadavarty
Sriram Tadavarty am 4 Aug. 2020
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 Kommentare
Sriram Tadavarty
Sriram Tadavarty am 4 Aug. 2020
Hope it helped.
Feel free to accept the answer, if it helped.
Regards,
Sriram

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by