Beruflich Dokumente
Kultur Dokumente
% Exp. 1
% Generation and plotting of discrete-time sinusoids
?
% s2 plotted as discrete time signal
subplot (223); % 3rd graphic window is selected
stem(t,s2); % plot of discrete samples
axis ([0 0.1 -0.6 0.6]); xlabel('time in second'); ylabel('amplitude');
title('discrete time signal using sin function, F=50Hz, Fs=1000 Hz')
% Verifying two discreet time sinusoids are same if frequencies are F and (F+Fs)
[s4, t4] = mysin (0.5, 1050, 1000, 0.1); % A=0.5, F=1050. Fs=1000, T=0.1
subplot (224); stem(t4, s4); axis ([0 0.1 -0.6 0.6]);
xlabel('time in second'); ylabel('amplitude');
title('A=0.5, F=1050 Hz, Fs=1000 Hz, T=0.1 sec')
Anything wrong anywhere?
% Here we write a function mysquare.m that reconstructs a square wave from its
% Fourier coefficients. T0 = Time period of square wave, n= No. of harmonics used
function [s,t]=mysquare(T0,n)
s=0;
for i=1:n
j=2*(i-1)+1; % Only odd harmonics of sin function are present
s=s+(4*sin(2*pi*F0*j*t))/(pi*j); % Weighted sum from Fourier expansion
end
% Exp. 3
% Use function mysquare.m to see addition of weighted sinusoids give a square wave
Added after class discussion: If noise is relatively more, the corrupted signal
will be more noise like. It is possible to calibrate signal-to-noise ratio for
simulation study such as, SNR of 30 dB, 20 dB, 10 dB, 0 dB. How it can be done
was shared with a few after class hour. It will be taken up again in the class.
The DSP Lab. will have
Added after class discussion: From your previous course, you already have
some idea of DFT which generates frequency samples that can be
manipulated using digital hardware. FFT (Fast Fourier Transform) is a faster
way of calculating DFT where the speed up factor is the highest of number of
DFT points is in integer power of 2. We shall discuss it in the class in detail.
NFFT = 2^nextpow2(L);
% Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
Added after class discussion: The signal y is the signal of slide no. 13 of this
presentation. You might have seen from time domain plot there that the signal
was very noisy. The same is reflected here in the plot. The 120 Hz sinusoid
there had higher amplitude (1.0) than 50 Hz sinusoid (0.7). The same is
reflected here and the difference is due to in-frequency noise. Note how
frequency axis tics are arrived at.
>> help fftshift
For matrices, fftshift(X) swaps the first quadrant with the third and
the second quadrant with the fourth.
Simulation based lab. experiment
>> help square
square Square wave generation.
square(T) generates a square wave with period 2*Pi for the MATLAB
elements of time vector T. square(T) is like SIN(T), only built-in
command.
it creates a square wave with peaks of +1 to -1 instead of
a sine wave.