0% found this document useful (0 votes)
7 views

Assignment-1 SNS Dhruv Parshad

Uploaded by

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

Assignment-1 SNS Dhruv Parshad

Uploaded by

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

Dhruv Parshad 3B(ECE)

2K22/EC/93
ASSIGNMENT -1
(Signal and System)

INPUT CODE:
% Define the parameters
T = 2; % Period of the square wave
t = linspace(0, 5*T, 1000); % Time vector
N_values = [1, 2, 10, 50, 100]; % Values of N

% (a) Generate the periodic square wave signal


signal_1 = square(2*pi*t/T);
plot(t,signal_1);
xlabel('t');
ylabel('Amplitude');
title('Square wave')

% (b) Calculate Fourier series coefficients (ak)


k = -11:11; % Range of k values
ak = zeros(size(k)); % Initialize coefficient vector

for i = 1:length(k)
ak(i) = (1/T) * trapz(t, signal_1 .* exp(-1i*2*pi*k(i)*t/T));
end

% Plot magnitude and phase spectra of Fourier coefficients


figure;

% Magnitude spectrum
subplot(2, 1, 1);
stem(k, abs(ak));
xlabel('k');
ylabel('|ak|');
title('Magnitude Spectrum');
xlim([-11, 11]);

% Phase spectrum
subplot(2, 1, 2);
stem(k, angle(ak));
xlabel('k');
ylabel('Phase (radians)');
title('Phase Spectrum');
xlim([-11, 11]);

% (c) Reconstruct the signal for different values of N and plot


figure;

for i = 1:length(N_values)
N = N_values(i);
signal_1_reconstructed = zeros(size(t)); % Initialize
reconstructed signal

for j = 1:length(k)
if abs(k(j)) <= 11
signal_1_reconstructed = signal_1_reconstructed +
ak(j) * exp(1i*2*pi*k(j)*t/T);
end
end

subplot(length(N_values), 1, i);
plot(t, real(signal_1_reconstructed), 'r', 'LineWidth', 1.5);
hold on;
plot(t, signal_1, 'b--');
xlim([0, 4*T]);
xlabel('Time');
ylabel('Amplitude');
title(['Reconstructed Signal, N = ' num2str(N)]);
legend('Reconstructed', 'Original');
end

OUTPUT :

a) Generation of Square Wave with time period ‘T=2’

b) Plotting magnitude and phase spectra of the FS


coefficients for -11<k<11.
c) Reconstructing the signal Signal_1 using the Fourier series
coefficients calculated in (b) above and the synthesis
equation, by using the following values of N = { 1, 2 , 10 ,
50 , 100}
All the reconstructed signals looks same as of actual signal_1
Also if the signal is reconstructed by adding the Fourier
series, then overshoots appear around the edges. These
overshoots decay outwards in a damped oscillatory manner
away from the edges. This is known as GIBBS phenomenon
The Fourier series approaches the original signal x(t) as the
number of terms in approximation increases.

You might also like