0% found this document useful (0 votes)
2 views6 pages

Lab4 PDF

The document contains MATLAB code for generating and plotting analog and discrete signals. It demonstrates the creation of cosine signals at different frequencies and sampling rates, along with their respective plots. Additionally, it includes a section for computing and plotting the Discrete Fourier Transform (DFT) of a discrete signal.

Uploaded by

dulguunn65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Lab4 PDF

The document contains MATLAB code for generating and plotting analog and discrete signals. It demonstrates the creation of cosine signals at different frequencies and sampling rates, along with their respective plots. Additionally, it includes a section for computing and plotting the Discrete Fourier Transform (DFT) of a discrete signal.

Uploaded by

dulguunn65
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Fs = 1000;

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);

samples_per_sec = [5, 10, 30, 80, 100];


figure(4);
for i = 1:length(samples_per_sec)
Fs = samples_per_sec(i) * f0;
Ts = 1/Fs;
n = 0:Ts:1/f0;
x_n = cos(2*pi*f0*n);

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

You might also like