0% found this document useful (0 votes)
22 views5 pages

Day11b1 Compressed

This document discusses sampling and reconstructing a signal composed of multiple sinusoids. It defines the continuous signal, samples it at different frequencies, reconstructs the sampled signals using interpolation, and plots the original, sampled, and reconstructed signals as well as their spectra. For each sampling frequency, it samples the continuous signal, reconstructs it using interpolation, and plots the sampled signal, reconstructed signal, and spectrum of the sampled signal.
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)
22 views5 pages

Day11b1 Compressed

This document discusses sampling and reconstructing a signal composed of multiple sinusoids. It defines the continuous signal, samples it at different frequencies, reconstructs the sampled signals using interpolation, and plots the original, sampled, and reconstructed signals as well as their spectra. For each sampling frequency, it samples the continuous signal, reconstructs it using interpolation, and plots the sampled signal, reconstructed signal, and spectrum of the sampled signal.
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/ 5

SAMPLING AND RECONSTRUCTION

% Define the frequencies of the sinusoids


frequencies = [20, 40, 60, 80]; % in Hz

% Define the time range for the signal


T = 1; % 1 second
t_continuous = 0:1/1000:T; % High-resolution time vector for plotting

% Initialize the continuous signal


x_continuous = zeros(size(t_continuous));

% Create the continuous signal by summing the sinusoids


for i = 1:length(frequencies)
x_continuous = x_continuous + sin(2 * pi * frequencies(i) * t_continuous);
end

% Create a figure for the original signal


figure;
subplot(6, 1, 1);
plot(t_continuous, x_continuous);
title('Original Signal (Continuous)');
xlabel('Time (s)');
ylabel('Amplitude');

1
% Define the sampling frequencies
fs_values = [60, 100, 140, 170]; % in Hz

% Initialize variables to store sampled signals and reconstructed signals


x_sampled = cell(1, length(fs_values));
x_reconstructed = cell(1, length(fs_values));

% Create a figure for the spectrum of the original signal


figure;
frequencies = (-500:500); % Frequency range for the spectrum
spectrum_original = abs(fft(x_continuous, 1001));
plot(frequencies, spectrum_original);
title('Spectrum of Original Signal');
xlabel('Frequency (Hz)');
ylabel('Magnitude');

% Sampling, Reconstruction, and Spectrum for each sampling frequency


for i = 1:length(fs_values)
fs = fs_values(i);

% Sample the signal


t_sampled = 0:1/fs:T;
x_sampled{i} = sin(2 * pi * frequencies(1) * t_sampled); % Initialize with the
first sinusoid

for j = 2:length(frequencies)

2
x_sampled{i} = x_sampled{i} + sin(2 * pi * frequencies(j) * t_sampled);
end

% Reconstruct the signal using interpolation (sinc interpolation)


t_reconstructed = 0:1/1000:T; % High-resolution time vector for reconstruction
x_reconstructed{i} = interp1(t_sampled, x_sampled{i}, t_reconstructed,
'spline');

% Create a figure for the sampled signal


figure;
subplot(3, 1, 1);
plot(t_sampled, x_sampled{i});
title(['Sampled Signal (Sampling Frequency = ' num2str(fs) 'Hz)']);
xlabel('Time (s)');
ylabel('Amplitude');

% Create a figure for the reconstructed signal


subplot(3, 1, 2);
plot(t_reconstructed, x_reconstructed{i});
title(['Reconstructed Signal (Sampling Frequency = ' num2str(fs) 'Hz)']);
xlabel('Time (s)');
ylabel('Amplitude');

% Create a figure for the spectrum of the sampled signal


subplot(3, 1, 3);
N = length(t_sampled);
spectrum_sampled = abs(fft(x_sampled{i}, N));
frequencies = (-fs/2):(fs/N):(fs/2-fs/N);
plot(frequencies, spectrum_sampled);
title(['Spectrum of Sampled Signal (Sampling Frequency = ' num2str(fs) 'Hz)']);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
end

3
4
5

You might also like