In: Electrical Engineering
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');
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.