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

Signal Processing Assignment2

The document describes generating a signal with 3 frequencies and adding noise. It defines parameters for signal generation and FFT calculation. Plots of the time-domain signal and frequency spectrums with and without noise are shown.
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)
14 views8 pages

Signal Processing Assignment2

The document describes generating a signal with 3 frequencies and adding noise. It defines parameters for signal generation and FFT calculation. Plots of the time-domain signal and frequency spectrums with and without noise are shown.
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/ 8

Assignment 2: Signal

Processing Using MATLAB

Table of Contents
General Information ............................................................................................................................. 1
Clean Up ........................................................................................................................................... 1
Parameter Definitions (Signal Generation With and Without Noise) ............................................................. 1
Parameter Definitions (For FFT Calculation) ........................................................................................... 2
Plotting the Signals with their Frequency Spectrums ................................................................................. 2

General Information
Author: Haider Hasan Hamood

Date Created: 7-3-2024

Context: ECE308, Computer Aided Communication Systems Design Lab

Objective: We want to generate a sinusoidal signal with 3 frequencies (5, 10, 15 Hz) and find its Single-Sided and
Double-Sided Amplitude Spectrum Using FFT with and without noise

Clean Up
clear;
clc;
close all;

Parameter Definitions (Signal Generation With


and Without Noise)
frequencies = [5 10 15]; % [Hz] the 3 frequencies for the signal
Fs = 500; % [Hz] The sampling frequency
Ts = 1/Fs; % [s] The sampling time

time_interval_1 = 0:Ts:2-Ts; % [s] Time interval 1, corresponds to f = 5 Hz


time_interval_2 = 2:Ts:4-Ts; % [s] Time interval 2, corresponds to f = 10 Hz
time_interval_3 = 4:Ts:6-Ts; % [s] Time interval 3, corresponds to f = 15 Hz
t = [time_interval_1 time_interval_2 time_interval_3]; % [s] time intervals
grouped in one vector

sig_no_noise1 = sin(2*pi*frequencies(1)*time_interval_1); % [mW] first part of


the signal (with f = 5 Hz)

1
Assignment 2: Signal Pro-
cessing Using MATLAB

sig_no_noise2 = sin(2*pi*frequencies(2)*time_interval_2); % [mW] second part


of the signal (with f = 10 Hz)
sig_no_noise3 = sin(2*pi*frequencies(3)*time_interval_3); % [mW] third part of
the signal (with f = 15 Hz)
signal_no_noise = [sig_no_noise1 sig_no_noise2 sig_no_noise3]; % [mW] the 3
parts of the signal grouped in one vector

noise = 0.1*randn(size(t)); % the noise to be added to the signal


signal_with_noise = signal_no_noise + noise; % [mW] the signal with noise
added

Parameter Definitions (For FFT Calculation)


% For Signal without Noise...
SIG_FFT_No_Noise_singleSided = fft(signal_no_noise); % Fast Fourier-Transform
of the signal

signal_length = 3000; % for windowing

P2_1 = abs(SIG_FFT_No_Noise_singleSided/signal_length);
P1_1 = P2_1(1:signal_length/2 + 1);
P1_1(2:end) = P1_1(2:end)*2;

% Single-Sided Spectrum...
f_singleSided = (0:signal_length/2) * 2*Fs/signal_length;

% Double-Sided Spectrum...
f_doubleSided = (-signal_length/2:signal_length/2 - 1) * (2*Fs/signal_length);
SIG_FFT_No_Noise_doubleSided = fftshift(SIG_FFT_No_Noise_singleSided);

% For Signal With Noise...


SIG_FFT_with_Noise_singleSided = fft(signal_with_noise); % Fast Fourier-
Transform of the signal

% We'll use the same signal length and frequency range for the noisy signal

P2_2 = abs(SIG_FFT_with_Noise_singleSided/signal_length);
P1_2 = P2_2(1:signal_length/2 + 1);
P1_2(2:end) = P1_2(2:end)*2;

SIG_FFT_with_Noise_doubleSided = fftshift(SIG_FFT_with_Noise_singleSided);

Plotting the Signals with their Frequency Spec-


trums
figure(1);
subplot(3, 1, 1);
plot(t, signal_no_noise); xlabel('Time (s)'); ylabel('Power (mW)');
title('Time domain of the signal (no noise)');
grid on;

2
Assignment 2: Signal Pro-
cessing Using MATLAB

subplot(3, 1, 2);
plot(f_singleSided, P1_1); xlabel('f (Hz)'); ylabel('|P1(f)|');
title('Single-Sided Amplitude Spectrum of the signal (no noise)');
grid on;
subplot(3, 1, 3);
plot(f_doubleSided, abs(SIG_FFT_No_Noise_doubleSided/signal_length));
xlabel('f (Hz)'); ylabel('|P1(f)|');
title('Double-Sided Spectrum of the signal (no noise)');
grid on;

figure(2);
subplot(3, 1, 1);
plot(t, signal_with_noise); xlabel('Time (s)'); ylabel('Power (mW)');
title('Time domain of the signal (with noise)');
grid on;
subplot(3, 1, 2);
plot(f_singleSided, P1_2); xlabel('f (Hz)'); ylabel('|P1(f)|');
title('Single-Sided Amplitude Spectrum of the signal (with noise)');
grid on;
subplot(3, 1, 3);
plot(f_doubleSided, abs(SIG_FFT_with_Noise_doubleSided/signal_length));
xlabel('f (Hz)'); ylabel('|P1(f)|');
title('Double-Sided Spectrum of the signal (with noise)');
grid on;

3
Assignment 2: Signal Pro-
cessing Using MATLAB

Published with MATLAB® R2023a

4
University of Kufa 9th – Mar – 2024

Assignment 2: Signal
Processing Using Matlab
Haider Hasan Hamood // 3rd Stage -Morning Study-
ECE // University of Kufa

Simulink System

Fig. 1: Simulink System

Page | 1 Computer Aided Comm. Systems Design


University of Kufa 9th – Mar – 2024

Results

5 Hz 10 Hz 15 Hz

5 Hz 10 Hz 15 Hz

Fig. 2: The signal (with and without noise) in the time domain

Fig. 3: The signal (without noise) in the frequency domain (dB scale)

Page | 2 Computer Aided Comm. Systems Design


University of Kufa 9th – Mar – 2024

Fig. 4: The signal (with noise) in the frequency domain (dB scale)

Fig. 5: The signal (with and without noise) in the frequency domain (dB scale)

Page | 3 Computer Aided Comm. Systems Design


University of Kufa 9th – Mar – 2024

Fig. 6: The signal (without noise) in the frequency domain (Linear scale)

Fig. 7: The signal (with noise) in the frequency domain (Linear scale)

Page | 4 Computer Aided Comm. Systems Design

You might also like