Matlab
Matlab
Matlab
1; harm1 = cos(2*pi*10*t); harm2 = 2*cos(2*pi*20*t+45/180*pi); signa2 = harm1 + harm2; harm3 = 1*cos(2*pi*30*t+60/180*pi); signa3 = signa2 + harm3; figure(1) subplot(2,3,1); plot(t, harm1) subplot(2,3,2); plot(t, harm2) subplot(2,3,3); plot(t, harm3) subplot(2,3,4); plot(t, signa2) subplot(2,3,5); plot(t, signa3)
From the graph, we can see that only 3 graph is be functioning since the source code of the program told so. As for the first graph, we want to observe how the first harmonic looks like. This is also same with second and the third picture. The number of sinusoidal wave will change according to the number of harmonic we want. As for instance, if we want first harmonic only, we will have picture number one as a result.
Adding an harmonic to the signal y(t): f0=10; t = 0:0.001:0.1; harm1 = cos(2*pi*10*t); harm2 = 2*cos(2*pi*20*t+45/180*pi); signa2 = harm1 + harm2; harm3 = 1*cos(2*pi*30*t+60/180*pi); signa3 = signa2 + harm3; harm4 = 1.5+cos(2*pi*40*t-120/180*pi); signa4 = harm3 + harm4; figure(1) subplot(2,3,1); plot(t, harm1) subplot(2,3,2); plot(t, harm2) subplot(2,3,3); plot(t, harm3) subplot(2,3,4); plot(t, harm4) subplot(2,3,5); plot(t, signa2) subplot(2,3,6); plot(t, signa3)
The next task is adding the forth harmonic into the figure. While observing the source code, the forth harmonic is equal to cosine function added with signal no 3. The function of forth harmonic is
still the same with previous one. As we say the graph is in forth harmonic, we can see four repeatedly sinusoidal wave as shown. 2) Magnitude Spectrum of a Square Wave a) % Program to give partial Fourier sums of an % odd square wave 0f 2Vpp amplitude n_max = input('Enter vector of highest harmonic values desired (odd):'); f = 1; N = n_max; %length (n_max) t = 0:0.002:1; omega_0 = 2*pi*f; x = zeros(size(t)); n = 1:1:N; b_n = zeros(size(n)); fori=1:(N+1)/2; k = 2*i-1; b_n(k) = 4/(pi*k); % This part is for plotting the Magnitude Spectrum figure(1) subplot ((N+1)/2,1,i); stem(b_n), xlabel('Integer Multiple of Fundamental Frequency') ylabel ('Amplitude'),grid; x = x+b_n(k)*sin(omega_0*k*t); % This part is for plotting the partial Fourier sum figure(2) subplot ((N+1)/2,1,i), plot(t,x), xlabel ('t'), ylabel ('partial sum'); axis ([0 1 -1.5 1.5]), text(0.05, -0.5,['max.har.=',num2str(k)]); grid; end Enter vector of highest harmonic values desired (odd):1
And for this one, there were first, third and fifth harmonic.
Last but not least, these figure shows the combination of first, third, fifth and seventh harmonic. As you can see, when observing each of the graph, we can make a conclusion that the number of sinusoidal wave is directly proportional to the number of harmonic given. However, in this case, we only have odd harmonic since all the graphs were odd function.
b) % Program to give partial Fourier sums of an % triangular wave of 2Vpp amplitude n_max = input('Enter vector of highest harmonic values desired (odd):'); f = 1; N = n_max; %length (n_max) t = 0:0.002:1; omega_0 = 2*pi*f; x = zeros(size(t)); n = 1:1:N; a_n = zeros(size(n)); fori=1:(N+1)/2; k = 2*i-1; a_n(k) = -8/(pi^2*k*k); % This part is for plotting the Magnitude Spectrum figure(1) subplot ((N+1)/2,1,i); stem(a_n), xlabel('Integer Multiple of Fundamental Frequency') ylabel ('Amplitude'),grid; x = x+a_n(k)*cos(omega_0*k*t); % This part is for plotting the partial Fourier sum figure(2) subplot ((N+1)/2,1,i), plot(t,x), xlabel ('t'), ylabel ('partial sum'); axis ([0 1 -1.5 1.5]), text(0.05, -0.5,['max.har.=',num2str(k)]); grid; end Enter vector of highest harmonic values desired (odd):1
These were the first and third harmonic for the triangular wave.
As you can see, the graphs show the first, third and fifth harmonic of triangular wave. The fifth harmonic started to shows the behaviour of triangular wave.
At the seventh harmonic, we can see the perfect triangular wave. As you know, triangular wave also included in sinusoidal wave. Different with the previous sinusoidal wave, the number of odd harmonic will shows the perfect behaviour as the number of the odd harmonic increases.
Sampling Example n = 0:20; x = 0.8.^n; stem(n,x,'filled','b','LineWidth',2) grid xlabel('Time Index (n)') ylabel('x[n]')
This graph shows the result of sampling with n = 1-20, with the function x = 0.8 ^ value of n. As you can see, the graph behaves like negative exponential, since when the value of n increases, x decreases.
With the same value of n but different function of x (at this time, x = cos (2*pi*60/240*n). Then, the sampling rate is = 240. We can see the graph only digitalized the function of x with least effect on sinusoidal wave (since the number of sampling is not so big).
At this time, we use the sampling rate = 480, bigger compared to the previous one. As you can see, the graph shows the digitalized sinusoidal wave with more proper behaviour.
Lastly, we are using sampling rate = 1000. Compared to the first and second graphs before, this graph shows more perfect digitalized sinusoidal wave. As a conclusion, as the sampling rate increases, the more perfect digitalized sinusoidal wave we could get.
Sampling and Aliasing Extra t1 = [0 .1 .2 .3]; t2 = 0:0.1:0.3; t3 = linspace(0, 0.3, 4); T = [t1' t2' t3']; X = sin(T) Results: X = 0 0.0998 0.1987 0.2955 0 0.0998 0.1987 0.2955 0 0.0998 0.1987 0.2955
Sampling Signals Fs = 100; N = 1000; stoptime = 9.99; t1 = (0:N-1)/Fs:stoptime; x1 = sin(2*pi*2*t1); x2 = sin(2*pi*3*t2); plot(x1) figure, plot(x2)
Aliasing t = 0:0.001:2; xa = sin(2*pi*5*t); plot(t, xa) holdon fs = 15; ts = 0:1/fs:2; xs1 = sin(2*pi*5*ts); plot(ts, xs1, 'ro-') fs = 7.5; ts = 0:1/fs:2; xs2 = sin(2*pi*5*ts); plot(ts,xs2,'ro-') holdoff
Aliasing effect can be defined as an effect that causes different signals to become indistinguishable (or aliases of one another) when sampled. In this figure, the red one graph shows the aliasing effect, since it decrease the resolution of the original graph (that is, blue). We can decrease or repair this effect by set the sampling frequency greater than two times the maximum frequency of the signal to be sampled. This satisfies the Nyquist theorem, where fs > 2fm (fm is Nyquist frequency).