Error Using Plot for a Derived Fourier Transform Signal

1 visualización (últimos 30 días)
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

Respuesta aceptada

Sriram Tadavarty
Sriram Tadavarty el 4 de Ag. de 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 comentarios
Sriram Tadavarty
Sriram Tadavarty el 4 de Ag. de 2020
Hope it helped.
Feel free to accept the answer, if it helped.
Regards,
Sriram

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Spectral Measurements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by