Question

In: Electrical Engineering

explain this Matlab code and finish its last line. %% clear all; clc; %% % Données...

explain this Matlab code and finish its last line.

%%
clear all;
clc;
%%
% Données de départ
NbrEchParPer=128*2;
NbrPer=16; % Ensuite essayer avec 512
T=1e-3;
% calcul préliminaire
fs=NbrEchParPer/(T);
NbrEch=NbrEchParPer*NbrPer;
%Axes des temps et des élongations
t=[0:NbrEch-1]./fs;
x=repmat([ones(1,NbrEchParPer/2),zeros(1,NbrEchParPer/2)]
,1,NbrPer);
%représentation des signaux temporels
fig1=figure(1);clf;
subplot(4,1,[1 2],'Parent',fig1,'Color',[0 0 0]);
hold on;
plot(t,x,'.b');
plot(t,x,'-g');
ylim([-1,2]);
%%
%Calcul de la FFT
X=fft(x);
%Axe des fréquences
df=fs/((NbrEch-mod(NbrEch,2))/2);
f=[0:NbrEch-1].*df;
%représentation du spectre
subplot(4,1,3,'Parent',fig1,'Color',[0 0 0]);
hold on;
plot(f,abs(X),'m');
subplot(4,1,4,'Parent',fig1,'Color',[0 0 0]);
hold on;
plot(f,abs(X)XXXXXXXXXXXX,'m');

Solutions

Expert Solution

modified matlab code is given below in bold letters.

clc;
close all;
clear all;

clear all;
clc;
%%
% Données de départ
NbrEchParPer=128*2;
NbrPer=16; % Ensuite essayer avec 512
T=1e-3;
% calcul préliminaire
fs=NbrEchParPer/(T);
NbrEch=NbrEchParPer*NbrPer;
%Axes des temps et des élongations
t=[0:NbrEch-1]./fs;
x=repmat([ones(1,NbrEchParPer/2),zeros(1,NbrEchParPer/2)],1,NbrPer);
%représentation des signaux temporels
fig1=figure(1);clf;
subplot(4,1,[1 2],'Parent',fig1,'Color',[0 0 0]);
hold on;
plot(t,x,'.b');
plot(t,x,'-g');
ylim([-1,2]);
%%
% %Calcul de la FFT

% Finding FFT of x(t)
N = nextpow2(length(x));
X = fftshift(fft(x,2^N));

X = X / length(x);
k = -(length(X)-1)/2:1:length(X)/2;
f = k/length(X) * fs;
subplot(4,1,[3 4],'Parent',fig1,'Color',[0 0 0]);
plot(f,abs(X));grid;
xlabel('Frequency in Hz');
ylabel('Amplitude');
title('Double sided Magnitude spectrum of x(t)');


the time and frequency plots are given below.

From the above plot it is observed that the signal and the frequency response of the signal are shown. The signal at DC component of 0.5 and and the fundamental frequency component (1000 Hz) has the magnitude of -.3 approximately. As the frequency increases, the magnitude keeps dropping until it reaches zero.


Related Solutions

Using this sample matlab code: clear all; clc A= ????????; B= ????????; AUG=[A B]; for L=1:size(A,2)...
Using this sample matlab code: clear all; clc A= ????????; B= ????????; AUG=[A B]; for L=1:size(A,2) %Pivoting starts for k=L:size(AUG,1) for m=k+1:size(AUG,1) if abs(AUG(k,L))<abs(AUG(m,L)) temp=AUG(m,:); AUG(m,:)=?????????; AUG(k,:)=?????????; end end end %Pivoting ends %Gauss Elimination starts for k=L+1:size(AUG,1) AUG(k,:)= ????????????????????????????; AA=AUG(:,1:size(A,2)) BB=AUG(:,size(A,2)+1:end) end %Gauss Elimination ends end b)Write a MATLAB M-file which performs gauss elimination without pivoting step by step and shows the coefficient matrix in each step. Using cond (X, P) calculate the condition number of the final step coefficient...
Fix the bugs in this matlab program so that it solves. clear clf clc time =...
Fix the bugs in this matlab program so that it solves. clear clf clc time = linspace(0, 5, 100); m = 1; k = 100; c = 1; delta = 0.2; [period, response] = Exmp(m, k, c, delta, time); plot(time, response) grid %Exmp(m, k, c, delta, time) % %________________________________________ function [T, x] = Exmp(m, k, c, delta, t) omega = sqrt(k/m); cC = 2*m*omega; if c>= cC disp('Not an underdamped system') T = 0; x = 0; return; end %...
please let me know reference of this MATLAB code. please explain this code line by line....
please let me know reference of this MATLAB code. please explain this code line by line. . . N=256; %% sampling number n=linspace(0,1,N); fs=1/(n(2)-n(1)); x=5*(sin((2*pi*10*n))); %% create signal N=length(x); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(211) plot(f,fftshift(abs(fft(x)))); title('|G(f)|');grid; xlabel('frequency'); ylabel('|G(f)|'); %Zero padding xx=[zeros(1,128) x zeros(1,128)]; N=length(xx); f=[-fs/2:fs/N:fs/2-fs/N]; subplot(212) plot(f,fftshift(abs(fft(xx)))); title('|Gz(f)|');grid; xlabel('frequency'); ylabel('|Gz(f)|');
I explain the following in detail, with a clear line, and a clear, close and tidy...
I explain the following in detail, with a clear line, and a clear, close and tidy illustration: executive management For engineering projects (Project Management), Parties Engineering project, pillars, engineering project, pillars Engineering project, engineering project phases, engineering project management, functions and tasks, project manager, project resource management, project planning, estimation Project cost, project time control, project financial management
Write a MATLAB code for importing an image and then being able to find all the...
Write a MATLAB code for importing an image and then being able to find all the coordinates that would draw that image on a plot column by column and row by row with a continuous line.
using matlab Show the two formals or figures in time domin and z dominclc clear all...
using matlab Show the two formals or figures in time domin and z dominclc clear all b=[1,-4,5] a=[1,-6,11,-6] [R,P,C]=residuez(b,a) Ez=tf(b,a,1,'variable','z') zplane(b,a)
can someone finish and check my code on main. cpp? Its not working for me even...
can someone finish and check my code on main. cpp? Its not working for me even though im sure my code make sense is it possible to output each function to show they work. this is supposed to be a vector class library made from allocated memory i have included templated functions in the class file to help create the rest of the functions. Thank you so much note: i did not include main.cpp because it  was empty- im hoping someone...
Can someone please write clear and concise comments explaining what each line of code is doing...
Can someone please write clear and concise comments explaining what each line of code is doing for this program in C. I just need help tracing the program and understand what its doing. Thanks #include <stdio.h> #include<stdlib.h> #include<unistd.h> #include<sys/wait.h> int join(char *com1[], char *com2[]) {    int p[2], status;    switch (fork()) {        case -1:            perror("1st fork call in join");            exit(3);        case 0:            break;        default:...
Can someone please add clear and concise comments thoroughly explaining each line of code below. Just...
Can someone please add clear and concise comments thoroughly explaining each line of code below. Just need help understanding the code, don't need to modify it. The purpose of the code is to count the frequency of words in a text file, and return the most frequent word with its count. It uses two algorithms: Algorithm 1 is based on the data structure LinkedList. It maintains a list for word frequencies. The algorithm runs by scanning every token in the...
Ironwood Company manufactures a variety of sunglasses. Production information for its most popular line, the Clear...
Ironwood Company manufactures a variety of sunglasses. Production information for its most popular line, the Clear Vista (CV), follows: Per Unit Sales price $ 48.50 Direct materials 17.00 Direct labor 10.00 Variable manufacturing overhead 3.00 Fixed manufacturing overhead 5.00 Total manufacturing cost $ 35.00 Suppose that Ironwood has been approached about producing a special order for 2,500 units of custom CV sunglasses for a new semiprofessional volleyball league. All units in the special order would be produced in the league’s...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT