0% found this document useful (0 votes)
52 views11 pages

PCS Lab 1

Uploaded by

Muneeb Ahmad
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)
52 views11 pages

PCS Lab 1

Uploaded by

Muneeb Ahmad
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/ 11

Page 1 of 11

EEE325-Principle of communication system

Lab # 01:

Name Jamal khan

Registration Number FA20-BEE-78


5-C
Class

Instructor’s Name Mam Asma Jadoon

Lab Assessment
Post Lab Total
In-Lab Data
Data Analysis Writing Style
Presentation
Page 2 of 11

Composite signal generation, spectrum, analysis, and filtering using


MATLAB.
In Lab Task # 01
Generate a sin wave of 1kHz frequency with only 5 cycles. Verify the frequency by
calculating the time period from the graph. Use grid and data cursor if required. Remember to
choose the appropriate sampling frequency and time vector.
Code In MATLAB:-
frequency = 1000;
num_cycle = 5;
duration = num_cycle/frequency;
sample = 10000;
t = 0:1/sample:duration;
sin_wave = sin(2*pi*frequency*t);
plot(t, sin_wave,'linewidth',2);
title('Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude(m)');
legend ('sin wave');
grid on;

Output:-

Figure:1.0: Output of in Lab Task # 01


Page 3 of 11

In Lab Task # 02
Analyze the frequency spectrum of the signal generated in task 1.1, with 100 cycles instead
of 5. However, show only 3 cycles in the figure (use xlim command).
Code in Matlab:-
frequency = 1000;
total_cycles = 100;
sampling_rate = 10 * frequency;
duration = total_cycles / frequency;
t = 0:1/sampling_rate:duration;
sine_wave = sin(2 * pi * frequency * t);
subplot(2,1,1)
plot(t, sine_wave,'g','linewidth',2);
xlabel('Time (s)');
ylabel('Amplitude');
title('1000 Hz Sine Wave with 100 Cycles');
grid on;
subplot(2,1,2)
plot(t, sine_wave,':g','linewidth',2);
xlabel('Time (s)');
ylabel('Amplitude');
title('1000 Hz Sine Wave with 100 Cycles');
grid on;
xlim([0, 3 / frequency]);

Output:-

Figure :2.0: Output of in Lab Task # 02


Page 4 of 11

In Lab Task # 03
Make a composite signal with sin wave of three frequencies: f1 = 500Hz, f2 = 2500Hz, f3 =
4000Hz. Assume equal amplitudes initially to analyze the frequency spectrum and change the
amplitudes of the three waves and describe the changes in the spectrum of composite signal.
Code in MATLAB:-
Fs = 10000;
t = 0:1/Fs:1;
frequencies = [500, 2500, 4000];
Amplitude = 1;
signals = Amplitude *sin(2. *pi *frequencies' *t);
composite_signal = sum(signals);
N = length(composite_signal);
frequencies = linspace(0, Fs/2, round(N/2) + 1);
spectrum = abs(fft(composite_signal)/N);

figure;
subplot(2, 1, 1);
plot(t, composite_signal);
title('Composite Signal (Equal Amplitudes)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('composite function')
grid on;

subplot(2, 1, 2);
plot(frequencies, 2*spectrum(1:round(N/2)+1),'linewidth',2);
title('Frequency Spectrum (Equal Amplitudes)');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
legend('freq spectrum')
grid on;

sgtitle('Composite Signal and Frequency Spectrum (Equal Amplitudes)');


Output:-

Figure: 3.0: Output of in Lab Task # 03


Page 5 of 11

In Lab Task # 04
Make a low-pass, band-pass and high-pass Butterworth filter of order 6 with following cutoff
frequencies:- Lowpass cutoff: 500Hz, High pass cutoff: 2500Hz, Bandpass cutoff: 500Hz-
4000Hz Visualize the filter magnitude and phase response and highlight the magnitude
response at the cutoff frequencies(use data cursor).
Code In MATLAB:-
flow = 500;
fhigh = 2500;
fband = [500 4000];
fs = 25e3;
n = 6;
[bl,al] = butter(n,flow/(fs/2));
figure(1); freqz(bl,al); title('Low Pass')
[bh,ah] = butter(n,fhigh/(fs/2), 'high');
figure(2); freqz(bh,ah); title('High Pass')
[bp,ap] = butter(n/2,fband/(fs/2), 'bandpass');
figure(3); freqz(bp,ap); title('Band Pass')

Output:-

Figure: 4.0: Output of in Lab Task # 04


Page 6 of 11

Figure: 4.1: Output of in Lab Task # 04

Figure:4.2: Output of in Lab Task # 04


Page 7 of 11

In Lab Task # 05
Use appropriate filters with appropriate cutoff frequencies to extract signal components from
composite signal in task 1.3. Plot Original signal with spectrum, and the extracted
components with respective spectra.
Code in MATLAB:-
Fs = 5000;
t = 0:1/Fs:1;
f1 = 500;
f2 = 2500;
f3 = 4000;
A = 1;

s1 = A*sin(2*pi*f1*t);
s2 = A*sin(2*pi*f2*t);
s3 = A*sin(2*pi*f3*t);
composite_signal = s1 + s2 + s3;

cutoff_lowpass = 150;
filter_order = 100;
lowpass_filter = designfilt('lowpassfir', 'FilterOrder', filter_order,
'CutoffFrequency', cutoff_lowpass, 'SampleRate', Fs);

cutoff_bandpass_low = 150;
cutoff_bandpass_high = 250;
bandpass_filter = designfilt('bandpassfir', 'FilterOrder', filter_order,
'CutoffFrequency1', cutoff_bandpass_low, 'CutoffFrequency2',
cutoff_bandpass_high, 'SampleRate', Fs);

cutoff_highpass = 2000;
highpass_filter = designfilt('highpassfir', 'FilterOrder', filter_order,
'CutoffFrequency', cutoff_highpass, 'SampleRate', Fs);
signal_lowpass = filter(lowpass_filter, composite_signal);
signal_bandpass = filter(bandpass_filter, composite_signal);
signal_highpass = filter(highpass_filter, composite_signal);
N = length(composite_signal);
frequencies = linspace(0, Fs/2, floor(N/2) + 1);
spectrum_original = abs(fft(composite_signal)/N);
spectrum_lowpass = abs(fft(signal_lowpass)/N);
spectrum_bandpass = abs(fft(signal_bandpass)/N);
spectrum_highpass = abs(fft(signal_highpass)/N);

figure;
subplot(4, 1, 1);
plot(t, composite_signal,'linewidth',2);
title('Original Composite Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(4, 1, 2);
plot(frequencies, 2*spectrum_original(1:floor(N/2)+1),'linewidth',2);
title('Original Signal Spectrum');
xlabel('Frequency (Hz)');
Page 8 of 11

ylabel('Magnitude');
grid on;

subplot(4, 1, 3);
plot(t, signal_lowpass,'linewidth',2);
title('Low-Pass Filtered Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(4, 1, 4);
plot(frequencies, 2*spectrum_lowpass(1:floor(N/2)+1),'linewidth',2); %

title('Low-Pass Filtered Signal Spectrum');


xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
figure;
subplot(4, 1, 1);
plot(t, signal_bandpass,'linewidth',2);
title('Band-Pass Filtered Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(4, 1, 2);
plot(frequencies, 2*spectrum_bandpass(1:floor(N/2)+1),'linewidth',2);

title('Band-Pass Filtered Signal Spectrum');


xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
subplot(4, 1, 3);
plot(t, signal_highpass,'linewidth',2);
title('High-Pass Filtered Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(4, 1, 4);
plot(frequencies, 2*spectrum_highpass(1:floor(N/2)+1),'linewidth',2); %

title('High-Pass Filtered Signal Spectrum');


xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
Page 9 of 11

Output:-

Figure:5.0: Output of in Lab Task # 05

Figure : 5.1: Output of in Lab Task # 05


Page 10 of 11

Discussion and Conclusion:


Discussion
Figure # 01
If you increase the frequency, the sine wave will oscillate more rapidly, resulting in a shorter
duration for the same number of cycles.Increasing the duration will result in more cycles,
while decreasing it will lead to fewer cycles.
Figure # 02
Frequency: Changing the frequency alters the rate of oscillation. Higher frequencies result in
more rapid oscillations, while lower frequencies lead to slower ones.
Total Cycles: Adjusting the total cycles changes the number of complete waveforms within
the given duration. Increasing the total cycles increases the number of wave cycles shown in
the graph, and vice versa.
Sampling Rate: Modifying the sampling rate affects the temporal resolution of the graph. A
higher sampling rate provides a more detailed representation of the waveform, while a lower
sampling rate results in a coarser depiction with potential aliasing effects if it falls below the
Nyquist rate
Figure # 03
When changing the frequency from 500 Hz to 2500 Hz and then to 4000 Hz, significant
alterations in the graph occur. Higher frequencies lead to more rapid oscillations in the time
domain, resulting in shorter waveforms within the same time duration. This compression of
the waveform visually demonstrates a higher-pitched and faster-changing signal. In the
frequency domain, the spectral peak shifts accordingly, reflecting the dominant frequency
component in each case, demonstrating the direct relationship between frequency and the
temporal and spectral characteristics of the signal.
Figure # 04
These Butterworth filters are commonly used in signal processing and have smooth frequency
responses, which means they introduce minimal distortion to the phase of the filtered signals
within their passbands. The filter order and cutoff frequencies can be adjusted to meet
specific filtering requirements based on the characteristics of the signals you are working
with
Figure # 05
We chose these filters to selectively extract specific frequency components from the
composite signal.
Low-Pass Filter: We used a low-pass filter with a cutoff frequency of 150 Hz to isolate
lower-frequency components and attenuate high-frequency noise, helping us focus on the
fundamental frequencies.
Band-Pass Filter: The band-pass filter with cutoff frequencies between 150 Hz and 250 Hz
allowed us to isolate a specific frequency band, filtering out both low and high-frequency
components while retaining the desired band of interest.
Page 11 of 11

Conclusion:-
 In this lab we learned how to use the basic cammands of matlab
 We learned how to plot different signals
 We learned how to create a sin wave and generate its graph
 We extrected 3 cycles from 100 cycles using xlim cammand
 We learned how to create a composite function and its frequency spectrum with cutoff
frequency
 We also learned about low pass,high pass and band pass and its phases

You might also like