0% found this document useful (0 votes)
16 views9 pages

LAB-1 Signal Concepts and Noise 2

This document outlines a laboratory exercise for CEN344 at King Saud University, focusing on signal concepts and noise. It includes tasks for generating square waves from sinusoids, analyzing the effects of limited bandwidth channels on signal propagation, and studying the impact of noise on received signals. The lab aims to provide practical experience with signal generation, filtering, and noise analysis using MATLAB.

Uploaded by

ai.ahmedeslam
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)
16 views9 pages

LAB-1 Signal Concepts and Noise 2

This document outlines a laboratory exercise for CEN344 at King Saud University, focusing on signal concepts and noise. It includes tasks for generating square waves from sinusoids, analyzing the effects of limited bandwidth channels on signal propagation, and studying the impact of noise on received signals. The lab aims to provide practical experience with signal generation, filtering, and noise analysis using MATLAB.

Uploaded by

ai.ahmedeslam
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/ 9

King Saud University

College of Computer and Information Sciences


Department of Computer Engineering
Course: CEN344
Prepared by: Dr. Abdulmohsen Mutairi

LAB-1: Signal Concepts and Noise


Objectives: In this LAB, you will learn to generate a square wave from basic sinusoids and
see the effect of limited channel bandwidth and noise.

Part 1: Generating approximate square wave from a sum of sinusoids

In this part, you are going to synthesize a square wave from its frequency components. As studied
in the lecture, a square wave with amplitudes +A and –A can be expressed as

4 1
𝑠(𝑡) = 𝐴 × × ∑ sin(2𝜋 𝑘𝑓 𝑡)
𝜋 𝑘
𝑘 𝑜𝑑𝑑,𝑘=1

where 𝑓 is the fundamental frequency. In this Lab, you are going to generate a square wave using as
many of its harmonics as you can.

1.1. First, as always in MATLAB you have to setup the sampling rate, the number of samples to be
generated and the time length of the signal. Let's assume that the maximum frequency that we
will generate in this experiment is 𝑓𝑚 = 1000 Hz.
fm=1000; % 1 KHz
Fs = 2*fm; % sampling rate must be twice the max freq. in the
signal
Ts =1/Fs; % sample time (interval between adjacent samples)
L = 16384; % number of samples generated
To=L*Ts; % time window (duration of signal)
t = 0:Ts:To-Ts; % time vector, from 0 up the last sample before To

1.2. Next, generate a 10 Hz square wave with amplitude 3 using a sum of sinusoids. Start with only
two sinusoids: the fundamental one + the second harmonic. You can start with the following
loop and modify it to increase the number of components in the signal.
A= ; % amplitude
f= ; % fundamental frequency
s=0; % clear the sum
K_max=100; % index of the highest harmonic
for k=1:2:K_max
s_k = A/k * sin(2*pi*k*f*t);
s = s + s_k;
end

1.3. Next, generate a 10 Hz square wave with amplitude 3 using the built-in MATLAB function
square() in order to compare to your approximate signal:
% generate a perfect square wave using MATLAB built-in function
s0 = A*square(2*pi*f*t); % square wave

1.4. Next, compute the frequency spectrum of s(t). First, you need to set the length of the FFT. It
must be at least equal to the number of samples (L) in the signal. It is better to have a number
that is a power of 2. Next, run the FFT which returns the complex values of the frequency
spectrum S(f). Take the magnitude of S and store it in a new vector S_mag. Note that you need
to normalize the values of the spectrum by L/2.
%
N = 2^nextpow2(L); % Next power of 2 from length of x
S = fft(s,N); % X(f) is frequency spectrum of x(t)
S_mag = abs(S) /(L/2); % magnitude spectrum |X(f)|. Must be
normalized by L/2

The FFT returns the frequency spectrum values from 0 up to the sampling frequency Fs. The first
half of this range represent the spectrum of the signal and the second half represent a mirror
image of it. From the sampling theorem, we know that Fs must be twice the maximum
frequency component of the signal. Therefore, the frequency range of interest to us is from 0 to
Fs/2.
%
% the spacing between each frequency bin is fo=1/To
fo=1/To;
f_vec = 0:fo:Fs/2-1; % frequency vector for plotting S(f)

1.5. Finally, plot the two time signals on the same figure to compare and also plot the frequency
spectrum. You should see the individual impulses at each of the frequency components.
% First plot the perfect square wave
figure(1);
subplot(2,1,1)
plot(t,s0,'r','LineWidth',2);
grid on;
axis([0 0.5 -3.5 3.5]); % limit the time plot to only 0.5 second
xlabel('time (seconds)');
hold on;
% Then, plot the approximate wave on top of the first one
plot(t,s,'b','LineWidth',2);
axis([0 0.5 -3.5 3.5]); % limit the time plot to only 1 second
grid on;
title('approx square wave');
legend ('s_0(t)','s_1(t)');
xlabel('time (seconds)');
hold off;
% Next, plot single-sided magnitude spectrum.
subplot(2,1,2)
plot(f_vec,S_mag(1:length(f_vec))) ; % plot X_mag versus the
frequency vector
title('Magnitude Spectrum of s(t)');
xlabel('Frequency (Hz)');
ylabel('|S(f)|');

1.6. Repeat steps 1.1-1.5 and increase the number of harmonics to 3, 5, 7, 10 and 100.
1.7. What can you say about the amplitude of the high-frequency components?
Part 2: The effect of limited-bandwidth channel on signal propagation

In this part, you are going to send a signal (which is an approximate square wave) through a limited-
bandwidth channel and study the distortion effect. A channel acts as a filter. In this experiment, we
will use simple channel filter

2.1. Set the sampling rate, the number of samples to be generated and the time length of the signal
as in Part 1.
fm=1000; % 1 KHz
Fs = 2*fm; % sampling rate must be twice the max freq. in the
signal
Ts =1/Fs; % sample time (interval between adjacent samples)
L = 16384; % number of samples generated
To=L*Ts; % time window (duration of signal)
t = 0:Ts:To-Ts; % time vector, from 0 up the last sample before To

2.2. Next, generate a 10 Hz square wave with amplitude 3 using a sum of sinusoids starting with the
fundamental frequency up to the 50th harmonic (K_max=100). You can start with the following
loop and modify it to increase the number of components in the signal.
A= ; % amplitude
f= ; % fundamental frequency
s=0; % clear the sum
K_max= ; % index of the highest harmonic
for k=1:2:K_max
s_k = A/k * sin(2*pi*k*f*t);
s = s + s_k;
end

2.3. Compute the frequency spectrum of s(t) as done in Part 1.


%
N = 2^nextpow2(L); % Next power of 2 from length of x
S = fft(s,N); % X(f) is frequency spectrum of x(t)
S_mag = abs(S) /(L/2); % magnitude spectrum |X(f)|. Must be
normalized by L/2
%
fo=1/To;
f_vec = 0:fo:Fs/2-1; % frequency vector for plotting S(f)

2.4. Now, create a channel filter. To simplify, we will just assume a simple filter that that has a
triangular shape decreasing from 2 down to 0 at the maximum bandwidth and then all filter
coefficients above B are zeros as in the following figure.
%
% Set the bandwidth of the channel
B= ; % bandwidth of channel Hz
H_length=floor(B/fo);
H=zeros(size(S_mag));
H(1:H_length)=linspace(2,0,H_length);
H_mag=abs(H); % this has no effect because our filter is a simple
with real coefficients Only

2.5. Next, pass the signal through the channel. From your signal & system course, you know that
the process of filtering is just multiplying the Fourier transform of s(t) by the transfer function
of the channel H. The received signal r(t) is inverse Fourier transform of the product.
%
R=S.*H; % Fourier transform of the received signal (r)
r_x = ifft(R);
r=real(r_x); % real part of the inverse FFT
%

2.6. Finally, plot the transmitted signal and the received signal and also plot the frequency spectrum
of the transmitted signal and the channel filter
% plot to compare the received signal to the transmitted one
figure(1);
subplot(2,2,1)
plot(t,s,'r','LineWidth',2); % plot the transmitted square wave
grid on;
axis([0 0.5 -3.5 3.5]); % limit the time plot to only 1 second
xlabel('time (seconds)');
title('transmitted signal s(t)');

subplot(2,2,3);
plot(t,r,'b','LineWidth',2); % plot the received signal
axis([0 0.5 -3.5 3.5]); % limit the time plot to only 1 second
grid on;
title('received signal r(t)');
xlabel('time (seconds)');

% Plot single-sided magnitude spectrum.


subplot(2,2,2)
plot(f_vec,S_mag(1:length(f_vec)),'r','LineWidth',2) ; % plot S_mag
versus the frequency vector
axis([0 1000 0 3.5]);
title('Magnitude Spectrum of signal |S(f)|');
grid on;
xlabel('Frequency (Hz)');

subplot(2,2,4)
plot(f_vec,H(1:length(f_vec)),'b','LineWidth',2) ; % plot H_mag
versus the frequency vector
title('Channel filter |H(f)|');
axis([0 1000 0 3.5]);
grid on;
xlabel('Frequency (Hz)');

2.7. Repeat steps 2.1-2.6 with different values of channel bandwidth B=10 Hz, 50 Hz, 200 Hz.
2.8. What can you say about the effect of channel bandwidth on the distortion of the signal?
Part 3: The effect of noise on signal propagation

In this part, you are going to send a signal (which is an approximate square wave) through a limited-
bandwidth channel and add a noise signal and study the effect on the received signal. Noise is a
signal with random amplitudes that gets added to the signal at the receiver.

3.1. Set the sampling rate, the number of samples to be generated and the time length of the signal
as in Part 1.
fm=1000; % 1 KHz
Fs = 2*fm; % sampling rate must be twice the max freq. in the
signal
Ts =1/Fs; % sample time (interval between adjacent samples)
L = 16384; % number of samples generated
To=L*Ts; % time window (duration of signal)
t = 0:Ts:To-Ts; % time vector, from 0 up the last sample before To

3.2. Next, generate a 10 Hz square wave with amplitude 3 using a sum of sinusoids starting with the
fundamental frequency up to the 50th harmonic (K_max=100) as done in Part 2.
A= ; % amplitude
f= ; % fundamental frequency
s=0; % clear the sum
K_max= ; % index of the highest harmonic
for k=1:2:K_max
s_k = A/k * sin(2*pi*k*f*t);
s = s + s_k;
end

3.3. Compute the frequency spectrum of s(t) as done in Part 1.


%
N = 2^nextpow2(L); % Next power of 2 from length of x
S = fft(s,N); % X(f) is frequency spectrum of x(t)
S_mag = abs(S) /(L/2); % magnitude spectrum |X(f)|. Must be
normalized by L/2
%
fo=1/To;
f_vec = 0:fo:Fs/2-1; % frequency vector for plotting S(f)

3.4. Now, create a channel filter as done in Part 2 with bandwidth of 100 Hz.
%
% Set the bandwidth of the channel
B= ; % bandwidth of channel Hz
H_length=floor(B/fo);
H=zeros(size(S_mag));
H(1:H_length)=linspace(2,0,H_length);
H_mag=abs(H); % this has no effect because our filter is a simple
with real coefficients Only
3.5. Next, pass the signal through the channel as done in Part 2.
%
R=S.*H; % Fourier transform of the received signal (r)
r_x = ifft(R);
r=real(r_x); % real part of the inverse FFT
%

3.6. Now, generate the noise signal with random amplitudes and add it to the received signal. Set
the noise power to 1 watt and later change to test multiple values of noise power
% generate the noise signal with power = 1;
noisePower= ;
n = sqrt(noisePower)*randn(1,length(r));

% Next, add the noise signal to the received signal


r_noisy = r + n; % received noisy signal

3.7. Then, compute the Signal to Noise Ratio (SNR) in Decibel (dB)
% First, compute the power of the received signal r(t)
signalPower = mean(r.^2);
% Then, compute the signal to noise ratio in dB
SNR = signalPower/noisePower;
SNR_dB = 10*log10(SNR);

3.8. Finally, plot the transmitted signal, the noise signal and the received noisy signal to compare
% plot to compare the received signal to the transmitted one
figure(1);
subplot(2,2,1)
plot(t,s,'r','LineWidth',2); % plot the transmitted square wave
grid on;
axis([0 0.25 -5 5]); % limit the time plot to only .25 second
xlabel('time (seconds)');
title('transmitted signal s(t)');

subplot(2,2,2);
plot(t,n,'b','LineWidth',1); % plot the noise signal
axis([0 0.25 -5 5]); % limit the time plot to only .25 second
grid on;
title(‘noise signal');
xlabel('time (seconds)');

subplot(2,2,3);
plot(t, r_noisy,'b','LineWidth',1); % plot the received noisy
signal
axis([0 0.25 -5 5]); % limit the time plot to only .25 second
grid on;
title(’received noisy signal');
xlabel('time (seconds)');
3.9. Repeat steps 3.1-2.8 with different values of noise power 4, 9, 16 Watts
3.10. What can you say about the relationship between the SNR and the quality of the
received signal?
3.11. What is the effect of decreasing the value of SNR on the process of converting signals to
bits at the receiver?

You might also like