Generate frequency spectrum of original and regenerated signal

1 Ansicht (letzte 30 Tage)
Laveeza
Laveeza am 17 Jan. 2023
Beantwortet: Sam Chak am 17 Jan. 2023
Hi I am using code from this video https://www.youtube.com/watch?v=Ww_8hPQcCHs&feature=youtu.be . I want to generate frequency spectrum of signal xa and xr. Can you guide me how to generate it.
A=1;F=2;theta=0;
dt=0.001;
t=0:dt:1;
xa=A*sin(2*pi*F*t + theta);
subplot(3,1,1);
plot(t,xa);
xlabel('time (sec)');
ylabel('xa');
title('Analogue (continous) Input Signal', 'LineWidth',5);
Fs=6*F; Ts=1/Fs;
n=Fs;
n1=0:Ts:n*Ts;
xs=A*sin(2*pi*F*n1+theta);
subplot(3,1,2);
stem(n1,xs);
xlabel('samples (n)');
ylabel('xs');
title('Discrete Time Signal', 'LineWidth',5);
t1=linspace(0,max(n1),(max(n1)/dt));
xr=interp1(n1,xs,t1,"linear");
subplot(3,1,3);
plot(t1,xr);
xlabel('time (sec)');
ylabel('xr');
title('Reconstructed Signal', 'LineWidth',5);

Antworten (1)

Sam Chak
Sam Chak am 17 Jan. 2023
You can copy and paste it on the Workspace and hit [Enter] to run it.
If you want to edit the code in the future, paste into a blank script, save a filename, maybe 'freq_gen.m' in a folder, and then "Run" it.
More info on how to add folders to search path:
A = 1;
F = 2;
theta = 0;
dt = 0.001;
t = 0:dt:1;
xa = A*sin(2*pi*F*t + theta);
subplot(3,1,1);
plot(t, xa);
xlabel('time (sec)');
ylabel('xa');
title('Analogue (continous) Input Signal', 'LineWidth',5);
Fs = 6*F;
Ts = 1/Fs;
n = Fs;
n1 = 0:Ts:n*Ts;
xs = A*sin(2*pi*F*n1 + theta);
subplot(3,1,2);
stem(n1, xs);
xlabel('samples (n)');
ylabel('xs');
title('Discrete Time Signal', 'LineWidth',5);
t1 = linspace(0, max(n1), (max(n1)/dt));
xr = interp1(n1, xs, t1, "linear");
subplot(3,1,3);
plot(t1, xr);
xlabel('time (sec)');
ylabel('xr');
title('Reconstructed Signal', 'LineWidth',5);

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by