#Script file: t5_2.py # #Purpose: Demonstrate noise filtering by averaging # # #Record of the revisions: # Date Programmer Description of change # ==== ========== ===================== # xxx yyy ddd Reformatted code # #Define variables: # v - the amplitude of the noise # %TODO: complete the rest of data dictionary # # # from pylab import * f = 100.; #frequency of the signal in sec fs = 5000.; #sampling rate in 1/sec # plot 3 cycles t = arange(0,3./f, 1./fs); #total time = 3 period x = sin(2*pi*f*t); #original signal v = 0.01; #amplitude of the noise r = sqrt(v)*randn(len(t)); #noise # Xw = x + r; #signal plus noise (filter input) # y = zeros([size(Xw)]); # for n in arange(2,size(Xw)) : # y[n] = ( Xw[n] + Xw[n-1] + Xw[n-2] )/3; #y[n] is the filtered signal # # plot(y); #plot the filtered signal hold; #plot the original signal over top the plot(x,'r'); #filtered signal to see the difference