{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Lab 4: Frequency Analysis -- Calibration of the SDR frequency using GSM signals
\n", "\n", "\n", "\n", "\n", "### Michael Lustig \n", "\n", "#### Note: The instruction in this lab are now less detailed and require some thought and common sense with respect to choosing parameters and implementations. You should probably make sure you plot various temporary results (even though we may not request them) in order to guarentee your code is correct -- like the results of filter design or filtering....\n", "\n", "* The lab was inspired by the Kalibrate project by Joshua Lackey\n", "\n", "We hope you enjoy it!\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Import functions and libraries\n", "from __future__ import division\n", "import numpy as np, matplotlib.pyplot as plt, time, IPython.display\n", "from numpy import *\n", "from numpy.fft import *\n", "from matplotlib.pyplot import *\n", "from rtlsdr import RtlSdr\n", "from scipy import signal \n", "import pyaudio\n", "import time\n", "%matplotlib inline" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# function to compute average power spectrum\n", "def avgPS( x, N=256, fs=1):\n", " M = floor(len(x)/N)\n", " x_ = reshape(x[:M*N],(M,N)) * np.hamming(N)[None,:]\n", " X = np.fft.fftshift(np.fft.fft(x_,axis=1),axes=1)\n", " return r_[-N/2.0:N/2.0]/N*fs, mean(abs(X**2),axis=0)\n", "\n", "\n", "# Plot an image of the spectrogram y, with the axis labeled with time tl,\n", "# and frequency fl\n", "#\n", "# t_range -- time axis label, nt samples\n", "# f_range -- frequency axis label, nf samples\n", "# y -- spectrogram, nf by nt array\n", "# dbf -- Dynamic range of the spect\n", "\n", "def sg_plot( t_range, f_range, y, dbf = 60, fig = None) :\n", " eps = 10.0**(-dbf/20.0) # minimum signal\n", " \n", " # find maximum\n", " y_max = abs(y).max()\n", " \n", " # compute 20*log magnitude, scaled to the max\n", " y_log = 20.0 * np.log10( (abs( y ) / y_max)*(1-eps) + eps )\n", " \n", " # rescale image intensity to 256\n", " img = 256*(y_log + dbf)/dbf - 1\n", " \n", " \n", " fig=figure(figsize=(16,6));\n", " \n", " plt.imshow( np.flipud( 64.0*(y_log + dbf)/dbf ), extent= t_range + f_range ,cmap=plt.cm.gray, aspect='auto');\n", " plt.xlabel('Time, s');\n", " plt.ylabel('Frequency, Hz');\n", " plt.tight_layout();\n", " \n", "def myspectrogram_hann_ovlp(x, m, fs, fc, dbf = 60, fig = None):\n", " # Plot the spectrogram of x.\n", " # First take the original signal x and split it into blocks of length m\n", " \n", " # check if x is real\n", " isreal_bool = isreal(x).all()\n", " \n", " # pad x up to a multiple of m \n", " lx = len(x);\n", " nt = (lx + m - 1) // m\n", " x = append(x,zeros(-lx+nt*m))\n", " x = x.reshape((m//2,nt*2), order='F')\n", " x = concatenate((x,x),axis=0)\n", " x = x.reshape((m*nt*2,1),order='F')\n", " x = x[r_[m//2:len(x),ones(m//2)*(len(x)-1)].astype(int)].reshape((m,nt*2),order='F')\n", " \n", " \n", " xmw = x * hanning(m)[:,None];\n", " \n", " # frequency index\n", " t_range = [0.0, lx / fs]\n", " \n", " if isreal_bool:\n", " f_range = [ fc, fs / 2.0 + fc]\n", " xmf = fft(xmw,len(xmw),axis=0)\n", " fig = sg_plot(t_range, f_range, xmf[0:m//2,:], dbf, fig);\n", " else:\n", " f_range = [-fs / 2.0 + fc, fs / 2.0 + fc]\n", " xmf = abs(fftshift( fft( xmw ,len(xmw),axis=0), axes=0 ))\n", " fig = sg_plot(t_range, f_range, xmf, dbf, fig);\n", " \n", " return fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## RTL-SDR frequency Drift\n", "\n", "The rtl-sdr has has a 28.8MHz crystal oscillator, which sets the reference frequency used for demodulation on the tuner. The crystal is known to have poor quallity and therefore its frequency can drift considerably with temperature. The drift is measured in parts per millions (PPM) and can go up to $\\pm50$ PPM. The result of such a drift is that when you tune to a certain frequency, you will actually be tunning to an offset frequency. This offset is proportional to the center frequency, so the absolute frequency offset gets worse for higher frequencies. \n", "\n", "This sort of oscillator drifts are very common in other devices, such as your cellphone. The wireless industry has come up with many different techniques in which the clock, or the absolute frequency can be corrected for. In this lab we will use the GSM cellphone network to correct for the frequency drift of the rtl-sdr. GSM base stations are required to have an accurate clock within 0.05 ppm, so they are an excellent source of \"accurate\" signals. This is very much the first step that a GSM based phone would do in order to connect to the network. \n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before we start talking about how to use the GSM network to calibrate our rtl-sdr, let's learn a bit about the system\n", "\n", "\n", "## GSM : Global System for Mobile Communications\n", "\n", "This section is heavily based on \"GSM for dummies\" (http://www.pennula.de/datenarchiv/gsm-for-dummies.pdf)\n", "\n", "GSM is a popular digital cellular network. It is based on time-division-multiple-access (TDMA), which means that several phones use the same channel by time interleaving. GSM operates in several different carrier frequencies. In the US and Canada and number of other countries, the frequency bands are 850MHz and 1900MHz. In this lab we will use the 850MHz frequency band, since for the majority of you have the 820T tuner based rtl-sdrs, and the 1900MHz band is outside of its range (28-1700MHz). \n", "\n", "### Frequencies\n", "For the GSM-850 the band is separated into Uplink frequencies 824-849MHz and downlink frequencies 869-894MHz. The base station transmits on the downlink frequencies and mobile phones transmit on the uplink frequencies. GSM operates in duplex mode in which the phones and base stations receive and transmit at the same time. This is the reason that the uplink and the downlink are separated by 50MHz!. A channel number, also known as Absolute Radio Frequency Channel Number (ARFCN) is assigned a pair of uplink and downlink frequencies. There are 124 channels numbered 128-251 in the GSM-850 system. Each channel is allocated a bandwidth of 200KHz. For the downlink frequencies $f_N = 869.2+0.2*(ARFCN-128)$ MHz. \n", "\n", "### Modulation\n", "GSM uses Gaussian Minimum Shift Keying (GMSK in short) as a modulation method. We will cover this in part II of this lab. But, in short.... it is a binary digital Frequency Modulated scheme in which the phase between each bit period is continuouse. Bits are encoded as different frequencies separated by one-half the bit-rate. The modulation rate in GSM is $1625/6 \\approx 270.833$ kb/s. For more information read (http://en.wikipedia.org/wiki/Minimum-shift_keying) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Time-Division-Multiple-Acess\n", "\n", "GSM uses time-division to share a frequency channel among users. Each frequency is divided into blocks of time that are known as time-slots. There are 8 time-slots that are numberes TS0 - TS7. Each time-slot lasts about 576.9 $\\mu s$. Given the bit-rate above, a total of 156.25 bits can be transmitted in each slot. Each slot allocates 8.25 of it \"bits time\" as guard-time, split between the beginning and the end of each time-slot. This time is necessary to prevent overlapping between the different time slots. In addition, 3 bits on both sides of the time-slot do not contain any data and are there to allow for ramping the amplifiers up and down. \n", "\n", "Data transmitted within each time-slot is called a burst. There are several type of burts, with different purposes. We are interested in the so called \"frequency correction\" burst, which is a burst of a pure frequency tone at 1/4th the bitrate of GSM or (1625000 / 6) / 4 = 67708.3 Hz. \n", "\n", "\n", "
\"gsm\"
\n", "
Figure 1: TDMA frames and bursts
\n", "\n", "\n", "### Frame Structure, and Frequency Correction Channel (FCCH)\n", "GSM has hirarchial structure. At the bottom is the burst, which was discussed above, the next is a TDMA frame, which consists of several bursts and the next is a multi-frame, which consists of several frames. \n", "\n", "A TDMA frame consists of 8 time slots and is 4.615ms long. A control channel multi-frame is composed of 51 TDMA frames (numbered 0-50) and is 235.4ms long. A base station transmits a frequency correction burst in regular positions. The frequency correction channel repeats every 51 frames and the burst occurs at the TS0 time-slot in frames 0,10,20,30 and 40 in the control channel multi-frame. \n", "\n", "
\"gsm\"
\n", "
Figure 2: Frequency correction bursts at 67708.3Hz are transmitted at time slot TS0 on frames 0,10,20,30 and 40 in a control hannel multi-frame. That sequence repeates every 51 TDMA frames. So the interval between bursts within a frame is 46.15ms, and the interval between the last burst in a frame to the first burst in the next is 50.765ms
\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we receive a signal from a base station, we should see these tone bursts at 67.7083KHz offset with respect to the center frequency of the channel. If the frequency offset of the bursts is different than 67.7083KHz, then we can compute its offset and find the correction that is needed to calibrate our software defined radio. \n", "\n", "\n", "### Finding a GSM base station\n", "\n", "The first thing to do is to find a GSM base station in your area, that has a good steady signal. If you have poor cell reception, you might want to try this near cory hall -- where we were able to pick up a few. Unfortunately, the downlink frequency band is shared with spread-spectrum LTE and 3G stations as well, so detection based on the energy of a signal in a channel is not enough. It is easy to find a base station based on the spectrum shape in the channel and also based on the frequency correction bursts. It is posible to develop routines in order to do so automatically, but for the sake of simplicity (and time) we will manually search for GSM base station in our area. \n", "\n", "Use either Gqrx or SDR\\# to look for GSM base station. Here's a screen shot of GSM and CDMA\n", "\n", "
\"gsm\"
\n", "
Figure 3: Spectrum of GSM and spread spectrum when sampled at 2MS/s
\n", "\n", "\n", "Here's the average power spectrum as well as the magnitude of the time signal. Note that for GSM, the energy is concentrated towards the center of the spectrum and drops at the edges smoothly. You can also see that we have a considerable amount of frequency offset, because the spectrum is not centered around the right frequency. \n", "\n", "I've searched the spectrum around Cory hall and found the following frequencies to have GSM base stations: 869.2 (med), 869.4 (hi) , 869.6 (low), 874.4 (med), 874.6 (hi), 879.2 (low), 879.4 (med), 879.6 (hi), 879.8 (med), 890.2 (med), 890.4 (med), 890.6 (low), 890.8 (med), 891.0 (hi), 891.4 (med), where (low), (med), (high) are the signal intensity I measured at my office at 5th floor of cory. NOTE: These are good options to try, but reception varies across the building and campus. \n", "\n", "\n", "In case you are in a place without GSM basestations, then we recorder some data for you to practice and develop your code on. It can be downloaded from: https://inst.eecs.berkeley.edu/~ee123/sp14/lab/lab4/gsm.npy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Task I: \n", "\n", "* Find a GSM base-station with SDR\\# or with Gqrx\n", "* In ipython notebook, collect 25600*3 samples of data at a samping rate of 240KHz. Discard the first 2000 samples as they are generally not valid. \n", "* Compute the signals's average power spectrum. \n", "* Display both the power spectrum and a magnitude-time domain section that corresponds to 5ms, which should cover a time period just over 1 TDMA frame length (1200 samples). \n", "* Can you see 8 TDMA time-slots? You should see the guard time between TDMA frames! \n", "\n", "##### Debug hints\n", "* If your time signal is quantized -- try increasing the gain\n", "* Sometimes, the reference frequency will be way off -- over 60ppm. In that case, your spectrum will be significanly assymmetric around the center. You can use the function `sdr.set_freq_correction(ppm)` to correct for some of the offset. Setting `sdr.set_freq_correction(1)` will shift the spectrum by 880Hz around 880MHz\n", "* If you don't see the TDMA frames, then you may have just too low of an SNR. Place the antenna on a conductive surface, close to a window. " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fs = 240000\n", "fc = \n", "gain = \n", "ppm = \n", "\n", "# your code here\n", "\n", "sdr = RtlSdr()\n", "sdr.sample_rate = fs # sampling rate\n", "sdr.gain = gain\n", "sdr.center_freq = fc\n", "sdr.set_freq_correction(ppm)\n", "# collect data and throw away the first 2000 samples, since they are no good!\n", "data = sdr.read_samples(25600*3)[2048:]\n", "sdr.close()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# In case you don't have a base station, download gsm.npy and uncomment the next line\n", "#data = np.load('gsm.npy')\n", "\n", "# throw away the first 2000 samples, since they are no good!\n", "data = data[2048:]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# compute average power spectrum\n", "f, sp = avgPS(data,N=256,fs=fs/1000)\n", "fig = figure(figsize=(8,4))\n", "plot(f,10*log10(sp))\n", "title('average power spectrum of GSM')\n", "xlabel('frequency offset [KHz]')\n", "\n", "# plot \n", "fig = figure(figsize=(16,4))\n", "plot(r_[0:1200.0]/fs*1000,abs(data[:1200]))\n", "title('Magnitude GSM signal, showing TDMA frames')\n", "xlabel('t [ms]')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One way to see the frequency correction bursts is to compute a spectrogram of the signal. This is very effective, though not very computation efficient for the purpose of detecting the bursts. \n", "\n", "* Use the function myspectrogram_hann_ovlp from lab 2 \n", "* For the length of the burst, what length should the spectrogram window be in order to detect the bursts? Play with different parameters. \n", "* You should be able to see about 6 frequency correction bursts. Also note that in many cases the frequency correction bursts can be 30-50KHz away from where they are supposed to be!" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Your code here\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Finding the FCCH bursts and computing the frequency offset\n", "\n", "There are many methods for robust frequency correction for GSM. The approach we will take here is using an envelope detection over a frequency band to detect the position in time of the FCCH bursts. Once the the samples of a burst are recognized, we can use the DFT to calculate the frequency offset. Magnitude averaging over several bursts will give us a more robust estimation of the offset. \n", "\n", "Of course, there are going to be many tradeoffs in the design. For example, to be able to distinguish the burst from noise, and the rest of the GSM signal, we would like to use a narrow-band filter. However, because of the frequency offset the FCCH burst might be outside of our filter bandwwidth and we will miss it! We can solve this in general by using a filter-bank to cover all the possible range of frequency drifts. In addition, narrow-band filters require many filter taps for selectivity. We can save some computation by using decimating filters -- so the detection can be performed at a lower rate. A polyphase implementation of these filters would also be efficient, though you are probably not going to observe much improvements in the python environment. \n", "\n", "For simplicity, in this lab, we will use one narrow-band filter, not a filter bank. To make sure we are looking at the right range, look at the spectrogram above. You should have a good idea what is the offset of the FCCH bursts. \n", "\n", "#### Task II:\n", "* Calculate the length of a FCCH burst in samples for 240KHz sampling rate. What is it?\n", "* Find the approximate frequency of the FCCH burst from the spectrogram (you need to be accurate up to $\\pm 7.5KHz$) and record it as the $f_{cc}$ (no punn intended). In the ideal case of no frequency offset it should be 67.7083KHz.\n", "* Demodulate the GSM signal by $f_{cc}$ to bring that offset frequency down to DC.\n", "* Design a low-pass filter with a pass-band bandwidth of $\\pm7.5$KHz. The number of taps should be odd and correspond roughly to the length of the FCCH burst. What is the TBW product of the filter in that case?? (TBW or Time-Bandwidth product is the product of the length of the filter (in seconds) multiplied with the filter's bandwidth (in Hz) and hence unitless)\n", "* Filter and decimate the data. and plot the magnitude of the result, can you see the FCCH burts?\n", "\n", "##### Debug hints:\n", "* You should clearly see 6 pulses, if you don't, then the pulses are not within your filter bandwidth\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Your code here\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The next step is to detect the position of the FCCH bursts in time and compute their frequency. \n", "\n", "* Write a function that will take the signal and its sampling rate as an input. The function will find the location of the FCCH bursts, and return the starting and ending indexes of each burst within the input array. (You should know the length of each burst from the sampling rate!)\n", "\n", "There are many ways to detect bursts, ... we leave that as a design challenge for you. Some approaches might be more robust then others. \n", "\n", "* Apply the function on the decimated signal to obtain the FCCH bursts positions.\n", "\n", "\n", "##### Debug hints\n", "* debug well that you are actually detecting the bursts!!!\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def locateBurst(x, fs):\n", " # fcch_idx_pos = locateBurst ( x, fs) \n", " # function to find the starting and ending FCCH bursts in a given signal segment\n", " # Inputs:\n", " # x - signal array\n", " # fs - sampling frequency\n", " #\n", " # Outputs:\n", " # fcch_idx_pos and N x 2 array in which each row represend starting and ending indexes of bursts\n", " #\n", "\n", " \n", " \n", " # Your code here\n", "\n", "\n", " \n", " \n", " \n", " \n", " return pulses \n", " \n", " \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Your test code here\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now that we detected the bursts, we can extract just bursts signals and compute their frequency by finding the peak of a zero-padded DFT. \n", "\n", "Of course there are several bursts in our segment. We can combine the estimates by computing the mean power spectrum of all the bursts and then extract the frequency by finding the peak in the mean power spectrum.\n", "\n", "* Write a function that will take the signal, the FCCH burst positions, the demodulation frequency of our estimated FCCH (i.e., $f_{cc}$) and the bandwidth of the decimated signal. The function will extract the segments of the FCCH bursts, zero-pad them appropriately to get a frequency resolution of 10Hz. The function will then find the actual frequency of the FCCH bursts from the average power spectrum of the DFTs, and calculate the actual offset with respect to 67.7083KHz. \n", "\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def findOffset(data,fcch_pos, fcc, nbw, disp=0):\n", " # freq = findFreq ( data, fcch_pos, fcc, nbw, disp=0)\n", " #\n", " # The function takes the signal the FCCH burst positions, the center frequency of the filter and \n", " # the bandwidth of the decimated signal. The function extracts the segments of the FCCH bursts, \n", " # zero-pad them appropriately, finds the actual frequency of the FCCH bursts within the decimated signal,\n", " # and calculate the actual frequency.\n", " # Inputs:\n", " # data - an array of data\n", " # fcch_pos - positions of fcch bursts generated by locateBurst\n", " # fcc - estimated fcch frequency, which you used to demodulate the data\n", " # nbw - sampling rate of the data\n", " # disp - optinally display the average power spectrum\n", " #\n", " # Outputs:\n", " # offset - The estimated frequency offset with respect to ideal fcch frequency. \n", " \n", " \n", " # Your code here\n", "\n", "\n", " \n", " \n", " return (fcch + fcc) - (1625000.0 / 6.0) / 4.0 " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Apply the function on your data to find the frequency offset.\n", "\n", "\n", "##### Debug hints\n", "* try displaying the power spectrum, or even an image showing all the individual burst power spectrum's intensity" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Your code here\n", "\n", "\n", "\n", "\n", "offset = findOffset( )\n", "print('offset=',offset)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "* what is the shift in PPM?\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Your code here\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fantastic! now, you have found the offset in PPM, you can set the driver of the rtlsdr to correct for this offset by using the \n", "`sdr.set_freq_correction(-ppm)` instruction. The negative sign is because of your offset was -1ppm, you should tell the sdr to compensate by setting its offset to +1ppm. Unfortunately, the driver only accepts integer ppm corrections, so you can only set it to the closes integer value. \n", "\n", "\n", "Task: \n", "Write a new function, `Kalibrate(Nmframes, fc, fs,gain, fcc, ppm, h_bw)`, which automates all the above. \n", "* It acquires number of samples (must be divisible by 256!!!!!) corresponding to a time closest to `Nmframe * 235.4ms`, which is effectively collecting `Nmframe` number of multi-frames worth of data. It collects them with sdr settings of center frequency `fc`, sampling rate of `fs`, frequency correction offset in ppm of `ppm`, and gain of `gain`. The function also takes the estimate FCCH frequency `fcc` and the filter bandwidth `h_bw`. \n", "* The function return the frequency offset in hz, and in ppm.\n", "\n", "\n", "Debug your function well!\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def Kalibrate(Nmframe, fc, fs,ppm,gain, fcc, h_bw, disp=0):\n", " # (offset, ppm) = Kalibrate(Nmframe, fc, fs,ppm,gain, fcc, h_bw, disp=0)\n", " #\n", " # Inputs:\n", " # Nmfram - number of multi-frames length of data to acquire\n", " # fc - center frequency of the sdr driver\n", " # fs - the sampling rate of the sdr driver\n", " # ppm - the frequency correction in ppm for the sdr driver\n", " # gain - gain of the sdr driver\n", " # fcc - estimated fcch frequency, which you used to demodulate the data\n", " # h_bw - Bandwidth of the low-pass filter\n", " # disp - optinally display the average power spectrum\n", " #\n", " # Outputs:\n", " # offset - The estimated frequency offset with respect to ideal fcch frequency. \n", " # ppm - frequency offset in ppm\n", "\n", "\n", " \n", " \n", " # Your code here\n", "\n", "\n", " \n", " \n", " return (offset, offset / (fc + (1625000.0 / 6.0) / 4.0)*1e6)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Your debug code here\n", "\n", "\n", "\n", "fs = \n", "fc = \n", "Ndata = 1\n", "gain = \n", "ppm = \n", "offset = Kalibrate(Ndata, fc, fs,ppm,gain, (1625000.0 / 6.0) / 4.0, 15000,disp=1)\n", "print(offset)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Task:\n", "Track the frequency drift by calling Kalibrate consequitively for about 4 minutes. Plot the frequency drift in Hz as a function of time. To record the time, record the value of `time.time()` before each call to Kalibrate. Can you see the effect of the heating of the crystal oscilator as the chip is being used? Try blowing air on the sdr, to see the effect on the frequency drift. \n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline\n", "import time\n", "import pylab as pl\n", "from IPython import display\n", "\n", "fs = 240000\n", "fc = \n", "Ndata = 1\n", "gain = \n", "ppm = ;\n", "\n", "\n", "t = np.zeros(300)\n", "fset=np.zeros(300)\n", "\n", "fig = figure(figsize=(16,4))\n", "for n in r_[0:300]:\n", " t[n]=time.time()\n", " fset[n] = Kalibrate(Ndata, fc, fs,ppm, gain, (1625000.0 / 6.0) / 4.0, 15000,disp=0)[0]\n", " \n", " if n % 10 == 0:\n", " pl.plot((t[:n]-t[0])/60.0,fset[:n],'b')\n", " display.clear_output(wait=True)\n", " display.display(pl.gcf())\n", "fig = figure(figsize=(16,4))\n", "plt.plot((t[:n]-t[0])/60.0,fset[:n])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }