Generate frequency spectrum of original and regenerated signal

1 回表示 (過去 30 日間)
Laveeza
Laveeza 2023 年 1 月 17 日
回答済み: Sam Chak 2023 年 1 月 17 日
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);

回答 (1 件)

Sam Chak
Sam Chak 2023 年 1 月 17 日
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);

カテゴリ

Help Center および File ExchangeSmoothing and Denoising についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by