|
| 1 | +from rsf.proj import * |
| 2 | + |
| 3 | +""" |
| 4 | +This SCons script aims to reproduce Fig 1.1-7 to Fig 1.1-10, presented in Öz Yilmaz' Seismic Data Analysis, Vol 1. |
| 5 | +
|
| 6 | +The first three frames show sinusoidal functions with different frequencies: |
| 7 | + * 1: Frequency - 25 Hz |
| 8 | + * 2: Frequency - 75 Hz |
| 9 | + * 3: Frequency - 150 Hz |
| 10 | +
|
| 11 | +The fourth frame shows the composition of two sinusoids with frequencies: |
| 12 | + * 1: Frequency - 12.5 Hz |
| 13 | + * 2: Frequency - 75 Hz |
| 14 | +
|
| 15 | +All the functions above are sampled at three different rates: |
| 16 | + * 1: Sampling rate - 2 ms |
| 17 | + * 2: Sampling rate - 4 ms |
| 18 | + * 3: Sampling rate - 8 ms |
| 19 | +
|
| 20 | +The original figures exemplified aliasing: the consequence of sampling below the Nyquist rate. |
| 21 | +
|
| 22 | +*For some reason, the original figures appear to be "smoother" than they should. |
| 23 | +""" |
| 24 | + |
| 25 | +# Sinusoid parameters |
| 26 | +frequency = [25,75,150] # frequencies in Hz |
| 27 | +samplingrate = [0.002,0.004,0.008] # sampling rates in seconds |
| 28 | + |
| 29 | +for i in range(3): |
| 30 | + for j in range(3): |
| 31 | + jrate = samplingrate[j] |
| 32 | + # Produce sinusoid |
| 33 | + Flow('sinusoid%g-%gms'%(i+1,jrate*1000),None, |
| 34 | + ''' |
| 35 | + math n1=%g d1=%f o1=0 |
| 36 | + output="sin(x1*%f*2*(2*asin(1)))" | |
| 37 | + put label1="Time" unit1="s" |
| 38 | + '''%(1/jrate+1,jrate,frequency[i])) # pi is defined as 2*asin(1) |
| 39 | + Plot('sinusoid%g-%gms'%(i+1,jrate*1000), |
| 40 | + 'graph title="Sinusoid %g, sampling rate = %g ms" screenratio=0.75 min1=0 max1=1 min2=-1 max2=1'%(i+1,jrate*1000)) |
| 41 | + Result('sinusoid%g-%gms'%(i+1,jrate*1000), |
| 42 | + 'graph title="Sinusoid %g, sampling rate = %g ms" screenratio=0.5 min1=0 max1=1 min2=-1 max2=1'%(i+1,jrate*1000)) |
| 43 | + |
| 44 | + # Recovering Amplitude spectra through FFT |
| 45 | + ## Fourier transform |
| 46 | + fftwindow = int(0.4/jrate) # we window N full cycles |
| 47 | + Flow('fourier%g-%gms'%(i+1,jrate*1000),'sinusoid%g-%gms'%(i+1,jrate*1000),'window n1=%g | fft1'%fftwindow) |
| 48 | + |
| 49 | + ## Amplitude spectra |
| 50 | + Flow('fampspectra%g-%gms'%(i+1,jrate*1000),'fourier%g-%gms'%(i+1,jrate*1000), |
| 51 | + ''' |
| 52 | + math output="2*abs(input)/%g" | real | put label1="Frequency" unit1="Hz" |
| 53 | + '''%fftwindow) # normalized by 2/N |
| 54 | + Plot('fampspectra%g-%gms'%(i+1,jrate*1000), |
| 55 | + 'graph title="Amplitude Spectrum" screenratio=1 min1=0 max1=250 min2=0 max2=1') |
| 56 | + Result('fampspectra%g-%gms'%(i+1,jrate*1000), |
| 57 | + 'graph title="Amplitude Spectrum %g" screenratio=1 min1=0 max1=250 min2=0 max2=1'%(i+1)) |
| 58 | + |
| 59 | + ## Plot side by side |
| 60 | + Plot('subplot%g-%gms'%(i+1,jrate*1000),'sinusoid%g-%gms fampspectra%g-%gms'%(i+1,jrate*1000,i+1,jrate*1000), |
| 61 | + 'SideBySideAniso') |
| 62 | + Result('subplot%g-%gms'%(i+1,jrate*1000),'sinusoid%g-%gms fampspectra%g-%gms'%(i+1,jrate*1000,i+1,jrate*1000), |
| 63 | + 'SideBySideAniso') |
| 64 | + |
| 65 | + Plot('frame%g'%(i+1),['subplot%g-%gms'%(i+1,samplingrate[j]*1000) for j in range(3)],'OverUnderAniso') |
| 66 | + Result('frame%g'%(i+1),['subplot%g-%gms'%(i+1,samplingrate[j]*1000) for j in range(3)],'OverUnderAniso') |
| 67 | + |
| 68 | +# Composite signal |
| 69 | +for j in range(3): |
| 70 | + jrate = samplingrate[j] |
| 71 | + # Produce sinusoid |
| 72 | + Flow('sinusoid4-%gms'%(jrate*1000),None, |
| 73 | + ''' |
| 74 | + math n1=%g d1=%f o1=0 |
| 75 | + output="sin(x1*12.5*2*(2*asin(1)))+sin(x1*75*2*(2*asin(1)))" | |
| 76 | + put label1="Time" unit1="s" |
| 77 | + '''%(1/jrate+1,jrate)) # pi is defined as 2*asin(1) |
| 78 | + Plot('sinusoid4-%gms'%(jrate*1000), |
| 79 | + 'graph title="Sinusoid %g, sampling rate = %g ms" screenratio=0.75 min1=0 max1=1 min2=-1 max2=1'%(i+1,jrate*1000)) |
| 80 | + Result('sinusoid4-%gms'%(jrate*1000), |
| 81 | + 'graph title="Sinusoid %g, sampling rate = %g ms" screenratio=0.5 min1=0 max1=1 min2=-1 max2=1'%(i+1,jrate*1000)) |
| 82 | + |
| 83 | + # Recovering Amplitude spectrum through FFT |
| 84 | + ## Fourier transform |
| 85 | + fftwindow = int(0.4/jrate) # we window N full cycles |
| 86 | + Flow('fourier4-%gms'%(jrate*1000),'sinusoid4-%gms'%(jrate*1000),'window n1=%g | fft1'%fftwindow) |
| 87 | + |
| 88 | + ## Amplitude spectrum |
| 89 | + Flow('fampspectra4-%gms'%(jrate*1000),'fourier4-%gms'%(jrate*1000), |
| 90 | + ''' |
| 91 | + math output="2*abs(input)/%g" | real | put label1="Frequency" unit1="Hz" |
| 92 | + '''%fftwindow) # normalized by 2/N |
| 93 | + Plot('fampspectra4-%gms'%(jrate*1000), |
| 94 | + 'graph title="Amplitude Spectrum" screenratio=1 min1=0 max1=250 min2=0 max2=1') |
| 95 | + Result('fampspectra4-%gms'%(jrate*1000), |
| 96 | + 'graph title="Amplitude Spectrum %g" screenratio=1 min1=0 max1=250 min2=0 max2=1'%(i+1)) |
| 97 | + |
| 98 | + ## Plot side by side |
| 99 | + Plot('subplot4-%gms'%(jrate*1000),'sinusoid4-%gms fampspectra4-%gms'%(jrate*1000,jrate*1000), |
| 100 | + 'SideBySideAniso') |
| 101 | + Result('subplot4-%gms'%(jrate*1000),'sinusoid4-%gms fampspectra4-%gms'%(jrate*1000,jrate*1000), |
| 102 | + 'SideBySideAniso') |
| 103 | + |
| 104 | +Plot('frame4',['subplot4-%gms'%(samplingrate[j]*1000) for j in range(3)],'OverUnderAniso') |
| 105 | +Result('frame4',['subplot4-%gms'%(samplingrate[j]*1000) for j in range(3)],'OverUnderAniso') |
| 106 | + |
| 107 | +End() |
0 commit comments