Question

In: Electrical Engineering

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)|');

Solutions

Expert Solution

This code is see the effect of padding zeros in the signal. It increases the Resolution of the fft.

I have added comments to each line of code for your understanding

N=256; %The number of samples taken for x(n)

n=linspace(0,1,N); %creating the values of points @ where to sample the function x(n)

fs=1/(n(2)-n(1));   %sampling rate

x=5*(sin((2*pi*10*n))); %% create signal


N=length(x);    %length of the signal is equal to the number of samples taken

f=[-fs/2:fs/N:fs/2-fs/N];   %as we sample a signal with fs, We can only see the spectrum of it in the range -fs/2 to fs/2

subplot(211)    %making a plot of 2 images in one and usign the first image

plot(f,fftshift(abs(fft(x)))); %ploting the fft of the signal

title('|G(f)|');grid;

xlabel('frequency');

ylabel('|G(f)|');

%Zero padding

xx=[zeros(1,128) x zeros(1,128)];   %padding zeros at the front and back of the signal

N=length(xx);   %defining new lenghth of the signal

f=[-fs/2:fs/N:fs/2-fs/N];   %%as we sample a signal with fs, We can only see the spectrum of it in the range -fs/2 to fs/2

subplot(212) %making a plot of 2 images in one and usign the second image


plot(f,fftshift(abs(fft(xx)))); %ploting the fft of the padded signal

title('|Gz(f)|');grid;

xlabel('frequency');

ylabel('|Gz(f)|');


As can be seen, plot 2 has more details on the graph than plot 1. This shows the increases resolution of the fft


Related Solutions

Please let me know how to make code sort. If you put sort (sort 1000 6...
Please let me know how to make code sort. If you put sort (sort 1000 6 5 4 3 2 1, not separate), you will get 1 2 3 4 5 6 1000. sort 50 300 27 5 5 27 50 300 public static void main (String[] args) {        Scanner scnr = new Scanner(System.in);        String a = "";            a = scnr.nextLine();            String[] b = imput.split(" ") if (b[0].equalsI("sort")) { }...
Below is the only information I received for these questions. Please let me know if there...
Below is the only information I received for these questions. Please let me know if there is any additional info you may need. Any questions will help Federal Taxation I Module 8: Comprehensive Tax Return Project Jared and Ashley have come to you for help filing their 2018 tax return. They are married on December 31, 2018 and are both age 40. They live with their three qualifying children, Nick, Betty, and Roger, who are 12, 14, and 17 years...
Please let me know about the material structure and properties of Solar energy devices.
Please let me know about the material structure and properties of Solar energy devices.
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');
Hello! Please let me know, thank you! You have a credit card with a balance of...
Hello! Please let me know, thank you! You have a credit card with a balance of $13,600 and an APR of 18 percent compounded monthly. You have been making monthly payments of $260 per month, but you have received a substantial raise and will increase your monthly payments to $335 per month. How many months quicker will you be able to pay off the account? 37.39 Months 36.05 Months 40.06 Months 11.71 Months 34.33 Months Thank you!
Please let me know what the formulas are to calculate the following: I am seeing different...
Please let me know what the formulas are to calculate the following: I am seeing different answers and I don't know which is correct. E 15–26 Lease concepts; finance/sales-type leases; guaranteed and unguaranteed residual value Each of the four independent situations below describes a sales-type lease in which annual lease payments of $100,000 are payable at the beginning of each year. Each is a finance lease for the lessee. Determine the following amounts at the beginning of the lease: A....
Please let me know which is true or false and reasons. 11. Both the linear momentum...
Please let me know which is true or false and reasons. 11. Both the linear momentum and the kinetic energy are conserved during elastic collisions. 12. Consider a rigid-body rotating freely around a fixed point. Its moment of inertia is generally a scalar value. 13. The parallel axis theorem implies that the moment of inertia of a rigid body is minimum around its center of mass. 14. For single point particle rotating freely around a fixed point, the direction of...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following...
This is a Matlab Exercise problem. Please create the Matlab code and figure for the following problem using problem specifications: Plot x vs y when y=sin(x), y=cos(x), y=sin (2*x), and y=2*sin(x) when x = 1:0.1:10. Use 2 by 2 subplot, sin(x) is in location 1, cos(x) is in location 2, sin(2*x) is in location 3 and 2*sin(x) is in location 4. The plot should have: (1) x label = ‘x value’, y label = ‘y value’, legend ‘y=sin(x)’,’ y=cos(x)’,’ y=sin...
Give me a working code in MATLAB for Crout Decomposition. The code must work totally fine...
Give me a working code in MATLAB for Crout Decomposition. The code must work totally fine and must break into 2 matrix L and U It must be in MATLAB The code used must use continue statement. If no continue statement is there in code it will be downvoted. Answer only if you know or else i will dislike badly
I have tried to answer the following questions. Please let me know if I missed one...
I have tried to answer the following questions. Please let me know if I missed one and why. 1) A light car and a heavy car are headed toward each other from opposite directions at the same speed. The ground is level. Which of the two will be harder to stop? the heavier car 2) Instead of stopping the cars, you jump out of the way. The two cars crash head-on. After the crash what do you see? The two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT