0% found this document useful (0 votes)
21 views8 pages

DSP Lab Open ended Fall 2023

Uploaded by

Be Educate
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)
21 views8 pages

DSP Lab Open ended Fall 2023

Uploaded by

Be Educate
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/ 8

Khwaja Fareed University of Engineering & Information Technology

Rahim Yar Khan

Department of Computer Engineering


Program: BS-CPEN-5
Open Ended Lab
[Course Code] CPEN-[3134] Course Engr. Muhammad Aqeel
Course Name: Digital Signal Processing Lab Instructor:
Total Marks: 20 Weightage: 20 %
Time Allowed: 100 Minutes Exam date: 22/12/2023

Name:Sawera Altaf

REG noCpen211101008

Note: Attempt all questions. Each question carries equal marks.

Q#1. (CLO-2) [PLO-2] C5 [05]

Design a program for Single-Sideband Amplitude Modulation?

% SSB-AM modulation and demodulation example in MATLAB

% Parameters

fs = 10000; % Sampling frequency (Hz)

T = 1; % Duration of the signal (seconds)

f_c = 1000; % Carrier frequency (Hz)

% Generate a message signal

t = 0:1/fs:T-1/fs;

message_signal = randn(size(t)); % Random message signal for demonstration

% SSB-AM modulation
carrier_signal = cos(2*pi*f_c*t);

ssb_am_modulated_signal = message_signal .* carrier_signal;

% SSB-AM demodulation

ssb_am_demodulated_signal = ssb_am_modulated_signal .* carrier_signal;

% Plot the signals

figure;

subplot(3,1,1);

plot(t, message_signal);

title('Message Signal');

subplot(3,1,2);

plot(t, ssb_am_modulated_signal);

title('SSB-AM Modulated Signal');

subplot(3,1,3);

plot(t, ssb_am_demodulated_signal);

title('SSB-AM Demodulated Signal');

xlabel('Time (seconds)');

Page 2 of 2
Q#2. (CLO-2) [PLO-2] [05]

Filter the sinusoidal signal using the band stop filter that has been designed. View the original signal and the
filtered signal in the Spectrum Analyzer. The tone at 1 kHz is unaffected. The tone at 12 kHz is filtered out and
attenuated, and the tone at 16 kHz is mildly attenuated because it appears in the transition band of the filter.

% Define your signal

fs = 10000; % Sampling frequency

t = 0:1/fs:1; % Time vector

f1 = 1000; % Frequency of the sinusoidal signal

f2 = 16000; % Frequency to be mildly displayed

signal = sin(2*pi*f1*t) + sin(2*pi*f2*t);

% Design a band-stop filter

f_stop_low = 900; % Lower stopband frequency

f_stop_high = 1100; % Upper stopband frequency

[b, a] = butter(4, [f_stop_low, f_stop_high]/(fs/2), 'stop');

Page 3 of 2
% Apply the filter

filtered_signal = filtfilt(b, a, signal);

% Plot the original and filtered signals

figure;

subplot(2,1,1);

plot(t, signal);

title('Original Signal');

subplot(2,1,2);

plot(t, filtered_signal);

title('Filtered Signal');

xlabel('Time (s)');

Q#3. (CLO-2) [PLO-2]C5 [05]

Design a program for Quadrature Amplitude Modulation of Two Sinusoidal Signals?

function qam_modulation_example()

Page 4 of 2
% Example of QAM modulation

% Generate example data (16-QAM symbols)

symbols_I = randi([-3, 3], 1, 100);

symbols_Q = randi([-3, 3], 1, 100);

% Modulate using QAM

[modulated_signal, time] = qam_modulation(symbols_I, symbols_Q, 16);

% Plot the modulated signal

figure;

plot(time, modulated_signal, 'LineWidth', 1.5);

title('QAM Modulation of Two Sinusoidal Signals');

xlabel('Time (s)');

ylabel('Amplitude');

grid on;

legend('QAM Modulated Signal');

end

function [modulated_signal, time] = qam_modulation(symbols_I, symbols_Q, modulation_order)

% QAM modulation function

samples_per_symbol = 100;

Page 5 of 2
symbol_rate = 1000; % in symbols per second

carrier_freq = 1e6; % in Hertz

% Time array

time = (0:(length(symbols_I) * samples_per_symbol - 1)) / symbol_rate;

% In-phase and Quadrature-phase components

i_component = zeros(1, length(time));

q_component = zeros(1, length(time));

% Modulate each symbol

for i = 1:length(symbols_I)

i_component((i - 1) * samples_per_symbol + 1:i * samples_per_symbol) = symbols_I(i);

q_component((i - 1) * samples_per_symbol + 1:i * samples_per_symbol) = symbols_Q(i);

end

% QAM modulation

modulated_signal = sqrt(2 / modulation_order) * (i_component .* cos(2 * pi * carrier_freq * time) - ...

q_component .* sin(2 * pi * carrier_freq * time));

Page 6 of 2
end

Q#4. (CLO-2) [PLO-2]C5 [05]

Design a Program for band stop Filters?


function bandstop_filter_example()
% Example of designing and applying a bandstop filter

% Sample signal
fs = 1000; % Sampling frequency in Hz
t = 0:1/fs:1; % Time vector
f1 = 50; % Frequency of the first sinusoidal component
f2 = 150; % Frequency of the second sinusoidal component
signal = sin(2*pi*f1*t) + 0.5*sin(2*pi*f2*t);

% Design bandstop filter


center_freq = 100; % Center frequency of the stopband
bandwidth = 20; % Bandwidth of the stopband
filter_order = 4; % Filter order

bandstop_filter = designfilt('bandstopiir', ...


'FilterOrder', filter_order, ...
'HalfPowerFrequency1', center_freq - bandwidth/2, ...
'HalfPowerFrequency2', center_freq + bandwidth/2, ...
'SampleRate', fs);

% Apply the bandstop filter to the signal


filtered_signal = filter(bandstop_filter, signal);

% Plot the original and filtered signals


figure;

subplot(2,1,1);
plot(t, signal);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');

subplot(2,1,2);
plot(t, filtered_signal);
title('Signal after Bandstop Filtering');

Page 7 of 2
xlabel('Time (s)');
ylabel('Amplitude');

sgtitle('Bandstop Filter Example');


end

-------------------- (Good Luck ) ------------------

Page 8 of 2

You might also like