Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can you please explain in words how does the loop works. Note the code is in Matlab language. %% code reset % close all figures

can you please explain in words how does the loop works. Note the code is in Matlab language.
%% code reset
% close all figures
close all
% clearing the work space
clear
% clearing command window
clc
%% frequency
freq = [10, 15, 20, 40, 60, 300];
%% plot
tiledlayout(3,2);
for i = 1:length(freq)
fs = freq(i);
ts = 1/fs; % sampling period
t_s = 0:ts:10-ts; % values of the time vector (x-axis)
x_s = 2+6*cos(2*pi*10*t_s)+cos(2*pi*20*t_s); % Original signal (analog)
nexttile;
plot(t_s, x_s);
title(['fs = ', num2str(fs),' Hz']);
axis([0 0.5 -4 10]);
xlabel('time (s)');
ylabel('x(t)');
end
%% stem
for i = 1:length(freq)
fs = freq(i);
ts = 1/fs;
t_s = 0:ts:10-ts;
x_s = 2+6*cos(2*pi*10*t_s)+cos(2*pi*20*t_s);
nexttile;
stem(t_s, x_s);
title(['fs = ', num2str(fs),' Hz']);
axis([0 0.5 -5 11]);
xlabel('Samples (n)');
ylabel('x(n)');
end
%% power spectrum plot (pwelch)
tiledlayout(3,2)
for i = 1:length(freq)
fs = freq(i);
ts = 1/fs;
t_s = 0:ts:10-ts;
x_s = 2+6*cos(2*pi*10*t_s)+cos(2*pi*20*t_s);
nexttile;
pwelch(x_s, [], [], [], fs)
title(['fs = ', num2str(fs),' Hz']);
end

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions