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 CenterFile Exchange에서 Smoothing and Denoising에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by