Lab4 PDF
Lab4 PDF
T = 1/Fs;
t = -1:T:1;
f0 = 10;
x_t = cos(2*pi*f0*t);
n = -100:100;
x_n = cos(pi/4 * n);
% Plot
figure(1);
subplot(2,1,1);
plot(t, x_t);
title('Analog Signal x(t)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
stem(n, x_n);
title('Discrete Signal x[n]');
xlabel('Samples');
ylabel('Amplitude');
grid on;
1
Published with MATLAB® R2024b
2
Fs = 100;
T = 1/Fs;
t = -1:T:1; % Continuous-time axis
% Analog signal
x_t = cos(pi/10*t) + 0.2*sin(pi/2*t);
% Discrete-time signal
n = -10:10;
x_n = cos(pi/10*n) + 0.2*sin(pi/2*n);
% Plot
figure(2);
subplot(2,1,1);
plot(t, x_t);
title('Analog Signal x(t)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
stem(n, x_n);
title('Discrete Signal x[n]');
xlabel('Samples');
ylabel('Amplitude');
grid on;
X_n = fft(x_n);
f_n = linspace(-Fs/2, Fs/2, length(X_n));
plot(f_n, abs(fftshift(X_n)));
title('DFT of x[n]');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
1
Published with MATLAB® R2024b
2
f0 = 100e3;
t = 0:1/(100*f0):1/f0;
x_t = cos(2*pi*f0*t);
subplot(length(samples_per_sec),1,i);
stem(n, x_n, 'r');
hold on;
plot(t, x_t, 'b');
title(['Sampling rate = ', num2str(Fs), ' samples/s']);
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
end
1
Published with MATLAB® R2024b