Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q1. Write a Matlab script that generates a signal with three frequencies and use

ID: 1766547 • Letter: Q

Question

Q1. Write a Matlab script that generates a signal with three frequencies and use the fast fourier transform (fft) to find determine the frequency content of the signal. The frequency axis must be properly scaled to show the actual frequencies in the signal. The parameters, functions needed, and tasks are Frequencies: f1 = 5, f2 15 and f3 Sample rate: fs 100 Hz Number of time ticks. 100 time ticks at T-1 (same for all frequencies) Suggestion: create the signal at each frequency and add to get composite signal with all frequencies Example to generate a signal as frequency f : s1 = sin(2*pi* f1 *t); where t is the 100 element time tick vector referred to above. (Use sine function for eac frequency component.) Do a 512 point fft, so if the signal name was s, then the code to accomplish the 512 point fft if we assign N- 512 is: S- fft(s.N). S is vector of complex number in the S in the frequency domain. To graphical view S. one must plot its magnitude To display S over the appropriate frequency range, make a vector of frequencies as follows: f= (0 : N/2-1 )/(N/2)*(fs/2); This vector provides the x-axis to view s Make a2x 1 subplot 30 Hz . . . . The first plot is the composite time signal consisting of the three frequencies in the time domain. Give appropriate title and label x and y axes o o The second shows the fft results in the frequency domain. It must show the three frequency components centered at 5, 15 and 30 Hz. Give appropriate title and label x and v axes

Explanation / Answer

% Start of the code
clc
clear variables
close all
fs = 100; % Sampling rate   
Ts = 1/fs; % Sampling period
L = 100; % Number of ticks
t = (0:L-1)*Ts; % Time vector
f1 = 5; % First frequency
f2 = 15; % Second frequency
f3 = 30; % Third frequency
s1 = sin(2*pi*f1*t); % First signal
s2 = sin(2*pi*f2*t); % Second signal
s3 = sin(2*pi*f3*t); % Third signal
s = s1+s2+s3; % Sum of all signals
N = 512;
S = fft(s,N);

% Compute the two sided spectrum
P2 = abs(S/L);

% Compute the single sided spectrum based on two sided spectrum.
P1 = P2(1:N/2);
P1(2:end-1) = 2*P1(2:end-1);

f = (0:N/2-1)/(N/2)*(fs/2); % Vector of frequencies

subplot(2,1,1)
plot(t,s1,t,s2,t,s3,t,s)
title('Singals')
xlabel('time')
ylabel('Amplitude')
legend('First signal','Second signal','Third signal','Combined signal')
grid on

subplot(2,1,2)
plot(f,P1)
title('Single-Sided Amplitude Spectrum of S')
xlabel('f (Hz)')
ylabel('Amplitude')
grid on
% End of the code