NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Chapter 3: Data and Signals

Time Domain Signal (Sine Wave)
% Parameters
fs = 1000; % Sampling frequency (Hz)
t = 0:1/fs:1; % Time vector from 0 to 1 second
f = 5; % Frequency of the sine wave (Hz)
% Generate the sine wave
signal = sin(2 * pi * f * t);
% Plot the signal
figure;
plot(t, signal);
title('Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
Unit Step Signal

% Parameters
t = -1:0.01:1; % Time vector from -1 to 1 second
% Generate the unit step signal
u = t >= 0;
% Plot the unit step signal
figure;
plot(t, u);
title('Unit Step Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

Unit Impulse Signal
% Parameters
n = -5:5; % Discrete time vector
% Generate the unit impulse signal
delta = (n == 0);
% Plot the unit impulse signal
figure;
stem(n, delta);
title('Unit Impulse Signal');
xlabel('n');
ylabel('Amplitude');
grid on;

Generate and Compare Analog and Digital Signals
% Parameters
fs = 1000; % Sampling frequency for analog (Hz)
t = 0:1/fs:1; % Time vector from 0 to 1 second
f = 5; % Frequency of the sine wave (Hz)
% Generate the analog signal (sine wave)
analog_signal = sin(2 * pi * f * t);
% Sampling the analog signal to create a digital signal
fs_digital = 100; % Sampling frequency for digital (Hz)
t_digital = 0:1/fs_digital:1; % Digital time vector
digital_signal = sin(2 * pi * f * t_digital); % Sampled signal
% Plot both analog and digital signals
figure;
hold on;
plot(t, analog_signal, 'b', 'LineWidth', 1.5); % Analog signal
stem(t_digital, digital_signal, 'r', 'filled', 'LineWidth', 1.5); % Digital signal
title('Comparison of Analog and Digital Signals');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Analog Signal', 'Digital Signal');

grid on;
hold off;

MATLAB Code for Two Signals with Same Amplitude and Phase, Different

Frequencies

% Parameters
fs = 1000; % Sampling frequency (Hz)
t = 0:1/fs:1; % Time vector from 0 to 1 second
A = 1; % Amplitude of the signals
phi = 0; % Phase (in radians)
% Frequencies for the two signals
f1 = 5; % Frequency of the first signal (Hz)
f2 = 10; % Frequency of the second signal (Hz)
% Generate the two signals
signal1 = A * sin(2 * pi * f1 * t + phi); % First signal
signal2 = A * sin(2 * pi * f2 * t + phi); % Second signal
% Plot both signals
figure;
hold on;
plot(t, signal1, 'b', 'LineWidth', 1.5); % First signal in blue
plot(t, signal2, 'r', 'LineWidth', 1.5); % Second signal in red
title('Two Signals with Same Amplitude and Phase, Different Frequencies');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Signal 1 (f=5 Hz)', 'Signal 2 (f=10 Hz)');
grid on;
hold off;

Calculate the wavelength in cm if the frequency = 6 GHz
% Given frequency
frequency_GHz = 6; % Frequency in GHz
frequency_Hz = frequency_GHz * 1e9; % Convert to Hz
% Speed of light
speed_of_light = 3e8; % Speed of light in m/s

% Calculate wavelength in meters
wavelength_m = speed_of_light / frequency_Hz; % Wavelength in meters
% Convert wavelength to centimeters
wavelength_cm = wavelength_m * 100; % Wavelength in centimeters
% Display the result
fprintf('The wavelength for a frequency of %.2f GHz is %.4f cm.n', frequency_GHz,
wavelength_cm);

Explanation
1. Frequency Conversion: The frequency is converted from gigahertz (GHz) to hertz (Hz).
2. Speed of Light: The speed of light is set to 3×1083 times 10^83×108 m/s.
3. Wavelength Calculation: The wavelength is calculated in meters using the formula

λ = C/f

4. Conversion to Centimeters: The wavelength in meters is then converted to centimeters
by multiplying by 100.
5. Output: The result is printed in the command window.
MATLAB code of the period of a signal is 100 ms. What is its frequency in
kilohertz?
% Given period in milliseconds
period_ms = 100; % Period in milliseconds
period_s = period_ms / 1000; % Convert to seconds
% Calculate frequency in Hz
frequency_Hz = 1 / period_s; % Frequency in Hz
% Convert frequency to kilohertz
frequency_kHz = frequency_Hz / 1000; % Frequency in kHz
% Display the result
fprintf('The frequency of a signal with a period of %.2f ms is %.2f kHz.n', period_ms,
frequency_kHz);

MATLAB Code for Three Sine Waves with Same Amplitude and Frequency,

Different Phases

% Parameters
fs = 1000; % Sampling frequency (Hz)
t = 0:1/fs:1; % Time vector from 0 to 1 second
A = 1; % Amplitude of the signals
f = 5; % Frequency of the sine waves (Hz)
% Different phases (in radians)
phase1 = 0; % Phase of the first sine wave
phase2 = pi/2; % Phase of the second sine wave (90 degrees)
phase3 = pi; % Phase of the third sine wave (180 degrees)
% Generate the three sine waves
signal1 = A * sin(2 * pi * f * t + phase1); % First sine wave
signal2 = A * sin(2 * pi * f * t + phase2); % Second sine wave
signal3 = A * sin(2 * pi * f * t + phase3); % Third sine wave
% Plot the three sine waves
figure;
hold on;
plot(t, signal1, 'b', 'LineWidth', 1.5); % First sine wave in blue
plot(t, signal2, 'r', 'LineWidth', 1.5); % Second sine wave in red
plot(t, signal3, 'g', 'LineWidth', 1.5); % Third sine wave in green
title('Three Sine Waves with Same Amplitude and Frequency, Different Phases');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Phase = 0', 'Phase = pi/2', 'Phase = pi');
grid on;
hold off;

Explanation
1. Parameters: The sampling frequency (fs), time vector (t), amplitude (A), and frequency (f) are
defined.
2. Phase Definitions: Three different phases are defined for the sine waves: 000, π2frac{pi}{2}2π
(90 degrees), and πpiπ (180 degrees).
3. Signal Generation: Three sine waves are generated using the sine function with the specified
phases.
4. Plotting: The sine waves are plotted on the same graph for visual comparison, with appropriate
legends and labels.

MATLAB code that generates a constant signal (0 Hz sine wave) and plots both

its time-domain and frequency-domain representations.

% Parameters
fs = 1000; % Sampling frequency (Hz)
t = 0:1/fs:1; % Time vector from 0 to 1 second
A = 1; % Amplitude of the signal
% Generate the 0 Hz signal (constant value)
signal = A * ones(size(t)); % A constant signal
% Calculate the FFT of the signal
N = length(signal);
Y = fft(signal);
f_freq = (0:N-1) * (fs/N); % Frequency vector
% Plotting
figure;
% Time Domain Plot
subplot(2, 1, 1);
plot(t, signal, 'k', 'LineWidth', 1.5);
title('Time Domain of 0 Hz Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Frequency Domain Plot
subplot(2, 1, 2);
plot(f_freq(1:N/2), abs(Y(1:N/2))/N);
title('Frequency Domain of 0 Hz Signal');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');
xlim([0 fs/2]); % Limit x-axis to half the sampling frequency
grid on;

MATLAB Code for Time Domain and Frequency Domain Sine Waves

for f= 8 Hz

% Parameters
fs = 1000; % Sampling frequency (Hz)
t = 0:1/fs:1; % Time vector from 0 to 1 second
A = 1; % Amplitude of the sine wave
% Generate the 8 Hz sine wave
frequency = 8; % Frequency of the sine wave (8 Hz)
signal = A * sin(2 * pi * frequency * t); % Sine wave
% Calculate the FFT of the signal
N = length(signal);
Y = fft(signal);
f_freq = (0:N-1) * (fs/N); % Frequency vector
% Plotting
figure;
% Time Domain Plot
subplot(2, 1, 1);
plot(t, signal, 'k', 'LineWidth', 1.5);
title('Time Domain of 8 Hz Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Frequency Domain Plot
subplot(2, 1, 2);
plot(f_freq(1:N/2), abs(Y(1:N/2))/N);
title('Frequency Domain of 8 Hz Sine Wave');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');
xlim([0 fs/2]); % Limit x-axis to half the sampling frequency
grid on;

Simple MATLAB Code for Time Domain and Frequency Domain Sine Waves for

f= 16 Hz

% Parameters
fs = 1000; % Sampling frequency (Hz)
t = 0:1/fs:1; % Time vector from 0 to 1 second
A = 1; % Amplitude of the sine wave
% Generate the 16 Hz sine wave
frequency = 16; % Frequency of the sine wave (16 Hz)
signal = A * sin(2 * pi * frequency * t); % Sine wave
% Calculate the FFT of the signal
N = length(signal);
Y = fft(signal);
f_freq = (0:N-1) * (fs/N); % Frequency vector
% Plotting
figure;
% Time Domain Plot
subplot(2, 1, 1);
plot(t, signal, 'k', 'LineWidth', 1.5);
title('Time Domain of 16 Hz Sine Wave');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Frequency Domain Plot
subplot(2, 1, 2);
plot(f_freq(1:N/2), abs(Y(1:N/2))/N);
title('Frequency Domain of 16 Hz Sine Wave');
xlabel('Frequency (Hz)');
ylabel('|Y(f)|');
xlim([0 fs/2]); % Limit x-axis to half the sampling frequency
grid on;

Explanation

1. Parameters:
o fs: The sampling frequency is set to 1000 Hz.
o t: A time vector ranging from 0 to 1 second.
o A: The amplitude of the sine wave.
2. Signal Generation:
o A sine wave with a frequency of 16 Hz is generated using the sine function.
3. FFT Calculation:
o The Fast Fourier Transform (FFT) of the signal is computed to analyze its frequency
components.

4. Plotting:
o Time Domain: The first subplot displays the 16 Hz sine wave over time.
o Frequency Domain: The second subplot shows the frequency spectrum, which should
have a peak at 16 Hz.

MATLAB code of the bandwidth of periodic signals: 100, 200, 300, 400,

500, 600, 700, 800 Hz where BW = Fh – Fl

To compute the bandwidth of a periodic signal composed of frequencies 100 Hz, 200 Hz, 300 Hz, 400 Hz,
500 Hz, 600 Hz, 700 Hz, and 800 Hz using the formula BW=Fh−FlBW = F_h - F_lBW=Fh−Fl (where
FhF_hFh is the highest frequency component and FlF_lFl is the lowest), you can use the following
MATLAB code.
% Parameters
Fs = 2000; % Sampling frequency (2 kHz)
t = 0:1/Fs:1; % Time vector (1 second duration)
% Define frequencies
frequencies = [100, 200, 300, 400, 500, 600, 700, 800]; % Frequencies in Hz
% Create periodic composite signal
periodic_signal = sum(sin(2 * pi * frequencies' * t), 1);
% Calculate the bandwidth
F_l = min(frequencies); % Lowest frequency
F_h = max(frequencies); % Highest frequency
BW = F_h - F_l; % Bandwidth calculation
% Display results
fprintf('Bandwidth of periodic composite signal: %.2f Hzn', BW);
     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.