├── .gitignore ├── AuxiliaryWork.zip ├── Dockerfile.txt ├── LICENSE.txt ├── Makefile ├── Makefile.old ├── README.md ├── RemoveCellWithNbInit.py ├── before_after.py ├── config_notebook_ensg ├── filter_config.py ├── filters ├── RemoveCellWithNbInitIpy.py └── __init__.py ├── html ├── Adaptive_versions.html ├── BasicFiltering_correction.html ├── BasicFiltering_text.html ├── BasicSystemsRepr.html ├── Bilinear_synthesis.html ├── Continuous_time_case.html ├── Convolution.html ├── DFT.html ├── DelaysAndScales.html ├── Demo_notebook.html ├── DigitalFilters.html ├── Discrete_Time_Fourier_properties.html ├── Embryon_TZ.html ├── ExamplesApplications.gif ├── ExamplesApplications.png ├── Exercises_BasicSystemsRepr.html ├── FIR_synthesis.html ├── Fourier_transform.html ├── GenericWiener.gif ├── GenericWiener.png ├── Grad_algo.html ├── Intro_Filtering.html ├── Intro_Fourier.html ├── LabImages_text.html ├── Lecture1_RandomSignals.html ├── Lecture2_RandomSignals.html ├── Lecture3_RandomSignals.html ├── Optimum_filtering.html ├── Optimum_filtering_en.html ├── Periodization_discretization.html ├── Sampling.html ├── Soundtries.html ├── SystemIdentification.png ├── TransferFunctions.html ├── Widgets_ipy6_withipy7compatibility.html ├── ZerosPoles.html ├── bacteria.png ├── barbara.png ├── cellules.png ├── conv_optfilter.jpg ├── conv_optfilter.png ├── correlation.py ├── decticelle.npz ├── ecg.npy ├── fig_filter1.png ├── fig_filter2.png ├── fig_template.jpg ├── fig_template.png ├── flatten.py ├── index.html ├── interactive_sols.ipy ├── interactive_sols.py ├── jolie_fin_de_page.png ├── latex_envs.css ├── lena512.png ├── nbinit.ipy ├── noisecancellation.jpg ├── parole_bruitee.npz ├── plot_rea.py ├── plot_sighisto.py ├── plt_LPtemplate.py ├── saturne.png ├── saturne_vraie.png ├── sb1.npz ├── sb2.npz ├── sig1.npz ├── signal.npz ├── syssound.py ├── test.py ├── test_sound.wav ├── toc.html ├── toc_and_cln.py ├── voix_outretombe.wav ├── widgets_utils.ipy ├── widgets_utils.py ├── windows_disp.ipy ├── windows_disp_jup.ipy ├── zerospolesdisplay.py └── zerospolesplay.py ├── index.html ├── index.ipynb ├── install_pkg_ensg ├── latex_envs.css ├── local_repo_update ├── local_repo_update_ensg ├── requirements.txt ├── sp_download ├── src ├── Adaptive_versions.ipynb ├── BasicFiltering_correction.ipynb ├── BasicFiltering_text.ipynb ├── BasicSystemsRepr.ipynb ├── Bilinear_synthesis.ipynb ├── Continuous_time_case.ipynb ├── Convolution.ipynb ├── DFT.ipynb ├── DelaysAndScales.ipynb ├── Demo_notebook.ipynb ├── DigitalFilters.ipynb ├── Discrete_Time_Fourier_properties.ipynb ├── Embryon_TZ.ipynb ├── ExamplesApplications.gif ├── ExamplesApplications.png ├── Exercises_BasicSystemsRepr.ipynb ├── FIR_synthesis.ipynb ├── Fourier_transform.ipynb ├── GenericWiener.gif ├── GenericWiener.png ├── Grad_algo.ipynb ├── Intro_Filtering.ipynb ├── Intro_Fourier.ipynb ├── LabImages_text.ipynb ├── Lecture1_RandomSignals.ipynb ├── Lecture2_RandomSignals.ipynb ├── Lecture3_RandomSignals.ipynb ├── Optimum_filtering.ipynb ├── Optimum_filtering_en.ipynb ├── Periodization_discretization.ipynb ├── Sampling.ipynb ├── Soundtries.ipynb ├── SystemIdentification.png ├── TransferFunctions.ipynb ├── Widgets_ipy6_withipy7compatibility.ipynb ├── ZerosPoles.ipynb ├── bacteria.png ├── barbara.png ├── cellules.png ├── conv_optfilter.jpg ├── conv_optfilter.png ├── correlation.py ├── decticelle.npz ├── ecg.npy ├── fig_filter1.png ├── fig_filter2.png ├── fig_template.jpg ├── fig_template.png ├── flatten.py ├── index.ipynb ├── interactive_sols.ipy ├── interactive_sols.py ├── jolie_fin_de_page.png ├── lena512.png ├── nbinit.ipy ├── noisecancellation.jpg ├── parole_bruitee.npz ├── plot_rea.py ├── plot_sighisto.py ├── plt_LPtemplate.py ├── saturne.png ├── saturne_vraie.png ├── sb1.npz ├── sb2.npz ├── sig1.npz ├── signal.npz ├── syssound.py ├── test.py ├── test_sound.wav ├── toc.ipynb ├── toc_and_cln.py ├── voix_outretombe.wav ├── widgets_utils.ipy ├── widgets_utils.py ├── windows_disp.ipy ├── windows_disp_jup.ipy ├── zerospolesdisplay.py └── zerospolesplay.py ├── tex ├── ExamplesApplications.png ├── GenericWiener.png ├── Poly.aux ├── Poly.out ├── Poly.pdf ├── Poly.tex ├── SystemIdentification.png ├── bacteria.png ├── barbara.png ├── cellules.png ├── conv_optfilter.jpg ├── conv_optfilter.png ├── fig_filter1.png ├── fig_filter2.png ├── fig_template.jpg ├── fig_template.png ├── header.tex ├── index.html ├── jolie_fin_de_page.png ├── lena512.png ├── noisecancellation.jpg ├── saturne.png └── saturne_vraie.png ├── update_distrib └── update_html /.gitignore: -------------------------------------------------------------------------------- 1 | *.tex 2 | *.log 3 | *.toc 4 | *tmp* 5 | *files/ 6 | exec/ 7 | conversion/ 8 | exec (copie)/ 9 | __pycache__/ 10 | /.project 11 | plustard/ 12 | __pycache__/ 13 | .ipynb_checkpoints/ 14 | LecturesSignalProcessing.zip 15 | AuxiliaryWork.zip 16 | !header.tex 17 | !Poly.tex 18 | !.gitignore 19 | -------------------------------------------------------------------------------- /AuxiliaryWork.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/AuxiliaryWork.zip -------------------------------------------------------------------------------- /Dockerfile.txt: -------------------------------------------------------------------------------- 1 | FROM andrewosh/binder-base 2 | 3 | MAINTAINER Jean-François Bercher <___@gmail.com> 4 | 5 | USER root 6 | 7 | # Add Julia dependencies 8 | #RUN apt-get update 9 | #RUN apt-get install -y julia libnettle4 && apt-get clean 10 | 11 | USER main 12 | 13 | 14 | 15 | # Install my custom extensions 16 | RUN jupyter nbextension install https://rawgit.com/jfbercher/latex_envs/master/latex_envs.zip --user 17 | RUN jupyter nbextension enable latex_envs/latex_envs 18 | RUN jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/highlighter.zip --user 19 | RUN jupyter nbextension enable usability/highlighter/highlighter 20 | RUN jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/interactive_sols.zip --user 21 | RUN jupyter nbextension enable usability/interactive_sols/interactive_sols 22 | 23 | # Install requirements for Python 3 24 | RUN /home/main/anaconda/envs/python3/bin/pip install -r requirements.txt 25 | 26 | 27 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | 3 | #--> original source file in main directory 4 | #IPYNB= $(wildcard *.ipynb) 5 | #this is to get the list of basenames dependencies in a subdir 6 | IPYNB= $(notdir $(wildcard src/*.ipynb)) #$(shell ls -1 src/*.ipynb |xargs -n1 basename) 7 | 8 | # 9 | MAIN_TeX="Poly.tex" 10 | MAIN_pdf=Poly.pdf 11 | zip_dest="public_html/PPMD/" 12 | web_dest="public_html/Lectures_SignalProcessing" 13 | ssh_user="bercherj@ssh.esiee.fr" 14 | # 15 | HTML= $(IPYNB:.ipynb=.html) 16 | SUBDIR_HTML = $(foreach I,$(HTML),html/$I) 17 | #alternatively: 18 | #SUBDIR_HTML = $(addprefix html/,$(HTML)) 19 | TEX= $(IPYNB:.ipynb=.tex) 20 | SUBDIR_TEX = $(foreach I,$(TEX),tex/$I) 21 | SUBDIR_exec = $(foreach I,$(IPYNB),exec/$I) 22 | 23 | here=$(CURDIR) 24 | dirName=$(notdir $(CURDIR)) 25 | 26 | html: $(SUBDIR_HTML) $(SUBDIR_exec) 27 | 28 | #to convert ipynb in current directory to html in sub html/ 29 | html/%.html: exec/%.ipynb 30 | echo "Executing jupyter nbconvert --to html_with_toclenvs $^" 31 | jupyter nbconvert --inplace --config filter_config.py $^ 32 | jupyter nbconvert --to html_with_toclenvs $^ 33 | ./update_html $^ 34 | #perl -pi -e s/_fr}/-fr}/g $^ 35 | mv exec/$*.html html/ 36 | rsync -a src/ html/ --exclude='*.ipynb' --exclude='*.html' --exclude='*.*py' 37 | 38 | tex: exec $(SUBDIR_TEX) 39 | 40 | altsrc: 41 | rsync -a src/ exec/ --exclude='*.ipynb' 42 | 43 | # Convert notebooks in src into an executable version in subdir exec 44 | exec/%.ipynb: src/%.ipynb 45 | echo "Executing jupyter nbconvert exec $^" 46 | jupyter nbconvert --execute --allow-errors --to notebook $^ --output-dir exec 47 | 48 | exec: altsrc $(SUBDIR_exec) 49 | 50 | 51 | tex/%.tex: exec/%.ipynb 52 | echo "Executing jupyter nbconvert --to latex_with_lenvs $^" 53 | cp $^ tex/ 54 | cd tex/ && \ 55 | jupyter nbconvert --to latex_with_lenvs --LenvsLatexExporter.removeHeaders=True --template thmsInNb_book $(notdir $^) &&\ 56 | cd .. &&\ 57 | rm tex/$(notdir $^) 58 | 59 | 60 | pdf: tex/${MAIN_pdf} 61 | 62 | tex/${MAIN_pdf}: $(SUBDIR_TEX) 63 | echo Compiling $(MAIN_TeX) to pdf in tex directory 64 | rsync -a src/*.png tex/ && \ 65 | cd tex && \ 66 | xelatex -interaction=nonstopmode $(MAIN_TeX) &> /dev/null | cat && \ 67 | xelatex -interaction=nonstopmode $(MAIN_TeX) &> /dev/null | cat 68 | 69 | zip: html 70 | rm -f $(dirName).zip 71 | zip -9 -r $(dirName) src/ 72 | zip -9 -r $(dirName) html/ 73 | zip -9 -r $(dirName) tex/*.pdf 74 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/$(dirName).zip $(ssh_user):$(zip_dest) 75 | 76 | all: tex html pdf 77 | cp *.css html/ 2>/dev/null | cat && \ 78 | cp *.png html/ 2>/dev/null | cat 79 | 80 | git: all 81 | git add . 82 | git commit -m "update `date +'%y.%m.%d %H:%M:%S'`" 83 | git push 84 | 85 | sync: $(SUBDIR_HTML) $(SUBDIR_EXEC) 86 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/html/*.* --exclude='*.ipynb' $(ssh_user):$(web_dest) 87 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/exec/*.ipynb $(ssh_user):$(web_dest) 88 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/exec/*.ipy $(ssh_user):$(web_dest) 89 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/exec/*.py $(ssh_user):$(web_dest) 90 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/tex/*.pdf $(ssh_user):$(web_dest) 91 | 92 | $(V).SILENT: 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /Makefile.old: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | 3 | #--> original source file in main directory 4 | #IPYNB= $(wildcard *.ipynb) 5 | #this is to get the list of basenames dependencies in a subdir 6 | IPYNB= $(notdir $(wildcard src/*.ipynb)) #$(shell ls -1 src/*.ipynb |xargs -n1 basename) 7 | 8 | # 9 | HTML= $(IPYNB:.ipynb=.html) 10 | SUBDIR_HTML = $(foreach I,$(HTML),html/$I) 11 | #alternatively: 12 | #SUBDIR_HTML = $(addprefix html/,$(HTML)) 13 | TEX= $(IPYNB:.ipynb=.tex) 14 | SUBDIR_TEX = $(foreach I,$(TEX),tex/$I) 15 | SUBDIR_exec = $(foreach I,$(IPYNB),exec/$I) 16 | 17 | here=$(CURDIR) 18 | #/home/bercherj/JFB/tstmake 19 | 20 | 21 | a: 22 | echo $(IPYNB) 23 | 24 | rien: $(IPYNB) 25 | echo $(IPYNB2) 26 | echo $(CURDIR) 27 | 28 | html: $(SUBDIR_exec) $(SUBDIR_HTML) 29 | #jupyter nbconvert --to html $(IPYNB) 30 | #echo "$(SUBDIR_HTML)" 31 | 32 | #to convert ipynb in current directory to html in sub html/ 33 | html/%.html: exec/%.ipynb 34 | echo "Executing jupyter nbconvert --to html $^" 35 | #jupyter nbconvert --to html exec/$(basename $(notdir $^)).ipynb --output html/$(basename $(notdir $^)).html 36 | ./conversion/conv_ipynb_to_html $^ 37 | mv exec/$*.html html/ 38 | 39 | tex: exec $(SUBDIR_TEX) 40 | 41 | #to convert ipynb in current directory to html in sub html/ 42 | #html/%.html: %.ipynb 43 | # echo "Executing jupyter nbconvert --to html $^" 44 | # #jupyter nbconvert --quiet --to html $^ 45 | # ./conversion/conv_ipynb_to_html $^ 46 | # mv $*.html html/ 47 | 48 | altsrc: 49 | rsync -a src/ exec/ --exclude=*.ipynb 50 | 51 | # Convert notebooks in src into an executable version in subdir exec 52 | exec/%.ipynb: src/%.ipynb 53 | echo "Executing jupyter nbconvert exec $^" 54 | jupyter nbconvert --execute --allow-errors --to notebook $^ --output exec/$(notdir $^) 55 | 56 | exec: altsrc $(SUBDIR_exec) 57 | 58 | #to convert ipynb in ipynb directory to html in sub html/ 59 | html/%.html: ipynb/%.ipynb 60 | echo "Executing jupyter nbconvert --to html $^" 61 | jupyter nbconvert --quiet --to html $^ 62 | mv $*.html html/ 63 | 64 | tex/%.tex: exec/%.ipynb 65 | echo "Executing jupyter nbconvert --to latex $^" 66 | cp $^ tex/ 67 | cd tex/ && \ 68 | echo "Executing jupyter $(here)/conversion/ipynb_thms_to_latex $(notdir $^)" && \ 69 | $(here)/conversion/ipynb_thms_to_latex $(notdir $^) #&&\ 70 | cd .. 71 | rm tex/$(notdir $^) 72 | 73 | pdf: tex 74 | cd tex && \ 75 | xelatex -interaction=nonstopmode Poly.tex &> /dev/null | cat && \ 76 | xelatex -interaction=nonstopmode Poly.tex &> /dev/null | cat 77 | 78 | zip: html 79 | rm -f LecturesSignalProcessing.zip 80 | zip -9 -r LecturesSignalProcessing src/ 81 | zip -9 -r LecturesSignalProcessing html/ 82 | zip -9 -r LecturesSignalProcessing tex/*.pdf 83 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/LecturesSignalProcessing.zip bercherj@ssh.esiee.fr:public_html/ 84 | 85 | all: tex html pdf 86 | cp *.css html/ 2>/dev/null | cat && \ 87 | cp *.png html/ 2>/dev/null | cat 88 | 89 | git: all 90 | git add . 91 | git commit -m "update `date +'%y.%m.%d %H:%M:%S'`" 92 | git push 93 | 94 | sync: all 95 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/html/*.css bercherj@ssh.esiee.fr:public_html/IT3007 96 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/html/*.html bercherj@ssh.esiee.fr:public_html/IT3007 97 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/*.ipynb bercherj@ssh.esiee.fr:public_html/IT3007 98 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/tex/*.pdf bercherj@ssh.esiee.fr:public_html/IT3007 99 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/*.png bercherj@ssh.esiee.fr:public_html/IT3007 100 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/*.zip bercherj@ssh.esiee.fr:public_html/IT3007 101 | 102 | 103 | 104 | rsync -av --chmod=755 -e "ssh -p 52222" $(here)/install* bercherj@ssh.esiee.fr:public_html/IT3007 105 | 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Journey in Signal processing with Jupyter 2 | 3 | [![Join the chat at https://gitter.im/jfbercher/LecturesSignalProcessing](https://badges.gitter.im/jfbercher/LecturesSignalProcessing.svg)](https://gitter.im/jfbercher/LecturesSignalProcessing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 4 | 5 | 6 | 7 | A Series of lectures given at [ESIEE-Paris](http://www.esiee.fr), [ISBS-Paris](http://www.isbs.fr/), [ENSG](http://www.ensg.eu/) 8 | 9 | by: J.-F. Bercher, (c) 2014-2018 10 | 11 | We provide here the complete collection of Jupyter's notebooks, together with their html version and a [PDF EBOOK](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/tex/Poly.pdf). 12 | 13 | - Notebooks are located in the subdirectory `src` and not fully executed, 14 | - while the html version in `html` corresponds to the full output. 15 | 16 | Beware that the notebooks make a heavy use of some Jupyter javascript extensions (e.g. latex_envs, exercise, ...) and unfortunately do not render correctly in nbviewer or in the github viewer ; that is the reason why we provide the static version in `./html`. See the install section below. 17 | 18 | 19 | ## Table of Contents 20 | 21 | The full table of contents is [here](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/index.html). 22 | Below are the chapter heads. 23 | 24 | [I - Effects of delays and scaling on signals](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/DelaysAndScales.html) 25 | 26 | [II - A basic introduction to filtering](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Intro_Filtering.html) 27 | 28 | [III -Introduction to the Fourier representation](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Intro_Fourier.html) 29 | 30 | [IV - Fourier transform](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Fourier_transform.html) 31 | 32 | [V - Convolution](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Convolution.html) 33 | 34 | [VI - Lab on Basic System Representations](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Exercises_BasicSystemsRepr.html) 35 | 36 | [VII - The continuous time case](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Continuous_time_case.html) 37 | 38 | [VIII - Periodization, discretization and sampling](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Periodization_discretization.html) 39 | 40 | [IX - Lab on basics in image processing](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/LabImages_text.html#Lab-on-basic-image-processing) 41 | 42 | [X - Digital filters](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/DigitalFilters.html) 43 | 44 | [XI - Lab on Basic Filtering Problems](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/BasicFiltering_text.html) 45 | 46 | [XII - Random Signals](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Lecture1_RandomSignals.html) 47 | 48 | [XIII - Adaptive Filters](https://rawgit.com/jfbercher/LecturesSignalProcessing/master/html/Optimum_filtering.html#Adaptive-Filters) 49 | 50 | 51 | 52 | ## Installation 53 | - Clone the repo as usual 54 | - The notebooks use a bunch of nbextensions that you shall install. 55 | 56 | - In particular, they need the [latex_envs extension](https://github.com/jfbercher/jupyter_latex_envs) that enable to enter and display LaTeX environments. You can install `LaTeX_envs` from pip and conda : 57 | ``` 58 | pip3 install jupyter_latex_envs [--user][--upgrade] 59 | jupyter nbextension install --py latex_envs [--user|--sys-prefix|--system] 60 | jupyter nbextension enable --py latex_envs [--user|--sys-prefix|--system] 61 | ``` 62 | The best option is to install these extensions from the [IPython-contrib/IPython-notebook-extensions](https://github.com/ipython-contrib/IPython-notebook-extensions) repo (also installable [from Pypi](https://pypi.org/project/jupyter_contrib_nbextensions/)). Follow the guidelines there. You may also install these extensions directly from here using: 63 | ```bash 64 | # Install jupyter extensions 65 | jupyter nbextension install https://rawgit.com/jfbercher/latex_envs/master/latex_envs.zip --user 66 | jupyter nbextension enable latex_envs/latex_envs 67 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/highlighter.zip --user 68 | jupyter nbextension enable usability/highlighter/highlighter 69 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/interactive_sols.zip --user 70 | jupyter nbextension enable usability/interactive_sols/interactive_sols 71 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/exercise.zip --user 72 | jupyter nbextension enable usability/exercise/main 73 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/exercise2.zip --user 74 | jupyter nbextension enable usability/exercise2/main 75 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/rubberband.zip --user 76 | jupyter nbextension enable usability/rubberband/main 77 | ``` 78 | 79 | 80 | ---- 81 | ### Development - Contributing - Contact 82 | 83 | This is an ongoing work and the maturity of the different chapters varies. Actually the first chapters are much less finalized that the later ones. Feel free to make corrections, add contents, examples, information. Your contribution will be most welcome (and acknowledged). You may do so by changing the files and submitting a pull request via the github interface. 84 | 85 | Contact the main author, Jean-François Bercher, at jf "dot" bercher "at" gmail "dot" com 86 | -------------------------------------------------------------------------------- /RemoveCellWithNbInit.py: -------------------------------------------------------------------------------- 1 | from nbconvert.preprocessors import Preprocessor 2 | 3 | class RemoveCellWithNbInit(Preprocessor): 4 | 5 | def preprocess(self, notebook, resources): 6 | notebook.cells = [cell for cell in notebook.cells if not '%run nbinit.ipy' in cell.source] 7 | return notebook, resources 8 | -------------------------------------------------------------------------------- /before_after.py: -------------------------------------------------------------------------------- 1 | import sys, re 2 | 3 | filename = sys.argv[1] 4 | with open(filename, 'r') as f: 5 | text = f.read() 6 | back = re.findall(r"\[Back\]\(([\S\s]*?)\)", text)[0].replace("ipynb","html") 7 | next = re.findall(r"\[Next\]\(([\S\s]*?)\)", text)[0].replace("ipynb","html") 8 | index = re.findall(r"\[Index\]\(([\S\s]*?)\)", text)[0].replace("ipynb","html") 9 | 10 | print('< previous | index | next >'.format(back, index, next)) 11 | 12 | -------------------------------------------------------------------------------- /config_notebook_ensg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # set proxies 4 | export http_proxy=http://10.0.4.2:3128 5 | export https_proxy=http://10.0.4.2:3128 6 | export all_proxy=http://10.0.4.2:3128 7 | 8 | # Run as user! 9 | 10 | if [ "$EUID" -eq 0 ] 11 | then echo "Lancer ce script en tant qu'utilisateur" 12 | exit 13 | fi 14 | 15 | # clone the git repository 16 | #cd ~ 17 | #git clone https://github.com/jfbercher/LecturesSignalProcessing.git 18 | #cd ~/LecturesSignalProcessing 19 | 20 | # Check if directories exist 21 | if [ ! -d "~/.jupyter/nbconfig" ]; then 22 | mkdir -p ~/.jupyter/nbconfig 23 | fi 24 | 25 | # Change rights 26 | sudo chown -R $USER:$USER ~/.local/share/jupyter 27 | sudo chown -R $USER:$USER ~/.jupyter/nbconfig 28 | 29 | 30 | # Install jupyter extensions 31 | # latex_envs 32 | pip3 install jupyter_latex_envs --user --upgrade 33 | jupyter nbextension install --py latex_envs --user 34 | jupyter nbextension enable latex_envs --user --py 35 | # ipywidgets 36 | pip3 install ipywidgets==6.0 --user # version 6 because the update causes problems 37 | jupyter nbextension enable --py widgetsnbextension 38 | # tiny extensions 39 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/highlighter.zip --user 40 | jupyter nbextension enable highlighter/highlighter 41 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/interactive_sols.zip --user 42 | jupyter nbextension enable usability/interactive_sols/interactive_sols 43 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/exercise.zip --user 44 | jupyter nbextension enable exercise/main 45 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/exercise2.zip --user 46 | jupyter nbextension enable exercise2/main 47 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/rubberband.zip --user 48 | jupyter nbextension enable rubberband/main 49 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/toc2.zip --user 50 | jupyter nbextension enable toc2/main 51 | jupyter nbextension install https://rawgit.com/jfbercher/small_nbextensions/master/code_prettify.zip --user 52 | jupyter nbextension enable code_prettify/code_prettify 53 | 54 | # Update rpy2 55 | # pip3 install rpy2 --update --user 56 | 57 | 58 | 59 | ##chmod executable files 60 | #cd ~/LecturesSignalProcessing 61 | #chmod 755 local_repo_update_ensg 62 | 63 | 64 | -------------------------------------------------------------------------------- /filter_config.py: -------------------------------------------------------------------------------- 1 | c = get_config() 2 | 3 | c.NbConvertApp.export_format = 'notebook' 4 | c.Exporter.preprocessors = ['filters.RemoveCellWithNbInitIpy'] 5 | 6 | # Usage: jupyter nbconvert --inplace --config filter_config.py FILE.ipynb 7 | -------------------------------------------------------------------------------- /filters/RemoveCellWithNbInitIpy.py: -------------------------------------------------------------------------------- 1 | from nbconvert.preprocessors import Preprocessor 2 | 3 | class RemoveCellWithNbInitIpy(Preprocessor): 4 | 5 | def preprocess(self, notebook, resources): 6 | celllist = [] 7 | for cell in notebook.cells: 8 | if '%run nbinit.ipy' in cell.source: 9 | cell.source = '' 10 | for output in cell.outputs: 11 | if 'text' in output: 12 | output['text'] = '' 13 | celllist.append(cell) 14 | notebook.cells = celllist 15 | 16 | return notebook, resources 17 | 18 | # def preprocess_cell(self, cell, resources, index): 19 | # print(type(cell)) 20 | # print("index ", index, " ---> ", cell.source) 21 | # if cell.cell_type == "code" and "outputs" in cell: 22 | # Below just an ad hoc personnal filter 23 | # if "%run nbinit.ipy" in cell.source: 24 | # cell.source = 'nnnn' 25 | #cell.cell_type = "code" 26 | #for output in cell.outputs: 27 | # output['text'] = 'aaa' 28 | # if "data" in output: 29 | # if 'text/html' in output.data: output.data['text/html'] = '' 30 | # if 'text/plain' in output.data: output.data['text/plain'] = '' 31 | # return cell, resources 32 | -------------------------------------------------------------------------------- /filters/__init__.py: -------------------------------------------------------------------------------- 1 | from .RemoveCellWithNbInitIpy import RemoveCellWithNbInitIpy 2 | -------------------------------------------------------------------------------- /html/ExamplesApplications.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/ExamplesApplications.gif -------------------------------------------------------------------------------- /html/ExamplesApplications.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/ExamplesApplications.png -------------------------------------------------------------------------------- /html/GenericWiener.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/GenericWiener.gif -------------------------------------------------------------------------------- /html/GenericWiener.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/GenericWiener.png -------------------------------------------------------------------------------- /html/SystemIdentification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/SystemIdentification.png -------------------------------------------------------------------------------- /html/bacteria.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/bacteria.png -------------------------------------------------------------------------------- /html/barbara.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/barbara.png -------------------------------------------------------------------------------- /html/cellules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/cellules.png -------------------------------------------------------------------------------- /html/conv_optfilter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/conv_optfilter.jpg -------------------------------------------------------------------------------- /html/conv_optfilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/conv_optfilter.png -------------------------------------------------------------------------------- /html/correlation.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. topic:: Correlation module 3 | 4 | 5 | Provides two correlation functions. :func:`CORRELATION` is slower than 6 | :func:`xcorr`. However, the output is as expected by some other functions. 7 | Ultimately, it should be replaced by :func:`xcorr`. 8 | 9 | For real data, the behaviour of the 2 functions is identical. However, for 10 | complex data, xcorr returns a 2-sides correlation. 11 | 12 | 13 | .. autosummary:: 14 | 15 | ~spectrum.correlation.CORRELATION 16 | ~spectrum.correlation.xcorr 17 | 18 | .. codeauthor: Thomas Cokelaer, 2011 19 | 20 | 21 | 22 | """#from numpy.fft import fft, ifft 23 | import numpy 24 | from numpy import arange, isrealobj 25 | from pylab import rms_flat 26 | 27 | __all__ = ['CORRELATION', 'xcorr'] 28 | 29 | 30 | def CORRELATION(x, y=None, maxlags=None, norm='unbiased'): 31 | r"""Correlation function 32 | 33 | This function should give the same results as :func:`xcorr` but it 34 | returns the positive lags only. Moreover the algorithm does not use 35 | FFT as compared to other algorithms. 36 | 37 | :param array x: first data array of length N 38 | :param array y: second data array of length N. If not specified, computes the 39 | autocorrelation. 40 | :param int maxlags: compute cross correlation between [0:maxlags] 41 | when maxlags is not specified, the range of lags is [0:maxlags]. 42 | :param str norm: normalisation in ['biased', 'unbiased', None, 'coeff'] 43 | 44 | * *biased* correlation=raw/N, 45 | * *unbiased* correlation=raw/(N-`|lag|`) 46 | * *coeff* correlation=raw/(rms(x).rms(y))/N 47 | * None correlation=raw 48 | 49 | :return: 50 | * a numpy.array correlation sequence, r[1,N] 51 | * a float for the zero-lag correlation, r[0] 52 | 53 | The *unbiased* correlation has the form: 54 | 55 | .. math:: 56 | 57 | \hat{r}_{xx} = \frac{1}{N-m}T \sum_{n=0}^{N-m-1} x[n+m]x^*[n] T 58 | 59 | The *biased* correlation differs by the front factor only: 60 | 61 | .. math:: 62 | 63 | \check{r}_{xx} = \frac{1}{N}T \sum_{n=0}^{N-m-1} x[n+m]x^*[n] T 64 | 65 | with :math:`0\leq m\leq N-1`. 66 | 67 | .. doctest:: 68 | 69 | >>> from spectrum import * 70 | >>> x = [1,2,3,4,5] 71 | >>> res = CORRELATION(x,x, maxlags=0, norm='biased') 72 | >>> res[0] 73 | 11.0 74 | 75 | .. note:: this function should be replaced by :func:`xcorr`. 76 | 77 | .. seealso:: :func:`xcorr` 78 | """ 79 | assert norm in ['unbiased','biased', 'coeff', None] 80 | #transform lag into list if it is an integer 81 | if y is None: 82 | y = x 83 | 84 | # N is the max of x and y 85 | N = max(len(x), len(y)) 86 | if len(x)>> from spectrum import * 182 | >>> x = [1,2,3,4,5] 183 | >>> c, l = xcorr(x,x, maxlags=0, norm='biased') 184 | >>> c 185 | array([ 11.]) 186 | 187 | .. seealso:: :func:`CORRELATION`. 188 | """ 189 | N = len(x) 190 | if y is None: 191 | y = x 192 | assert len(x) == len(y), 'x and y must have the same length. Add zeros if needed' 193 | #jfb#assert maxlags <= N, 'maxlags must be less than data length' 194 | 195 | if maxlags is None: 196 | maxlags = N-1 197 | lags = arange(0, 2*N-1) 198 | else: 199 | assert maxlags < N 200 | lags = arange(N-maxlags-1, N+maxlags) 201 | 202 | res = numpy.correlate(x, y, mode='full') 203 | 204 | if norm == 'biased': 205 | Nf = float(N) 206 | res = res[lags] / float(N) # do not use /= !! 207 | elif norm == 'unbiased': 208 | res = res[lags] / (float(N)-abs(arange(-N+1, N)))[lags] 209 | elif norm == 'coeff': 210 | Nf = float(N) 211 | rms = rms_flat(x) * rms_flat(y) 212 | res = res[lags] / rms / Nf 213 | else: 214 | res = res[lags] 215 | 216 | lags = arange(-maxlags, maxlags+1) 217 | return res, lags 218 | -------------------------------------------------------------------------------- /html/decticelle.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/decticelle.npz -------------------------------------------------------------------------------- /html/ecg.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/ecg.npy -------------------------------------------------------------------------------- /html/fig_filter1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/fig_filter1.png -------------------------------------------------------------------------------- /html/fig_filter2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/fig_filter2.png -------------------------------------------------------------------------------- /html/fig_template.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/fig_template.jpg -------------------------------------------------------------------------------- /html/fig_template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/fig_template.png -------------------------------------------------------------------------------- /html/flatten.py: -------------------------------------------------------------------------------- 1 | #Flattening a list of list 2 | #from http://rightfootin.blogspot.fr/2006/09/more-on-python-flatten.html which derives 3 | #from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363051 4 | def flatten(l, ltypes=(list, tuple)): 5 | ltype = type(l) 6 | l = list(l) 7 | i = 0 8 | while i < len(l): 9 | while isinstance(l[i], ltypes): 10 | if not l[i]: 11 | l.pop(i) 12 | i -= 1 13 | break 14 | else: 15 | l[i:i + 1] = l[i] 16 | i += 1 17 | return ltype(l) 18 | 19 | flatten(lw) -------------------------------------------------------------------------------- /html/interactive_sols.ipy: -------------------------------------------------------------------------------- 1 | 2 | ### ------------ interactive solutions: showing and hiding cells 3 | 4 | override_runrange=""" 5 | /* Override original execute-range function */ 6 | console.log("Overriding run-range javascript function"); 7 | IPython.Notebook.prototype.execute_cell_range = function (start, end) { 8 | this.command_mode(); 9 | for (var i=start; i 61 | 72 | """ 73 | 74 | # myhchboxb is a pretty checkbox with css 75 | myhchboxb = """ 76 |
77 | 80 | 84 |
85 | 91 | """ 92 | 93 | #var cell = IPython.notebook.get_cell(index+1); 94 | #cell.element.find("div.input").show() 95 | 96 | # myhchboxd is a pretty checkbox with css 97 | myhchboxd = """ 98 | 104 | """ 105 | 106 | 107 | #display(HTML(myhchboxb.format(cbx_id,nb_cells_to_process))) # display 108 | display(HTML(myhchboxd.format(nb_cells_to_process))) # display 109 | # the checkbox -------------------------------------------------------------------------------- /html/jolie_fin_de_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/jolie_fin_de_page.png -------------------------------------------------------------------------------- /html/latex_envs.css: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | 4 | 22 | 23 | */ 24 | 25 | 26 | /***************************************************************** 27 | LaTeX things 28 | *****************************************************************/ 29 | 30 | .latex_tmp {text-align: justify;} 31 | 32 | .latex_prob, 33 | .latex_examp, 34 | .latex_excs, 35 | .latex_problem, 36 | .latex_example, 37 | .latex_exercise, 38 | .latex_proof { 39 | font-style: normal; 40 | text-align: justify; 41 | margin-left: 0px; 42 | margin-right: 10px; 43 | margin-top: 0px; 44 | margin-bottom: 0px; 45 | background-color: #CCFFCC; 46 | display: block; 47 | } 48 | 49 | .latex_title { 50 | float: left; 51 | font-weight: bold; 52 | padding-right: 10px; 53 | } 54 | 55 | .latex_proofend { 56 | float: right; 57 | } 58 | 59 | .latex_listing { 60 | display: block; 61 | text-align: justify; 62 | margin-right: 30px; 63 | font-family: 'Lucida Sans Typewriter'; 64 | color:black; 65 | background-color: GhostWhite ; 66 | } 67 | 68 | .rendered_html pre, .rendered_html code { 69 | border: 0; 70 | background-color: rgba(161, 139, 139, 0); 71 | /* color: #000; */ 72 | font-size: 100%; 73 | padding: 0; 74 | } 75 | 76 | 77 | .latex_thm, .latex_theorem, .latex_lem, .latex_cor, .latex_defn, .latex_prop, .latex_rem, .latex_property, 78 | .latex_lemma, .latex_corollary, .latex_definition, .latex_proposition, .latex_remark, .latex_proof { 79 | 80 | display: block; 81 | text-align: justify; 82 | margin-right: 10px; 83 | margin-left: 0px; 84 | margin-top: 0px; 85 | margin-bottom: 0px; 86 | font-style: italic; 87 | color:black; 88 | background-color: beige; 89 | } 90 | 91 | .latex_textboxa { 92 | display: block; 93 | font-weight: bold; 94 | text-align: center; 95 | width: 80%; 96 | margin: auto; 97 | border: 2px solid; 98 | padding-top: 5px; 99 | padding-bottom: 5px; 100 | background-color: #f2dede; 101 | border-color: #eed3d7; 102 | color: #CC0099; 103 | border-radius: 8px; 104 | -webkit-border-radius: 8px; 105 | -moz-border-radius: 8px; 106 | border-radius: 8px 107 | } 108 | 109 | img.latex_img { 110 | display: block; 111 | margin: auto; 112 | /*height: XXXpx; /* */ 113 | width: 75%; 114 | } 115 | 116 | p.latex_img { 117 | display: block; 118 | width: 85%; 119 | margin: auto; 120 | text-align: justify; 121 | } 122 | 123 | /***************************************************************** 124 | GENERAL CONFIG 125 | *****************************************************************/ 126 | 127 | 128 | @font-face { 129 | font-family: "Computer Modern"; 130 | src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunss.otf'); 131 | } 132 | 133 | @font-face { 134 | font-family: "Computer Modern"; 135 | font-weight: bold; 136 | src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsx.otf'); 137 | } 138 | @font-face { 139 | font-family: "Computer Modern"; 140 | font-style: oblique; 141 | src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsi.otf'); 142 | } 143 | */ 144 | /* @font-face { 145 | font-family: "Computer Modern"; 146 | font-style: Typewriter; 147 | src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmuntt.otf'); 148 | }*/ 149 | 150 | @font-face { 151 | font-family: "Computer Modern"; 152 | font-weight: bold; 153 | font-style: oblique; 154 | src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunso.otf'); 155 | } 156 | 157 | 158 | div.cell{ 159 | width:100%; 160 | margin-left:auto; /*16% !important;* was preconised but pbs with some browsers*/ 161 | margin-right:auto; 162 | } 163 | h1 { 164 | font-family: Helvetica, serif; 165 | } 166 | h2 { 167 | font-family: Helvetica, serif; 168 | color: darkblue; 169 | } 170 | 171 | h4{ 172 | margin-top:12px; 173 | margin-bottom: 3px; 174 | } 175 | 176 | 177 | .rendered_html p {text-align:justify} 178 | 179 | div.text_cell_render{ 180 | font-family: "Computer Modern", Arial, "Helvetica Neue", Helvetica, Geneva, sans-serif; 181 | line-height: 145%; 182 | font-size: 130%; 183 | color: black; 184 | width:100%; 185 | /*width:800px;*/ 186 | margin-left:0px; 187 | margin-right:auto; 188 | 189 | } 190 | .CodeMirror{ 191 | font-family: "Source Code Pro", source-code-pro,Consolas, monospace; 192 | color: darkblue; 193 | } 194 | 195 | /* commented because many people prefer to have the prompt 196 | .prompt{ 197 | display: None; 198 | } 199 | */ 200 | 201 | /* 202 | div.output_area 203 | { 204 | display: block; 205 | margin-left: auto; 206 | margin-right: auto 207 | } 208 | */ 209 | div.output_subarea.output_text 210 | { 211 | margin-left: +2%; 212 | } 213 | 214 | div.output_subarea.output_png 215 | { 216 | margin-left: +10%; 217 | } 218 | div.output_subarea.output_svg 219 | { 220 | margin-left: +10%; 221 | } 222 | 223 | 224 | .text_cell_render h5 { 225 | font-weight: 300; 226 | font-size: 22pt; 227 | color: #4057A1; 228 | font-style: italic; 229 | margin-bottom: .5em; 230 | margin-top: 0.5em; 231 | display: block; 232 | } 233 | 234 | .warning{ 235 | color: rgb( 240, 20, 20 ) 236 | } 237 | 238 | 239 | 240 | -------------------------------------------------------------------------------- /html/lena512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/lena512.png -------------------------------------------------------------------------------- /html/nbinit.ipy: -------------------------------------------------------------------------------- 1 | 2 | print("... Configuring matplotlib formats") 3 | print("... Configuring matplotlib with inline figures") 4 | 5 | %config InlineBackend.figure_format = 'retina' 6 | #In new notebooks created for IPython 1.0+, I would recommend using %matplotlib inline, since it is more tidy 7 | # and you have more control over which packages are imported and how. Commonly, scipy and numpy are imported separately with: 8 | # from: http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb#Versions 9 | #%config InlineBackend.figure_format = 'svg' #this is depreceated in 2.x 10 | %config InlineBackend.figure_formats = {'retina', 'pdf', 'png', 'svg', 'jpeg'} 11 | 12 | print("... Importing numpy as np, scipy as sp, pyplot as plt, scipy.stats as stats") 13 | print(" ... scipy.signal as sig") 14 | import numpy as np 15 | import scipy as sp 16 | import matplotlib.pyplot as plt 17 | import scipy.stats as stats 18 | import scipy.signal as sig 19 | # Also import pylab for more easy interactive use (but less control) 20 | from pylab import * 21 | 22 | print("... Importing widgets, display, HTML, Image, Javascript") 23 | #For displaying widgets 24 | import ipywidgets as widgets 25 | from ipywidgets import interact, interactive, fixed 26 | from IPython.display import clear_output, display, HTML, Image, Javascript, JSON 27 | 28 | #Some specific imports for plotting 29 | 30 | ### ------------- 31 | print("... Some LaTeX definitions") 32 | 33 | LaTeXdefs=""" 34 | $$\\require{color} 35 | \\require{cancel} 36 | \\def\\tf#1{{\\mathrm{FT}\\left\{ #1 \\right\\}}} 37 | \\def\\flecheTF{\\rightleftharpoons } 38 | \\def\\TFI#1#2#3{{\\displaystyle{\\int_{-\\infty}^{+\\infty} #1 ~e^{j2\\pi #2 #3} 39 | ~\\dr{#2}}}} 40 | \\def\\TF#1#2#3{{\\displaystyle{\\int_{-\\infty}^{+\\infty} #1 ~e^{-j2\\pi #3 #2} 41 | ~\\dr{#2}}}} 42 | \\def\\sha{ш} 43 | \\def\\dr#1{\\mathrm{d}#1} 44 | \\def\\egalpardef{\\mathop{=}\\limits^\\triangle} 45 | \\def\\sinc#1{{\\mathrm{sinc}\\left( #1 \\right)}} 46 | \\def\\rect{\\mathrm{rect}} 47 | \\definecolor{lightred}{rgb}{1,0.1,0} 48 | \\def\myblueeqbox#1{{\\fcolorbox{blue}{lightblue}{$\textcolor{blue}{ #1}$}}} 49 | \\def\\myeqbox#1#2{{\\fcolorbox{#1}{light#1}{$\textcolor{#1}{ #2}$}}} 50 | \\def\\eqbox#1#2#3#4{{\\fcolorbox{#1}{#2}{$\\textcolor{#3}{ #4}$}}} 51 | % border|background|text 52 | \\def\\eqboxa#1{{\\boxed{#1}}} 53 | \\def\\eqboxb#1{{\\eqbox{green}{white}{green}{#1}}} 54 | \\def\\eqboxc#1{{\\eqbox{blue}{white}{blue}{#1}}} 55 | \\def\\eqboxd#1{{\\eqbox{blue}{lightblue}{blue}{#1}}} 56 | \\def\\E#1{\\mathbb{E}\\left[#1\\right]} 57 | \\def\\ta#1{\\left<#1\\right>} 58 | \\def\\egalparerg{{\\mathop{=}\\limits_\\mathrm{erg}}} 59 | \\def\\expo#1{\\exp\\left(#1\\right)} 60 | \\def\\d#1{\\mathrm{d}#1} 61 | \\def\\wb{\\mathbf{w}} 62 | \\def\\sb{\\mathbf{s}} 63 | \\def\\xb{\\mathbf{x}} 64 | \\def\\Rb{\\mathbf{R}} 65 | \\def\\rb{\mathbf{r}} 66 | \\def\\mystar{{*}} 67 | \\def\\ub{\\mathbf{u}} 68 | \\def\\wbopt{\\mathop{\\mathbf{w}}\\limits^\\triangle} 69 | \\def\\deriv#1#2{\\frac{\\mathrm{d}#1}{\\mathrm{d}#2}} 70 | \\def\\Ub{\\mathbf{U}} 71 | \\def\\db{\\mathbf{d}} 72 | \\def\\eb{\\mathbf{e}} 73 | \\def\\vb{\\mathbf{v}} 74 | \\def\\Ib{\\mathbf{I}} 75 | \\def\\Vb{\\mathbf{V}} 76 | \\def\\Lambdab{\\mathbf{\\Lambda}} 77 | \\def\\Ab{\\mathbf{A}} 78 | \\def\\Bb{\\mathbf{B}} 79 | \\def\\Cb{\\mathbf{C}} 80 | \\def\\Db{\\mathbf{D}} 81 | \\def\\Kb{\\mathbf{K}} 82 | \\def\\sinc#1{\\mathrm{sinc\\left(#1\\right)}} 83 | $$ 84 | """ 85 | 86 | display(HTML(LaTeXdefs)) 87 | 88 | ### ---------------------------------- 89 | print("... Defining figures captions ") 90 | 91 | display(HTML( 92 | """""")) 101 | 102 | #def figcaption(text,label=""): 103 | # display(HTML("
Caption: %s
" % text.replace('\n','
'))) 104 | 105 | def figcaption(text, label=" "): 106 | display(HTML("
Caption: %s
" 107 | % text.replace('\n', '
'))) 108 | text = text.replace('',r'\textbf{').replace('','}') #some replacement of HTML formatting 109 | text = text.replace('',r'\textit{').replace('','}') 110 | text = text.replace('',r'\texttt{').replace('','}') 111 | display(JSON({'caption': text, 'label':label}),include=["application/json"]) 112 | 113 | ### ------------------------------------------------- 114 | # A stub function 115 | def js_addon(): 116 | pass 117 | 118 | print("... Loading customized Javascript for interactive solutions (show/hide)") 119 | from interactive_sols import process_solution, unhide_next_cell, unhide_all_cells 120 | show_solution=process_solution 121 | #%run interactive_sols.ipy 122 | 123 | ## --------------------------------------------------- 124 | print("... Redefining interactive from ipywidgets") 125 | 126 | # Redefine interactive, because in the new version, return of functions 127 | # is automatically displayed. That is the way it is, see https://github.com/ipython/ipywidgets/issues/162 128 | # Thus what we do is to catch the call, redefine the function to hide its return. 129 | # Then it is always possible to call directly the original function and get its return value. 130 | # Also, it is possible to call it with the parameters selected from the interactive function 131 | # by func(**ww.kwargs) where ww is the object returned by intercative or interact. 132 | 133 | def interactive(f,*args,**kwargs): 134 | import ipywidgets 135 | def fn(*args,**kwargs): 136 | f(*args,**kwargs) 137 | w=ipywidgets.interactive(fn,*args,**kwargs) 138 | return w 139 | 140 | example=False 141 | if example: 142 | #func(**ww.kwargs) 143 | def func(x,y,col="red"): 144 | print(x,y) 145 | return x+y 146 | 147 | ww=interactive(func,x=[1,10],y=[3,7],col=("red","blue")) 148 | ww 149 | 150 | ## --------------------------------------------------- 151 | print("... Redefining capture for ipywidgets < 7") 152 | 153 | import ipywidgets 154 | if ipywidgets._version.version_info[0]<7: 155 | from functools import wraps 156 | # ipywidgets.widgets.widget_output.Output.capture = capture 157 | # 158 | def capture(self, clear_output=False, *clear_args, **clear_kwargs): 159 | """ 160 | Decorator to capture the stdout and stderr of a function. 161 | Parameters 162 | ---------- 163 | clear_output: bool 164 | If True, clear the content of the output widget at every 165 | new function call. Default: False 166 | wait: bool 167 | If True, wait to clear the output until new output is 168 | available to replace it. This is only used if clear_output 169 | is also True. 170 | Default: False 171 | usage: 172 | >> from ipywidgets import widgets 173 | >> out = widgets.Output() 174 | >> @out.capture(clear_output=True, wait=True) 175 | ... FUNCTION 176 | >> display(widgets.VBox([slide_k, out])) 177 | """ 178 | def capture_decorator(func): 179 | @wraps(func) 180 | def inner(*args, **kwargs): 181 | if clear_output: 182 | self.clear_output(*clear_args, **clear_kwargs) 183 | with self: 184 | return func(*args, **kwargs) 185 | return inner 186 | return capture_decorator 187 | ipywidgets.widgets.widget_output.Output.capture = capture 188 | -------------------------------------------------------------------------------- /html/noisecancellation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/noisecancellation.jpg -------------------------------------------------------------------------------- /html/parole_bruitee.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/parole_bruitee.npz -------------------------------------------------------------------------------- /html/plot_rea.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon Feb 17 13:51:59 2014 4 | 5 | @author: JF 6 | """ 7 | def plot_rea(sig,nb=10,fig=None): 8 | """ 9 | Plot `nb` realizations of the random variable object `rv` 10 | 11 | Parameters 12 | ---------- 13 | rv: object 14 | the random variable array 15 | nb: number 16 | number of realizations to display 17 | Returns 18 | ------- 19 | Nothing 20 | Modules 21 | ------- 22 | import matplotlib.gridspec as gridspec 23 | from itertools import cycle 24 | 25 | Examples 26 | -------- 27 | >>> rv=stats.norm(loc=0,scale=1) 28 | >>> plot_rea() 29 | 30 | """ 31 | import numpy as np 32 | import scipy as sp 33 | import matplotlib.pyplot as plt 34 | import matplotlib.gridspec as gridspec 35 | from itertools import cycle 36 | 37 | plt.figure(fig); plt.clf() 38 | plt.suptitle("Realizations and means of a random signal",fontsize=14,color='blue') 39 | G = gridspec.GridSpec(12, 12) 40 | #fig=figure(figsize=(10,4)) 41 | ax1 = plt.subplot(G[0:9, 0:10]) 42 | ax2 = plt.subplot(G[10:12, 0:10]) 43 | ax3 = plt.subplot(G[0:9, 11:12]) 44 | 45 | 46 | (K,N)=np.shape(sig) 47 | sig_sampled=sig[np.random.randint(0,K,nb),:] 48 | deltaA=sig.max()-sig.min() 49 | yrea=deltaA*np.linspace(0,nb,nb) 50 | decalage=np.outer(yrea,np.ones(N)) 51 | sig_sampled_dec=sig_sampled+0.5*decalage 52 | 53 | ax1.xaxis.tick_top() 54 | ax1.plot(sig_sampled_dec.T) 55 | ax1.set_yticks(yrea/2)#, 56 | ax1.set_yticklabels([str(x) for x in list(range(1,nb+1))]) 57 | ax1.set_xlim([0,N]) 58 | fivepercent=(sig_sampled_dec.max()-sig_sampled_dec.min())/20 59 | ax1.set_ylim([sig_sampled_dec.min()-fivepercent, sig_sampled_dec.max()+fivepercent]) 60 | ax1.set_ylabel("Realizations",fontsize=14) 61 | 62 | msig0=np.mean(sig,axis=0) 63 | ax2.plot(msig0) 64 | ax2.set_xlim([0,N]) 65 | ax2.set_xlabel("Time",fontsize=14) 66 | ax2.annotate("Ensemble average", 67 | xy=(80,msig0[80]), 68 | xytext=(0.55,0.25), textcoords='figure fraction' 69 | # , 70 | # arrowprops=dict(arrowstyle="->", 71 | # color="green", 72 | # connectionstyle="arc3,rad=0.3", 73 | # shrinkA=10, shrinkB=10) 74 | ) 75 | # yticks([]) 76 | 77 | clist = plt.rcParams['axes.color_cycle'] 78 | colorcycler = cycle(clist) 79 | ax3.yaxis.tick_right() 80 | m_sig_sampled1=np.mean(sig_sampled,axis=1) 81 | for k in range(len(yrea)): 82 | ax3.plot(m_sig_sampled1[k],yrea[k]/2,'o', color=next(colorcycler)) #sig 83 | ax3.plot(np.mean(sig_sampled,axis=1),yrea/2, alpha=0.5) #sig 84 | ax3.set_ylim([sig_sampled_dec.min()-fivepercent, sig_sampled_dec.max()+fivepercent]) 85 | ax3.set_yticks(yrea/2)#, 86 | ax3.set_yticklabels([str(x) for x in list(range(1,nb+1))]) 87 | ax3.set_xticks([m_sig_sampled1.min(), m_sig_sampled1.max()]) 88 | ax3.set_xticklabels(["{0:2.2f}".format(m_sig_sampled1.min()), "{0:2.3f}".format(m_sig_sampled1.max())])#, 89 | ax3.annotate("Time \naverage", 90 | xy=(m_sig_sampled1[0],yrea[0]/2), #xycoords='figure fraction', 91 | xytext=(0.85,0.92), textcoords='figure fraction' 92 | #, 93 | # arrowprops=dict(arrowstyle="->", 94 | # color="blue", 95 | # connectionstyle="arc3,rad=0.3", 96 | # shrinkA=10, shrinkB=10) 97 | ) 98 | #ax3.set_xlim([0,N]) 99 | 100 | 101 | if __name__ == '__main__': 102 | import scipy.stats as stats 103 | import matplotlib.gridspec as gridspec 104 | from itertools import cycle 105 | # Used for arbitrary subplots, with possible aliasing between them and all that 106 | 107 | rv=stats.norm(loc=0,scale=1) 108 | size=(100,150) 109 | sig=rv.rvs(size=size) 110 | plot_rea(sig,nb=10,fig=1) 111 | -------------------------------------------------------------------------------- /html/plot_sighisto.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Tue Feb 18 10:01:53 2014 4 | 5 | @author: JF 6 | """ 7 | import matplotlib.gridspec as gridspec 8 | from pylab import * 9 | # Used for arbitrary subplots, with possible aliasing between them and all that 10 | 11 | 12 | def plot_sighisto(X,M=10,fig=None): 13 | figure(fig); clf() 14 | G = gridspec.GridSpec(12, 12) 15 | ax1 = subplot(G[0:8, 0:12]) 16 | ax2 = subplot(G[9:12, 0:12],sharex=ax1) 17 | #G.update(left=0.05, right=0.48, wspace=0.05) 18 | N=len(X) 19 | D=max(X)-min(X) 20 | ax1.plot(X,range(N)) 21 | ax1.set_ylabel('Time') 22 | ax1.axis([min(X)-D/10, max(X)+D/10, 0, N]) 23 | # make these tick labels invisible 24 | setp( ax1.get_xticklabels(), visible=False) 25 | (n,b,p)=plt.hist(X,M) 26 | ax2.hist(X,M) 27 | ax2.set_xlabel('Amplitude') 28 | ax2.set_ylim([0, 1.1*max(n)]) 29 | #ax2.axis([min(X)-D/10, max(X)+D/10, 0, 1.1*max(h)]) 30 | # Reset the bottom subplot to have xticks 31 | #setp(gca,'xtickMode', 'auto') 32 | 33 | 34 | if __name__ == '__main__': 35 | import scipy.stats as stats 36 | import matplotlib.gridspec as gridspec 37 | # Used for arbitrary subplots, with possible aliasing between them and all that 38 | rv=stats.norm(loc=0,scale=1) 39 | plot_sighisto(rv.rvs(200),fig=2) -------------------------------------------------------------------------------- /html/plt_LPtemplate.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | from numpy import pi 4 | 5 | def plt_LPtemplate(omega, A, Abounds=None): 6 | """omega contains the template frequencies [band-pass, band-stop] 7 | A contains the corresponding attenuations, Abounds, the y limits for the display 8 | """ 9 | [omegac, omegaa]=omega 10 | [Ac, Aa]=A 11 | if Abounds is None: 12 | delta=np.max(A)-np.min(A); Amax=np.max(A)+delta/5; Amin=np.min(A)-delta/5 13 | else: 14 | [Amax, Amin]=(Abounds) 15 | plt.plot([-omegac, -omegac, omegac, omegac],[Amin, Ac, Ac, Amin],'-', color='blue') 16 | plt.fill_between([-omegac, -omegac, omegac, omegac],[Amin, Ac, Ac, Amin], Amin, 17 | color='lightblue', alpha=0.6) 18 | 19 | plt.plot([-pi, -omegaa, -omegaa],[Aa, Aa, Amax],'-', color='blue') 20 | plt.fill_between([-pi, -omegaa, -omegaa],Amax, [Aa, Aa, Amax], color='lightblue', alpha=0.6) 21 | plt.plot([omegaa, omegaa,pi],[Amax, Aa, Aa],'-', color='blue') 22 | plt.fill_between([omegaa, omegaa,pi],Amax, [Amax, Aa, Aa],color='lightblue', alpha=0.6) 23 | plt.ylim([Amin, Amax]) 24 | plt.xlim([-pi, pi]) 25 | 26 | #plt.text(-3.7,0.4,'Fs/2', color='blue',fontsize=14) 27 | if __name__=="__main__": 28 | plt_LPtemplate([1, 1.84],[0, -20],Abounds=[5, -35]) -------------------------------------------------------------------------------- /html/saturne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/saturne.png -------------------------------------------------------------------------------- /html/saturne_vraie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/saturne_vraie.png -------------------------------------------------------------------------------- /html/sb1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/sb1.npz -------------------------------------------------------------------------------- /html/sb2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/sb2.npz -------------------------------------------------------------------------------- /html/sig1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/sig1.npz -------------------------------------------------------------------------------- /html/signal.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/signal.npz -------------------------------------------------------------------------------- /html/syssound.py: -------------------------------------------------------------------------------- 1 | def sysfileopen(filepath): 2 | import subprocess, os 3 | if sys.platform.startswith('darwin'): 4 | subprocess.call(('open', filepath)) 5 | elif os.name == 'nt': 6 | os.startfile(filepath) 7 | elif os.name == 'posix': 8 | # subprocess.call(('xdg-open', filepath)) 9 | subprocess.Popen(["xdg-open", filepath]) 10 | 11 | # Import useful read-write for wav files 12 | from scipy.io.wavfile import read as wavread, write as wavwrite 13 | 14 | def sound(var): 15 | from scipy.io.wavfile import write as wavwrite 16 | scaled = np.int16(var/np.max(np.abs(var)) * 32767) 17 | stmp=asarray(scaled,dtype=np.int16) 18 | wavwrite('stmp.wav',8820,stmp) 19 | sysfileopen("stmp.wav") 20 | -------------------------------------------------------------------------------- /html/test.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from zerospolesdisplay import * 3 | 4 | poles=np.array([0]) 5 | zeros=np.array([0.95*np.exp(1j*2*pi*0.4)]) 6 | A=ZerosPolesDisplay(poles,zeros) 7 | 8 | -------------------------------------------------------------------------------- /html/test_sound.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/test_sound.wav -------------------------------------------------------------------------------- /html/toc_and_cln.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | Created on Thu Nov 18 15:34:38 2014 4 | @author: JF 5 | """ 6 | 7 | import glob 8 | import os 9 | import sys 10 | import time 11 | from stat import * 12 | 13 | 14 | def texheaders_filtering(input_file): 15 | import re 16 | 17 | st = os.stat(input_file) 18 | atime = st[ST_ATIME] #access time 19 | mtime = st[ST_MTIME] #modification time 20 | 21 | with open(input_file,'rt') as f: 22 | text=f.read() 23 | #print(text) 24 | my_texfile = input_file #file.split('.html')[0] + 'b.html' 25 | if sys.version_info >= (3,0,0): 26 | my_texfile_desc = open(my_texfile, 'wt', newline='') 27 | else: 28 | my_texfile_desc = open(my_texfile_file, 'wt') 29 | 30 | 31 | def remp(intext): 32 | #out=re.findall('\\\\[sub]?section',intext.group(0)) 33 | out=re.findall('(\\\\[sub]?section|\\\\chapter)',intext.group(0)) 34 | 35 | print(out) 36 | """"print(out.group(0)) 37 | return out.group(0) """ 38 | return out[-1] 39 | 40 | #newtext=re.sub('section{Table of Contents}([\s\S]*?)\\[sub]?section{','Remplacement',text,flags=re.M) 41 | newtext=re.sub('\\\\section{Table of Contents}([\s\S]*?)(\\\\[sub]?section|\\\\chapter)',remp,text,flags=re.M) 42 | newtext=re.sub('\\\\begin{verbatim}[\s]*?[\s]*?\\\\end{verbatim}','',newtext,flags=re.M) 43 | newtext=re.sub('\\\\begin{verbatim}[\s]*?[\s]*?\\\\end{verbatim}','',newtext,flags=re.M) 44 | 45 | #bottom page with links to Index/back/next (suppress this) 46 | #'----[\s]*?
[Index](toc.ipynb)[\S ]*?.ipynb\)
' 47 | newtext=re.sub('\\\\begin{center}\\\\rule{3in}{0.4pt}\\\\end{center}[\s]*?\\\\href{toc.ipynb}{Index}[\S\s ]*?.ipynb}{Next}','',newtext,flags=re.M) 48 | 49 | 50 | # figcaption(text,label=) 51 | tofind="figcaption\(([\s\S]*?)\)\n([\s\S]*?)\\\\begin{center}\s*\\\\adjustimage[\s\S]*?}}{([\S]*?)}\s*\\\\end{center}" 52 | 53 | def replacement(text): 54 | cap=re.match("\"([\S\s]*?)\",[\S\s]*?label=\"([\S]*?)\"",text.group(1)) 55 | 56 | if cap==None: 57 | cap=re.match("\"([\S\s]*?)\"",text.group(1)) 58 | caption=cap.group(1) 59 | label="" 60 | rep="\n%s\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\linewidth]{%s}\n\\caption{%s}\n\\end{figure}" % (text.group(2),text.group(3),caption) 61 | else: 62 | caption=cap.group(1) 63 | label=cap.group(2) 64 | rep="\n%s\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\linewidth]{%s}\n\\caption{%s}\n\\label{%s}\n\\end{figure}" % (text.group(2),text.group(3),caption,label) 65 | return rep 66 | code="Init" 67 | 68 | while (code!=None): 69 | code=re.search(tofind,newtext) 70 | newtext=re.sub(tofind,replacement,newtext,flags=re.M) 71 | 72 | 73 | 74 | my_texfile_desc.write(newtext) 75 | 76 | #modify the file timestamp 77 | my_texfile_desc.close() 78 | os.utime(my_texfile,(atime,mtime)) 79 | 80 | 81 | 82 | 83 | 84 | verbose=True 85 | if __name__ == '__main__': 86 | import argparse 87 | 88 | whatitdoes="""This program filters a LaTeX file \n 89 | - in order to remove the first 'table of contents section', 90 | to the next section ; 91 | - it replaces figcaption structures to "\\caption{\\label{}}" LaTeX constructs. 92 | - Finally, it also filters out various 'spurious' outputs""" 93 | myself="(c) JFB 2014" 94 | parser = argparse.ArgumentParser(description=whatitdoes, epilog=myself) 95 | # mandatory argument 96 | parser.add_argument( 97 | help = 'List of files to filter (accepts regular expressions)', 98 | dest = 'argfiles', default = '*.tex', type = str, nargs = '*') 99 | # verbosity flag 100 | parser.add_argument('-v','--verbose', help = 'Prints information', 101 | dest = 'verbose', default = False, #action='store_true' 102 | action='count') 103 | 104 | arguments = parser.parse_args() 105 | verbose=arguments.verbose 106 | if verbose==2: print("script arg: ", arguments.argfiles) 107 | 108 | if isinstance(arguments.argfiles,list): 109 | tex_files=[] 110 | for x in arguments.argfiles: 111 | tex_files = tex_files+glob.glob(x) 112 | else: 113 | tex_files = glob.glob(arguments.argfiles) 114 | if verbose==2: print("glog.glog expansion: ", tex_files, '\n') 115 | if len(tex_files ) == 0: 116 | raise RuntimeError('No TeX files to convert.') 117 | 118 | for file in tex_files: 119 | if verbose: 120 | print("Filtering {}".format(file)) 121 | texheaders_filtering(file) 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /html/voix_outretombe.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/html/voix_outretombe.wav -------------------------------------------------------------------------------- /html/widgets_utils.ipy: -------------------------------------------------------------------------------- 1 | # From http://nbviewer.ipython.org/gist/anonymous/840b5cec9e19f3e39090 2 | hbox = lambda x: (x.remove_class("vbox"), x.add_class("hbox")) 3 | # 4 | frame = lambda x: x.set_css({ 5 | "border": "outset 1px", 6 | "padding": 5, 7 | "border-radius": 5, 8 | "display": "inline-box", 9 | "margin": "5px" 10 | }) 11 | 12 | # Example 13 | if __name__="__main__": 14 | c = widgets.CheckboxWidget(description="", value=True)#, width=100, font_size='14pt', fore_color='red') 15 | t = widgets.HTMLWidget(value="how solution with a very long text how to align on the left? how solution with a very long text how to align on the left? how solution with a very long text how to align on the left?") 16 | t.set_css({'font-size': 16, 'width':'80%', 'margin-top':4}) 17 | cont = widgets.ContainerWidget(children=[c,t]) 18 | 19 | frame(cont) 20 | display(cont) 21 | _=hbox(cont) -------------------------------------------------------------------------------- /html/widgets_utils.py: -------------------------------------------------------------------------------- 1 | from IPython.html import widgets 2 | from IPython.display import clear_output, display, HTML, Image, Javascript 3 | # From http://nbviewer.ipython.org/gist/anonymous/840b5cec9e19f3e39090 4 | hbox = lambda x: (x.remove_class("vbox"), x.add_class("hbox")) 5 | # 6 | frame = lambda x: x.set_css({ 7 | "border": "outset 1px", 8 | "padding": 5, 9 | "border-radius": 5, 10 | "display": "inline-box", 11 | "margin": "5px" 12 | }) 13 | 14 | # Example 15 | if __name__=="__main__": 16 | c = widgets.CheckboxWidget(description="", value=True)#, width=100, font_size='14pt', fore_color='red') 17 | t = widgets.HTMLWidget(value="how solution with a very long text how to align on the left? how solution with a very long text how to align on the left? how solution with a very long text how to align on the left?") 18 | t.set_css({'font-size': 16, 'width':'80%', 'margin-top':4}) 19 | cont = widgets.ContainerWidget(children=[c,t]) 20 | 21 | frame(cont) 22 | display(cont) 23 | _=hbox(cont) -------------------------------------------------------------------------------- /html/windows_disp.ipy: -------------------------------------------------------------------------------- 1 | def bigwidget_cbk(value,val): 2 | ll=dict() 3 | clear_output(wait=True) 4 | fig,ax=plt.subplots(2,1,figsize=(9,5)) 5 | for n in range(nb_lines): 6 | for k,wi in enumerate(windows[6*n:6*(n+1)]): 7 | ll[wi]=lw[n][k].value 8 | 9 | if lw[n][k].value: 10 | #plt.plot(sig.get_window(wi,200),label=wi) 11 | wn=sig.get_window(wi,50) 12 | ax[0].plot(wn,label=wi) 13 | wf=np.fft.fftshift(20*np.log10(abs(np.fft.fft(wn,1000)))) 14 | wf=wf-np.max(wf) #normalization 15 | wf[np.where(wf==-inf)]=-500 16 | f=np.linspace(-0.5,0.5,1000)*50 17 | ax[1].plot(f,wf,label=wi) 18 | ax[1].set_xlim([-5, 5]) 19 | ax[1].set_xticks(np.arange(-5,6)) 20 | #ax[1].set_xticklabels(['$\\frac{%d}{N}$' %x for x in np.arange(-5,6)]) 21 | ax[1].set_xticklabels([str(x) for x in np.arange(-5,6)]) 22 | ax[1].set_xlabel('Frequency (normalized by 1/N)') 23 | ax[1].set_ylabel('dB') 24 | ax[1].set_ylim([-150, 5]) 25 | ax[0].legend() 26 | ax[1].legend() 27 | #plt.legend() 28 | 29 | # plt_win(ll,windows) 30 | return ll 31 | 32 | 33 | def plt_win(ll,windows): 34 | fig,ax=plt.subplots(211) 35 | for k,tst in enumerate(ll): 36 | if tst: 37 | wn=sig.get_window(windows[k],50) 38 | #ax[0].plot(wn,label=windows[k]) 39 | #ax[1].plot(np.linspace(-0.5,0.5,1024),np.fft.fftshift(abs(np.fft.fft(wn,1024))),label=windows[k]) 40 | ax[0].legend() 41 | ax[1].legend() 42 | 43 | nb_lines=len(windows)//6+1 44 | 45 | lw=[None]*nb_lines 46 | wm=[None]*nb_lines 47 | 48 | for m in range(nb_lines): 49 | lw[m]=[widgets.CheckboxWidget(description=w) for w in windows[6*m:6*(m+1)]] 50 | for k,ww in enumerate(lw[m]): ww.on_trait_change(bigwidget_cbk,'value') 51 | wm[m]=widgets.ContainerWidget(children=lw[m]) 52 | 53 | 54 | t = widgets.HTMLWidget(value="Window functions") 55 | t.set_css({'color':'blue', 'font-size': 18, 'width':'80%', 56 | 'margin-top':8,'margin-bottom':8, 'text-align':'center'}) 57 | 58 | xx=widgets.ContainerWidget( 59 | children=[t]+[wm[k] for k in range(nb_lines)]) 60 | display(xx) 61 | for k in range(nb_lines): hbox(wm[k]) 62 | frame(xx) -------------------------------------------------------------------------------- /html/windows_disp_jup.ipy: -------------------------------------------------------------------------------- 1 | out = widgets.Output() 2 | 3 | @out.capture(clear_output=True, wait=True) 4 | def bigwidget_cbk(value): 5 | ll = dict() 6 | #clear_output(wait=True) 7 | fig, ax = plt.subplots(2, 1, figsize=(9, 5)) 8 | plot_exists = False 9 | for n in range(nb_lines): 10 | for k, wi in enumerate(windows[6 * n:6 * (n + 1)]): 11 | ll[wi] = lw[n][k].value 12 | 13 | if lw[n][k].value: 14 | #plt.plot(sig.get_window(wi,200),label=wi) 15 | wn = sig.get_window(wi, 50) 16 | ax[0].plot(wn, label=wi) 17 | wf = np.fft.fftshift(20 * np.log10(abs(np.fft.fft(wn, 1000)))) 18 | wf = wf - np.max(wf) #normalization 19 | wf[np.where(wf == -inf)] = -500 20 | f = np.linspace(-0.5, 0.5, 1000) * 50 21 | ax[1].plot(f, wf, label=wi) 22 | ax[1].set_xlim([-5, 5]) 23 | ax[1].set_xticks(np.arange(-5, 6)) 24 | #ax[1].set_xticklabels(['$\\frac{%d}{N}$' %x for x in np.arange(-5,6)]) 25 | ax[1].set_xticklabels([str(x) for x in np.arange(-5, 6)]) 26 | ax[1].set_xlabel('Frequency (normalized by 1/N)') 27 | ax[1].set_ylabel('dB') 28 | ax[1].set_ylim([-150, 5]) 29 | plot_exists = True 30 | if plot_exists: 31 | ax[0].legend() 32 | ax[1].legend() 33 | 34 | plt.show() 35 | 36 | return ll 37 | 38 | @out.capture(clear_output=True, wait=True) 39 | def plt_win(ll, windows): 40 | fig, ax = plt.subplots(211) 41 | for k, tst in enumerate(ll): 42 | if tst: 43 | wn = sig.get_window(windows[k], 50) 44 | #ax[0].plot(wn,label=windows[k]) 45 | #ax[1].plot(np.linspace(-0.5,0.5,1024),np.fft.fftshift(abs(np.fft.fft(wn,1024))),label=windows[k]) 46 | ax[0].legend() 47 | ax[1].legend() 48 | plt.show() 49 | 50 | 51 | nb_lines = len(windows) // 6 + 1 52 | 53 | lw = [None] * nb_lines 54 | wm = [None] * nb_lines 55 | 56 | for m in range(nb_lines): 57 | lw[m] = [ 58 | widgets.Checkbox(description=w) for w in windows[6 * m:6 * (m + 1)] 59 | ] 60 | for k, ww in enumerate(lw[m]): 61 | ww.observe(bigwidget_cbk, 'value') 62 | wm[m] = widgets.HBox(children=lw[m]) 63 | 64 | t = widgets.HTML( 65 | value="
Window functions
", 66 | color='blue', 67 | font_size=24, 68 | width='100%', 69 | margin=8, 70 | margin_bottom=8, 71 | align='center') 72 | #t.set_css({'color':'blue', 'font-size': 18, 'width':'80%', 73 | # 'margin-top':8,'margin-bottom':8, 'text-align':'center'}) 74 | 75 | tt = widgets.HBox(children=[t, ], width='100%', align='end') 76 | xx = widgets.VBox( 77 | children=[tt] + [wm[k] for k in range(nb_lines)], width='100%') 78 | xx.align = "start" 79 | xx.box_style = "info" 80 | xx.border_radius = 20 81 | xx.padding = 10 82 | 83 | display(widgets.VBox([xx, out])) 84 | 85 | -------------------------------------------------------------------------------- /html/zerospolesdisplay.py: -------------------------------------------------------------------------------- 1 | """ 2 | Zeros/Poles + impulse response + transfer function displays 3 | jfb 2015 - last update november 22, 2018 4 | """ 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | from numpy import pi 8 | 9 | 10 | #line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance 11 | 12 | class ZerosPolesDisplay(): 13 | 14 | def __init__(self,poles=np.array([0.7*np.exp(1j*2*np.pi*0.1)]), 15 | zeros=np.array([1.27*np.exp(1j*2*np.pi*0.3)]), 16 | N=1000, response_real=True, ymax=1.2, Nir=64): 17 | 18 | 19 | self.poles=poles 20 | self.zeros=zeros 21 | 22 | self.ymax=np.max([ymax, 1.2*np.max(np.concatenate((np.abs(poles), np.abs(zeros))))]) 23 | self.poles_th=np.angle(self.poles) 24 | self.poles_r=np.abs(self.poles) 25 | self.zeros_th=np.angle(self.zeros) 26 | self.zeros_r=np.abs(self.zeros) 27 | self.N=N 28 | self.Nir=Nir 29 | 30 | self.poles_line = None 31 | self.zeros_line = None 32 | self.setup_main_screen() 33 | 34 | 35 | 36 | def setup_main_screen(self): 37 | 38 | import matplotlib.gridspec as gridspec 39 | 40 | #Poles & zeros 41 | self.fig = plt.figure(figsize=(9,7)) 42 | gs = gridspec.GridSpec(3,12) 43 | #self.ax = self.fig.add_axes([0.1, 0.1, 0.77, 0.77], polar=True, facecolor='#d5de9c') 44 | #self.ax=self.fig.add_subplot(221,polar=True, facecolor='#d5de9c') 45 | self.ax = plt.subplot(gs[0:,0:6],polar=True,facecolor='#d5de9c') 46 | #self.ax = self.fig.add_subplot(111, polar=True) 47 | self.fig.suptitle('Poles & zeros adjustment',fontsize=18, color='blue', 48 | x=0.1, y=0.98, horizontalalignment='left') 49 | #self.ax.set_title('Poles & zeros adjustment',fontsize=16, color='blue') 50 | self.ax.set_ylim([0, self.ymax]) 51 | self.poles_line, = self.ax.plot(self.poles_th,self.poles_r,'ob',ms=9, picker=5, label="Poles") 52 | self.zeros_line, = self.ax.plot(self.zeros_th,self.zeros_r,'Dr',ms=9, picker=5, label="Zeros") 53 | self.ax.plot(np.linspace(-np.pi,np.pi,500),np.ones(500),'--b',lw=1) 54 | self.ax.legend() 55 | 56 | 57 | #Transfer function 58 | self.axTF0= plt.subplot(gs[0,6:11],facecolor='LightYellow') 59 | #self.axTF[0].set_axis_bgcolor('LightYellow') 60 | self.axTF0.set_title('Transfer function (modulus)') 61 | #self.axTF1=self.fig.add_subplot(224,facecolor='LightYellow') 62 | self.axTF1=plt.subplot(gs[1,6:11],facecolor='LightYellow') 63 | self.axTF1.set_title('Transfer function (phase)') 64 | self.axTF1.set_xlabel('Frequency') 65 | f=np.linspace(0,1,self.N) 66 | self.TF=np.fft.fft(np.poly(self.zeros),self.N)/np.fft.fft(np.poly(self.poles),self.N) 67 | self.TF_m_line, = self.axTF0.plot(f,np.abs(self.TF)) 68 | self.TF_p_line, = self.axTF1.plot(f,180/np.pi*np.angle(self.TF)) 69 | #self.figTF.canvas.draw() 70 | 71 | #Impulse response 72 | #self.figIR = plt.figure() 73 | #self.axIR = self.fig.add_subplot(223,facecolor='Lavender') 74 | self.axIR = plt.subplot(gs[2,6:11],facecolor='Lavender') 75 | self.IR= np.real(self.impz(self.zeros,self.poles,self.Nir)) #np.real(np.fft.ifft(self.TF)) 76 | self.axIR.set_title('Impulse response') 77 | self.axIR.set_xlabel('Time') 78 | self.IR_m_line, = self.axIR.plot(self.IR) 79 | #self.figIR.canvas.draw() 80 | self.fig.canvas.draw() 81 | self.fig.tight_layout() 82 | 83 | def impz(self,zeros,poles,L): 84 | from scipy.signal import lfilter 85 | a=np.poly(poles) 86 | b=np.poly(zeros) 87 | d=np.zeros(L) 88 | d[0]=1 89 | h=lfilter(b,a,d) 90 | return h 91 | 92 | 93 | if __name__=="__main__": 94 | #sym_comp([1+1j, 2, 3-2j]) 95 | #case of complex poles and zeros 96 | poles=np.array([0.8*np.exp(1j*2*pi*0.125), 0.8*np.exp(1j*2*pi*0.15), 0.5]) 97 | zeros=np.array([0.95*np.exp(1j*2*pi*0.175), 1.4*np.exp(1j*2*pi*0.3), 0]) 98 | A=ZerosPolesDisplay(poles,zeros) 99 | 100 | """ 101 | #case of a single real pole 102 | poles=np.array([0.5]) 103 | zeros=np.array([0]) 104 | A=ZerosPolesPlay(poles,zeros,response_real=False) 105 | """ 106 | 107 | #plt.show() 108 | -------------------------------------------------------------------------------- /html/zerospolesplay.py: -------------------------------------------------------------------------------- 1 | """ 2 | Transfer function adjustment using zeros and poles drag and drop! 3 | jfb 2015 - last update january 08, 2015 4 | """ 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | from numpy import pi 8 | 9 | 10 | #line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance 11 | 12 | class ZerosPolesPlay(): 13 | 14 | def __init__(self,poles=np.array([0.7*np.exp(1j*2*np.pi*0.1)]), 15 | zeros=np.array([1.27*np.exp(1j*2*np.pi*0.3)]), 16 | N=1000, response_real=True, ymax=1.2, Nir=64): 17 | 18 | if response_real: 19 | self.poles, self.poles_isreal = self.sym_comp(poles) 20 | self.zeros, self.zeros_isreal = self.sym_comp(zeros) 21 | else: 22 | self.poles=poles 23 | self.poles_isreal= (np.abs(np.imag(poles))<1e-12) 24 | self.zeros=zeros 25 | self.zeros_isreal =(np.abs(np.imag(zeros))<1e-12) 26 | 27 | self.ymax=np.max([ymax, 1.2*np.max(np.concatenate((np.abs(poles), np.abs(zeros))))]) 28 | self.poles_th=np.angle(self.poles) 29 | self.poles_r=np.abs(self.poles) 30 | self.zeros_th=np.angle(self.zeros) 31 | self.zeros_r=np.abs(self.zeros) 32 | self.N=N 33 | self.Nir=Nir 34 | self.response_real=response_real 35 | 36 | self.being_dragged = None 37 | self.nature_dragged = None 38 | self.poles_line = None 39 | self.zeros_line = None 40 | self.setup_main_screen() 41 | self.connect() 42 | self.update() 43 | 44 | 45 | def setup_main_screen(self): 46 | 47 | import matplotlib.gridspec as gridspec 48 | 49 | #Poles & zeros 50 | self.fig = plt.figure() 51 | gs = gridspec.GridSpec(3,12) 52 | #self.ax = self.fig.add_axes([0.1, 0.1, 0.77, 0.77], polar=True, facecolor='#d5de9c') 53 | #self.ax=self.fig.add_subplot(221,polar=True, facecolor='#d5de9c') 54 | self.ax = plt.subplot(gs[0:,0:6],polar=True,facecolor='#d5de9c') 55 | #self.ax = self.fig.add_subplot(111, polar=True) 56 | self.fig.suptitle('Poles & zeros adjustment',fontsize=18, color='blue', 57 | x=0.1, y=0.98, horizontalalignment='left') 58 | #self.ax.set_title('Poles & zeros adjustment',fontsize=16, color='blue') 59 | self.ax.set_ylim([0, self.ymax]) 60 | self.poles_line, = self.ax.plot(self.poles_th,self.poles_r,'ob',ms=9, picker=5, label="Poles") 61 | self.zeros_line, = self.ax.plot(self.zeros_th,self.zeros_r,'Dr',ms=9, picker=5, label="Zeros") 62 | self.ax.plot(np.linspace(-np.pi,np.pi,500),np.ones(500),'--b',lw=1) 63 | self.ax.legend(loc=1) 64 | 65 | 66 | #Transfer function 67 | #self.figTF, self.axTF = plt.subplots(2, sharex=True) 68 | #self.axTF0=self.fig.add_subplot(222,facecolor='LightYellow') 69 | self.axTF0= plt.subplot(gs[0,6:11],facecolor='LightYellow') 70 | #self.axTF[0].set_axis_bgcolor('LightYellow') 71 | self.axTF0.set_title('Transfer function (modulus)') 72 | #self.axTF1=self.fig.add_subplot(224,facecolor='LightYellow') 73 | self.axTF1=plt.subplot(gs[1,6:11],facecolor='LightYellow') 74 | self.axTF1.set_title('Transfer function (phase)') 75 | self.axTF1.set_xlabel('Frequency') 76 | f=np.linspace(0,1,self.N) 77 | self.TF=np.fft.fft(np.poly(self.zeros),self.N)/np.fft.fft(np.poly(self.poles),self.N) 78 | self.TF_m_line, = self.axTF0.plot(f,np.abs(self.TF)) 79 | self.TF_p_line, = self.axTF1.plot(f,180/np.pi*np.angle(self.TF)) 80 | #self.figTF.canvas.draw() 81 | 82 | #Impulse response 83 | #self.figIR = plt.figure() 84 | #self.axIR = self.fig.add_subplot(223,facecolor='Lavender') 85 | self.axIR = plt.subplot(gs[2,6:11],facecolor='Lavender') 86 | self.IR= self.impz(self.zeros,self.poles,self.Nir) #np.real(np.fft.ifft(self.TF)) 87 | self.axIR.set_title('Impulse response') 88 | self.axIR.set_xlabel('Time') 89 | self.IR_m_line, = self.axIR.plot(self.IR) 90 | #self.figIR.canvas.draw() 91 | self.fig.canvas.draw() 92 | self.fig.tight_layout() 93 | 94 | def impz(self,zeros,poles,L): 95 | from scipy.signal import lfilter 96 | a=np.poly(poles) 97 | b=np.poly(zeros) 98 | d=np.zeros(L) 99 | d[0]=1 100 | h=lfilter(b,a,d) 101 | return h 102 | 103 | def sym_comp(self,p): 104 | L=np.size(p) 105 | r=list() 106 | c=list() 107 | for z in p: 108 | if np.abs(np.imag(z))<1e-12: 109 | r.append(z) 110 | else: 111 | c.append(z) 112 | out=np.concatenate((c,r,np.conjugate(c[::-1]))) 113 | isreal=(np.abs(np.imag(out))<1e-12) 114 | return out,isreal 115 | #sym_comp([1+1j, 2, 3-2j]) 116 | 117 | def connect(self): 118 | self.cidpick = self.fig.canvas.mpl_connect( 119 | 'pick_event', self.on_pick) 120 | self.cidrelease = self.fig.canvas.mpl_connect( 121 | 'button_release_event', self.on_release) 122 | self.cidmotion = self.fig.canvas.mpl_connect( 123 | 'motion_notify_event', self.on_motion) 124 | 125 | def update(self): 126 | 127 | #poles and zeros 128 | #self.fig.canvas.draw() 129 | 130 | #Transfer function & Impulse response 131 | if not(self.being_dragged is None): 132 | #print("Was released") 133 | 134 | f=np.linspace(0,1,self.N) 135 | self.TF=np.fft.fft(np.poly(self.zeros),self.N)/np.fft.fft(np.poly(self.poles),self.N) 136 | self.TF_m_line.set_ydata(np.abs(self.TF)) 137 | M=np.max(np.abs(self.TF)) 138 | #update the yscale 139 | current_ylim=self.axTF0.get_ylim()[1] 140 | if M>current_ylim or M<0.5*current_ylim: self.axTF0.set_ylim([0, 1.2*M]) 141 | 142 | #phase 143 | self.TF_p_line.set_ydata(180/np.pi*np.angle(self.TF)) 144 | #self.figTF.canvas.draw() 145 | 146 | # Impulse response 147 | self.IR=self.impz(self.zeros,self.poles,self.Nir) #np.fft.ifft(self.TF) 148 | #print(self.IR) 149 | self.IR_m_line.set_ydata(self.IR) 150 | M=np.max(self.IR) 151 | Mm=np.min(self.IR) 152 | #update the yscale 153 | current_ylim=self.axIR.get_ylim() 154 | update_ylim=False 155 | if M>current_ylim[1] or M<0.5*current_ylim[1]: update_ylim=True 156 | if Mm0.5*np.abs(current_ylim[0]): update_ylim=True 157 | if update_ylim: self.axIR.set_ylim([Mm, 1.2*M]) 158 | 159 | #self.figIR.canvas.draw() 160 | self.fig.canvas.draw() 161 | 162 | 163 | def on_pick(self, event): 164 | """When we click on the figure and hit either the line or the menu items this gets called.""" 165 | if event.artist != self.poles_line and event.artist != self.zeros_line: 166 | return 167 | self.being_dragged = event.ind[0] 168 | self.nature_dragged = event.artist 169 | 170 | 171 | def on_motion(self, event): 172 | """Move the selected points and update the graphs.""" 173 | if event.inaxes != self.ax: return 174 | if self.being_dragged is None: return 175 | p = self.being_dragged #index of points on the line being dragged 176 | xd = event.xdata 177 | yd = event.ydata 178 | #print(yd) 179 | if self.nature_dragged==self.poles_line: 180 | x,y = self.poles_line.get_data() 181 | if not (self.poles_isreal[p]): 182 | x[p],y[p]=xd,yd 183 | else: 184 | if np.pi/2 2 | 3 | 4 | 22 | 23 | */ 24 | 25 | 26 | /***************************************************************** 27 | LaTeX things 28 | *****************************************************************/ 29 | 30 | .latex_tmp {text-align: justify;} 31 | 32 | .latex_prob, 33 | .latex_examp, 34 | .latex_excs, 35 | .latex_problem, 36 | .latex_example, 37 | .latex_exercise, 38 | .latex_proof { 39 | font-style: normal; 40 | text-align: justify; 41 | margin-left: 0px; 42 | margin-right: 10px; 43 | margin-top: 0px; 44 | margin-bottom: 0px; 45 | background-color: #CCFFCC; 46 | display: block; 47 | } 48 | 49 | .latex_title { 50 | float: left; 51 | font-weight: bold; 52 | padding-right: 10px; 53 | } 54 | 55 | .latex_proofend { 56 | float: right; 57 | } 58 | 59 | .latex_listing { 60 | display: block; 61 | text-align: justify; 62 | margin-right: 30px; 63 | font-family: 'Lucida Sans Typewriter'; 64 | color:black; 65 | background-color: GhostWhite ; 66 | } 67 | 68 | .rendered_html pre, .rendered_html code { 69 | border: 0; 70 | background-color: rgba(161, 139, 139, 0); 71 | /* color: #000; */ 72 | font-size: 100%; 73 | padding: 0; 74 | } 75 | 76 | 77 | .latex_thm, .latex_theorem, .latex_lem, .latex_cor, .latex_defn, .latex_prop, .latex_rem, .latex_property, 78 | .latex_lemma, .latex_corollary, .latex_definition, .latex_proposition, .latex_remark, .latex_proof { 79 | 80 | display: block; 81 | text-align: justify; 82 | margin-right: 10px; 83 | margin-left: 0px; 84 | margin-top: 0px; 85 | margin-bottom: 0px; 86 | font-style: italic; 87 | color:black; 88 | background-color: beige; 89 | } 90 | 91 | .latex_textboxa { 92 | display: block; 93 | font-weight: bold; 94 | text-align: center; 95 | width: 80%; 96 | margin: auto; 97 | border: 2px solid; 98 | padding-top: 5px; 99 | padding-bottom: 5px; 100 | background-color: #f2dede; 101 | border-color: #eed3d7; 102 | color: #CC0099; 103 | border-radius: 8px; 104 | -webkit-border-radius: 8px; 105 | -moz-border-radius: 8px; 106 | border-radius: 8px 107 | } 108 | 109 | img.latex_img { 110 | display: block; 111 | margin: auto; 112 | /*height: XXXpx; /* */ 113 | width: 75%; 114 | } 115 | 116 | p.latex_img { 117 | display: block; 118 | width: 85%; 119 | margin: auto; 120 | text-align: justify; 121 | } 122 | 123 | /***************************************************************** 124 | GENERAL CONFIG 125 | *****************************************************************/ 126 | 127 | 128 | @font-face { 129 | font-family: "Computer Modern"; 130 | src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunss.otf'); 131 | } 132 | 133 | @font-face { 134 | font-family: "Computer Modern"; 135 | font-weight: bold; 136 | src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsx.otf'); 137 | } 138 | @font-face { 139 | font-family: "Computer Modern"; 140 | font-style: oblique; 141 | src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsi.otf'); 142 | } 143 | */ 144 | /* @font-face { 145 | font-family: "Computer Modern"; 146 | font-style: Typewriter; 147 | src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmuntt.otf'); 148 | }*/ 149 | 150 | @font-face { 151 | font-family: "Computer Modern"; 152 | font-weight: bold; 153 | font-style: oblique; 154 | src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunso.otf'); 155 | } 156 | 157 | 158 | div.cell{ 159 | width:100%; 160 | margin-left:auto; /*16% !important;* was preconised but pbs with some browsers*/ 161 | margin-right:auto; 162 | } 163 | h1 { 164 | font-family: Helvetica, serif; 165 | } 166 | h2 { 167 | font-family: Helvetica, serif; 168 | color: darkblue; 169 | } 170 | 171 | h4{ 172 | margin-top:12px; 173 | margin-bottom: 3px; 174 | } 175 | 176 | 177 | .rendered_html p {text-align:justify} 178 | 179 | div.text_cell_render{ 180 | font-family: "Computer Modern", Arial, "Helvetica Neue", Helvetica, Geneva, sans-serif; 181 | line-height: 145%; 182 | font-size: 130%; 183 | color: black; 184 | width:100%; 185 | /*width:800px;*/ 186 | margin-left:0px; 187 | margin-right:auto; 188 | 189 | } 190 | .CodeMirror{ 191 | font-family: "Source Code Pro", source-code-pro,Consolas, monospace; 192 | color: darkblue; 193 | } 194 | 195 | /* commented because many people prefer to have the prompt 196 | .prompt{ 197 | display: None; 198 | } 199 | */ 200 | 201 | /* 202 | div.output_area 203 | { 204 | display: block; 205 | margin-left: auto; 206 | margin-right: auto 207 | } 208 | */ 209 | div.output_subarea.output_text 210 | { 211 | margin-left: +2%; 212 | } 213 | 214 | div.output_subarea.output_png 215 | { 216 | margin-left: +10%; 217 | } 218 | div.output_subarea.output_svg 219 | { 220 | margin-left: +10%; 221 | } 222 | 223 | 224 | .text_cell_render h5 { 225 | font-weight: 300; 226 | font-size: 22pt; 227 | color: #4057A1; 228 | font-style: italic; 229 | margin-bottom: .5em; 230 | margin-top: 0.5em; 231 | display: block; 232 | } 233 | 234 | .warning{ 235 | color: rgb( 240, 20, 20 ) 236 | } 237 | 238 | 239 | 240 | -------------------------------------------------------------------------------- /local_repo_update: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This is to update a git repo from master, overwriting local modifications 3 | # if merge is not possible automatically 4 | # source: http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull 5 | # author jfb september 23, 2015 6 | 7 | # 0 - restore deleted files 8 | 9 | git ls-files -d -z | xargs -0 git checkout -- 10 | 11 | 12 | #first do a commit of your changes 13 | 14 | git add * 15 | git commit -a -m "local changes" 16 | 17 | #then fetch the changes and overwrite if there is a conflict 18 | 19 | git fetch origin master 20 | git merge -s recursive -X theirs origin/master -m "merge with local changes" 21 | -------------------------------------------------------------------------------- /local_repo_update_ensg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # This is to update a git repo from master, overwriting local modifications 3 | # if merge is not possible automatically 4 | # source: http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull 5 | # author jfb september 23, 2015 6 | 7 | # set proxies 8 | export http_proxy=http://10.0.4.2:3128 9 | export https_proxy=http://10.0.4.2:3128 10 | 11 | # 0 - restore deleted files 12 | 13 | git ls-files -d -z | xargs -0 git checkout -- 14 | 15 | 16 | #first do a commit of your changes 17 | 18 | git add * 19 | git commit -a -m "local changes" 20 | 21 | #then fetch the changes and overwrite if there is a conflict 22 | 23 | git fetch origin master 24 | git merge -s recursive -X theirs origin/master -m "merge with local changes" 25 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pandas 2 | numpy 3 | matplotlib 4 | scipy 5 | seaborn 6 | mpld3 7 | -------------------------------------------------------------------------------- /sp_download: -------------------------------------------------------------------------------- 1 | #/usr/bin/env bash 2 | 3 | #export https_proxy=10.0.4.2:3128 #ensg 4 | rm Lectures_SignalProcessing.zip 5 | if [ -d "./Lectures_SignalProcessing" ]; then 6 | rm -r Lectures_SignalProcessing/ 7 | fi 8 | wget -N http://www.esiee.fr/~bercherj/Documents/Lectures_SignalProcessing.zip 9 | unzip -o Lectures_SignalProcessing.zip 10 | -------------------------------------------------------------------------------- /src/DigitalFilters.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Digital filters" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "### Introduction" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "To be continued" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "### The z-transform" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "To be continued" 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "\n", 43 | "----\n", 44 | "
[Index](toc.ipynb) - [Back](LabImages_correction.ipynb) - [Next](ZerosPoles.ipynb)
" 45 | ] 46 | } 47 | ], 48 | "metadata": { 49 | "hide_input": false, 50 | "kernelspec": { 51 | "display_name": "Python 3", 52 | "language": "python", 53 | "name": "python3" 54 | }, 55 | "language_info": { 56 | "codemirror_mode": { 57 | "name": "ipython", 58 | "version": 3 59 | }, 60 | "file_extension": ".py", 61 | "mimetype": "text/x-python", 62 | "name": "python", 63 | "nbconvert_exporter": "python", 64 | "pygments_lexer": "ipython3", 65 | "version": "3.5.0" 66 | }, 67 | "latex_envs": { 68 | "LaTeX_envs_menu_present": true, 69 | "autoclose": false, 70 | "autocomplete": true, 71 | "bibliofile": "biblio.bib", 72 | "cite_by": "apalike", 73 | "current_citInitial": 1, 74 | "eqLabelWithNumbers": true, 75 | "eqNumInitial": 0, 76 | "hotkeys": { 77 | "equation": "ctrl-e" 78 | }, 79 | "labels_anchors": false, 80 | "latex_user_defs": false, 81 | "report_style_numbering": false, 82 | "user_envs_cfg": false 83 | }, 84 | "nbTranslate": { 85 | "displayLangs": [ 86 | "*" 87 | ], 88 | "hotkey": "alt-t", 89 | "langInMainMenu": true, 90 | "sourceLang": "en", 91 | "targetLang": "fr", 92 | "useGoogleTranslate": true 93 | }, 94 | "pyVarInspector": { 95 | "cols": { 96 | "lenName": 16, 97 | "lenType": 16, 98 | "lenVar": 40 99 | }, 100 | "types_to_exclude": [ 101 | "module", 102 | "function", 103 | "builtin_function_or_method", 104 | "instance", 105 | "_Feature" 106 | ], 107 | "window_display": false 108 | }, 109 | "toc": { 110 | "base_numbering": 1, 111 | "nav_menu": { 112 | "height": "68px", 113 | "width": "252px" 114 | }, 115 | "number_sections": true, 116 | "sideBar": true, 117 | "skip_h1_title": false, 118 | "title_cell": "Table of Contents", 119 | "title_sidebar": "Contents", 120 | "toc_cell": false, 121 | "toc_position": {}, 122 | "toc_section_display": "block", 123 | "toc_window_display": false 124 | }, 125 | "varInspector": { 126 | "cols": { 127 | "lenName": 16, 128 | "lenType": 16, 129 | "lenVar": 40 130 | }, 131 | "kernels_config": { 132 | "python": { 133 | "delete_cmd_postfix": "", 134 | "delete_cmd_prefix": "del ", 135 | "library": "var_list.py", 136 | "varRefreshCmd": "print(var_dic_list())" 137 | }, 138 | "r": { 139 | "delete_cmd_postfix": ") ", 140 | "delete_cmd_prefix": "rm(", 141 | "library": "var_list.r", 142 | "varRefreshCmd": "cat(var_dic_list()) " 143 | } 144 | }, 145 | "types_to_exclude": [ 146 | "module", 147 | "function", 148 | "builtin_function_or_method", 149 | "instance", 150 | "_Feature" 151 | ], 152 | "window_display": false 153 | } 154 | }, 155 | "nbformat": 4, 156 | "nbformat_minor": 1 157 | } 158 | -------------------------------------------------------------------------------- /src/ExamplesApplications.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/ExamplesApplications.gif -------------------------------------------------------------------------------- /src/ExamplesApplications.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/ExamplesApplications.png -------------------------------------------------------------------------------- /src/Exercises_BasicSystemsRepr.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Basic representations for digital signals and systems\n" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "Par [J.-F. Bercher](http://www.esiee.fr/~bercherj) -- march 5, 2014
\n" 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | ">This lab is an elementary introduction to the analysis of a filtering operation. In particular, we will illustrate the notions of impulse response, convolution, frequency representation transfer function.\n", 22 | "\n", 23 | ">In these exercises, we will work with digital signals. Experiments will be done with Python. \n", 24 | "\n", 25 | ">We will work with the filtering operation described by the following difference equation\n", 26 | "$$\n", 27 | "y(n)=a y(n-1) + x(n)\n", 28 | "$$\n", 29 | "where $x(n)$ is the filter's input and $y(n)$ its output." 30 | ] 31 | }, 32 | { 33 | "cell_type": "markdown", 34 | "metadata": {}, 35 | "source": [ 36 | "## Study in the time domain" 37 | ] 38 | }, 39 | { 40 | "cell_type": "markdown", 41 | "metadata": {}, 42 | "source": [ 43 | ">1. Compute analytically the impuse response (IR), as a function of the parameter $a$, assuming that the system is causal and that the initial conditions are zero.\n", 44 | ">2. Under Python, look at the help of function lfilter, by `help(lfilter)` and try to understand how it works. Propose a method for computing numerically the impulse response. Then, check graphically the impulse response, with $a = 0.8$. The following Dirac function enables to generate a Dirac impulse in discrete time: \n", 45 | " def dirac(n):\n", 46 | " \"\"\" dirac(n): returns a Dirac impulse on N points\"\"\"\n", 47 | " d=zeros(n); d[0]=1\n", 48 | " return d\n", 49 | "\n", 50 | ">3. Compute and plot the impulse responses for $a=-0.8$, $a=0.99$, and $a=1.01$. Conclusions." 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "## Study in the fequency domain\n" 58 | ] 59 | }, 60 | { 61 | "cell_type": "markdown", 62 | "metadata": {}, 63 | "source": [ 64 | ">2. Give the expression of the transfer function $H(f)$, and of its modulus $|H(f)|$ for any $a$. Give the theoretical amplitudes at $f = 0$ and $f = 1/2$ (in normalized frequencies, _i.e._ normalized with respect to Fe. Compute numerically the transfer function as the Fourier transform of the impulse response, for $a = 0.8$ and $a = -0.8$, and plot the results. Conclusions." 65 | ] 66 | }, 67 | { 68 | "cell_type": "markdown", 69 | "metadata": {}, 70 | "source": [ 71 | "Filtering\n", 72 | "============\n", 73 | ">1. Create a sine wave $x$ of frequency $f0 = 3$, sampled at $Fe = 32$ on $N=128$ points \n", 74 | "\n", 75 | ">2. Filter this sine wave by the previous filter\n", 76 | "\n", 77 | "> – using the function filter, y1=lfilter([1],[1 -0.8],x); \n", 78 | "\n", 79 | "> – using a convolution, y2=lfilter(h,1,x); with $h$ the impulse response of the filter for $a = 0.8$ \n", 80 | "> Explain why this last operation effectively corresponds to a convolution. Compare the two results. \n", 81 | "\n", 82 | ">3. Plot the transfer function and the Fourier transform of the sine wave. What will be the result of the product? Measure the gain and phase of the transfer function at the frequency of the sinusoid ($f_0=3$). Compare these values to the values of gain and phase measured in the time domain. \n", 83 | "\n", 84 | ">4. Do this experiment again, but with a pulse train instead of a sine. This is done simply in order to illustrate the fact that this time, the output of the filter is deformed. You may use\n", 85 | " def rectpulse(x):\n", 86 | " \"\"\"rectpulse(x): \n", 87 | " Returns a pulse train with period 2pi\"\"\"\n", 88 | " return sign(sin(x)) " 89 | ] 90 | } 91 | ], 92 | "metadata": { 93 | "hide_input": false, 94 | "interactive_sols": { 95 | "cbx_id": 1 96 | }, 97 | "kernelspec": { 98 | "display_name": "Python 3", 99 | "language": "python", 100 | "name": "python3" 101 | }, 102 | "language_info": { 103 | "codemirror_mode": { 104 | "name": "ipython", 105 | "version": 3 106 | }, 107 | "file_extension": ".py", 108 | "mimetype": "text/x-python", 109 | "name": "python", 110 | "nbconvert_exporter": "python", 111 | "pygments_lexer": "ipython3", 112 | "version": "3.5.0" 113 | }, 114 | "latex_envs": { 115 | "LaTeX_envs_menu_present": true, 116 | "autoclose": false, 117 | "autocomplete": true, 118 | "bibliofile": "biblio.bib", 119 | "cite_by": "apalike", 120 | "current_citInitial": 1, 121 | "eqLabelWithNumbers": true, 122 | "eqNumInitial": 0, 123 | "hotkeys": { 124 | "equation": "ctrl-e" 125 | }, 126 | "labels_anchors": false, 127 | "latex_user_defs": false, 128 | "report_style_numbering": false, 129 | "user_envs_cfg": false 130 | }, 131 | "nbTranslate": { 132 | "displayLangs": [ 133 | "*" 134 | ], 135 | "hotkey": "alt-t", 136 | "langInMainMenu": true, 137 | "sourceLang": "en", 138 | "targetLang": "fr", 139 | "useGoogleTranslate": true 140 | }, 141 | "toc": { 142 | "base_numbering": "1", 143 | "nav_menu": { 144 | "height": "98px", 145 | "width": "252px" 146 | }, 147 | "number_sections": true, 148 | "sideBar": true, 149 | "skip_h1_title": false, 150 | "title_cell": "Table of Contents", 151 | "title_sidebar": "Contents", 152 | "toc_cell": false, 153 | "toc_position": {}, 154 | "toc_section_display": "block", 155 | "toc_window_display": false 156 | } 157 | }, 158 | "nbformat": 4, 159 | "nbformat_minor": 1 160 | } 161 | -------------------------------------------------------------------------------- /src/GenericWiener.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/GenericWiener.gif -------------------------------------------------------------------------------- /src/GenericWiener.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/GenericWiener.png -------------------------------------------------------------------------------- /src/SystemIdentification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/SystemIdentification.png -------------------------------------------------------------------------------- /src/bacteria.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/bacteria.png -------------------------------------------------------------------------------- /src/barbara.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/barbara.png -------------------------------------------------------------------------------- /src/cellules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/cellules.png -------------------------------------------------------------------------------- /src/conv_optfilter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/conv_optfilter.jpg -------------------------------------------------------------------------------- /src/conv_optfilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/conv_optfilter.png -------------------------------------------------------------------------------- /src/correlation.py: -------------------------------------------------------------------------------- 1 | """ 2 | .. topic:: Correlation module 3 | 4 | 5 | Provides two correlation functions. :func:`CORRELATION` is slower than 6 | :func:`xcorr`. However, the output is as expected by some other functions. 7 | Ultimately, it should be replaced by :func:`xcorr`. 8 | 9 | For real data, the behaviour of the 2 functions is identical. However, for 10 | complex data, xcorr returns a 2-sides correlation. 11 | 12 | 13 | .. autosummary:: 14 | 15 | ~spectrum.correlation.CORRELATION 16 | ~spectrum.correlation.xcorr 17 | 18 | .. codeauthor: Thomas Cokelaer, 2011 19 | 20 | 21 | 22 | """#from numpy.fft import fft, ifft 23 | import numpy 24 | from numpy import arange, isrealobj 25 | from pylab import rms_flat 26 | 27 | __all__ = ['CORRELATION', 'xcorr'] 28 | 29 | 30 | def CORRELATION(x, y=None, maxlags=None, norm='unbiased'): 31 | r"""Correlation function 32 | 33 | This function should give the same results as :func:`xcorr` but it 34 | returns the positive lags only. Moreover the algorithm does not use 35 | FFT as compared to other algorithms. 36 | 37 | :param array x: first data array of length N 38 | :param array y: second data array of length N. If not specified, computes the 39 | autocorrelation. 40 | :param int maxlags: compute cross correlation between [0:maxlags] 41 | when maxlags is not specified, the range of lags is [0:maxlags]. 42 | :param str norm: normalisation in ['biased', 'unbiased', None, 'coeff'] 43 | 44 | * *biased* correlation=raw/N, 45 | * *unbiased* correlation=raw/(N-`|lag|`) 46 | * *coeff* correlation=raw/(rms(x).rms(y))/N 47 | * None correlation=raw 48 | 49 | :return: 50 | * a numpy.array correlation sequence, r[1,N] 51 | * a float for the zero-lag correlation, r[0] 52 | 53 | The *unbiased* correlation has the form: 54 | 55 | .. math:: 56 | 57 | \hat{r}_{xx} = \frac{1}{N-m}T \sum_{n=0}^{N-m-1} x[n+m]x^*[n] T 58 | 59 | The *biased* correlation differs by the front factor only: 60 | 61 | .. math:: 62 | 63 | \check{r}_{xx} = \frac{1}{N}T \sum_{n=0}^{N-m-1} x[n+m]x^*[n] T 64 | 65 | with :math:`0\leq m\leq N-1`. 66 | 67 | .. doctest:: 68 | 69 | >>> from spectrum import * 70 | >>> x = [1,2,3,4,5] 71 | >>> res = CORRELATION(x,x, maxlags=0, norm='biased') 72 | >>> res[0] 73 | 11.0 74 | 75 | .. note:: this function should be replaced by :func:`xcorr`. 76 | 77 | .. seealso:: :func:`xcorr` 78 | """ 79 | assert norm in ['unbiased','biased', 'coeff', None] 80 | #transform lag into list if it is an integer 81 | if y is None: 82 | y = x 83 | 84 | # N is the max of x and y 85 | N = max(len(x), len(y)) 86 | if len(x)>> from spectrum import * 182 | >>> x = [1,2,3,4,5] 183 | >>> c, l = xcorr(x,x, maxlags=0, norm='biased') 184 | >>> c 185 | array([ 11.]) 186 | 187 | .. seealso:: :func:`CORRELATION`. 188 | """ 189 | N = len(x) 190 | if y is None: 191 | y = x 192 | assert len(x) == len(y), 'x and y must have the same length. Add zeros if needed' 193 | #jfb#assert maxlags <= N, 'maxlags must be less than data length' 194 | 195 | if maxlags is None: 196 | maxlags = N-1 197 | lags = arange(0, 2*N-1) 198 | else: 199 | assert maxlags < N 200 | lags = arange(N-maxlags-1, N+maxlags) 201 | 202 | res = numpy.correlate(x, y, mode='full') 203 | 204 | if norm == 'biased': 205 | Nf = float(N) 206 | res = res[lags] / float(N) # do not use /= !! 207 | elif norm == 'unbiased': 208 | res = res[lags] / (float(N)-abs(arange(-N+1, N)))[lags] 209 | elif norm == 'coeff': 210 | Nf = float(N) 211 | rms = rms_flat(x) * rms_flat(y) 212 | res = res[lags] / rms / Nf 213 | else: 214 | res = res[lags] 215 | 216 | lags = arange(-maxlags, maxlags+1) 217 | return res, lags 218 | -------------------------------------------------------------------------------- /src/decticelle.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/decticelle.npz -------------------------------------------------------------------------------- /src/ecg.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/ecg.npy -------------------------------------------------------------------------------- /src/fig_filter1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/fig_filter1.png -------------------------------------------------------------------------------- /src/fig_filter2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/fig_filter2.png -------------------------------------------------------------------------------- /src/fig_template.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/fig_template.jpg -------------------------------------------------------------------------------- /src/fig_template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/fig_template.png -------------------------------------------------------------------------------- /src/flatten.py: -------------------------------------------------------------------------------- 1 | #Flattening a list of list 2 | #from http://rightfootin.blogspot.fr/2006/09/more-on-python-flatten.html which derives 3 | #from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/363051 4 | def flatten(l, ltypes=(list, tuple)): 5 | ltype = type(l) 6 | l = list(l) 7 | i = 0 8 | while i < len(l): 9 | while isinstance(l[i], ltypes): 10 | if not l[i]: 11 | l.pop(i) 12 | i -= 1 13 | break 14 | else: 15 | l[i:i + 1] = l[i] 16 | i += 1 17 | return ltype(l) 18 | 19 | flatten(lw) -------------------------------------------------------------------------------- /src/interactive_sols.ipy: -------------------------------------------------------------------------------- 1 | 2 | ### ------------ interactive solutions: showing and hiding cells 3 | 4 | override_runrange=""" 5 | /* Override original execute-range function */ 6 | console.log("Overriding run-range javascript function"); 7 | IPython.Notebook.prototype.execute_cell_range = function (start, end) { 8 | this.command_mode(); 9 | for (var i=start; i 61 | 72 | """ 73 | 74 | # myhchboxb is a pretty checkbox with css 75 | myhchboxb = """ 76 |
77 | 80 | 84 |
85 | 91 | """ 92 | 93 | #var cell = IPython.notebook.get_cell(index+1); 94 | #cell.element.find("div.input").show() 95 | 96 | # myhchboxd is a pretty checkbox with css 97 | myhchboxd = """ 98 | 104 | """ 105 | 106 | 107 | #display(HTML(myhchboxb.format(cbx_id,nb_cells_to_process))) # display 108 | display(HTML(myhchboxd.format(nb_cells_to_process))) # display 109 | # the checkbox -------------------------------------------------------------------------------- /src/jolie_fin_de_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/jolie_fin_de_page.png -------------------------------------------------------------------------------- /src/lena512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/lena512.png -------------------------------------------------------------------------------- /src/nbinit.ipy: -------------------------------------------------------------------------------- 1 | 2 | print("... Configuring matplotlib formats") 3 | print("... Configuring matplotlib with inline figures") 4 | 5 | %config InlineBackend.figure_format = 'retina' 6 | #In new notebooks created for IPython 1.0+, I would recommend using %matplotlib inline, since it is more tidy 7 | # and you have more control over which packages are imported and how. Commonly, scipy and numpy are imported separately with: 8 | # from: http://nbviewer.ipython.org/github/jrjohansson/scientific-python-lectures/blob/master/Lecture-4-Matplotlib.ipynb#Versions 9 | #%config InlineBackend.figure_format = 'svg' #this is depreceated in 2.x 10 | %config InlineBackend.figure_formats = {'retina', 'pdf', 'png', 'svg', 'jpeg'} 11 | 12 | print("... Importing numpy as np, scipy as sp, pyplot as plt, scipy.stats as stats") 13 | print(" ... scipy.signal as sig") 14 | import numpy as np 15 | import scipy as sp 16 | import matplotlib.pyplot as plt 17 | import scipy.stats as stats 18 | import scipy.signal as sig 19 | # Also import pylab for more easy interactive use (but less control) 20 | from pylab import * 21 | 22 | print("... Importing widgets, display, HTML, Image, Javascript") 23 | #For displaying widgets 24 | import ipywidgets as widgets 25 | from ipywidgets import interact, interactive, fixed 26 | from IPython.display import clear_output, display, HTML, Image, Javascript, JSON 27 | 28 | #Some specific imports for plotting 29 | 30 | ### ------------- 31 | print("... Some LaTeX definitions") 32 | 33 | LaTeXdefs=""" 34 | $$\\require{color} 35 | \\require{cancel} 36 | \\def\\tf#1{{\\mathrm{FT}\\left\{ #1 \\right\\}}} 37 | \\def\\flecheTF{\\rightleftharpoons } 38 | \\def\\TFI#1#2#3{{\\displaystyle{\\int_{-\\infty}^{+\\infty} #1 ~e^{j2\\pi #2 #3} 39 | ~\\dr{#2}}}} 40 | \\def\\TF#1#2#3{{\\displaystyle{\\int_{-\\infty}^{+\\infty} #1 ~e^{-j2\\pi #3 #2} 41 | ~\\dr{#2}}}} 42 | \\def\\sha{ш} 43 | \\def\\dr#1{\\mathrm{d}#1} 44 | \\def\\egalpardef{\\mathop{=}\\limits^\\triangle} 45 | \\def\\sinc#1{{\\mathrm{sinc}\\left( #1 \\right)}} 46 | \\def\\rect{\\mathrm{rect}} 47 | \\definecolor{lightred}{rgb}{1,0.1,0} 48 | \\def\myblueeqbox#1{{\\fcolorbox{blue}{lightblue}{$\textcolor{blue}{ #1}$}}} 49 | \\def\\myeqbox#1#2{{\\fcolorbox{#1}{light#1}{$\textcolor{#1}{ #2}$}}} 50 | \\def\\eqbox#1#2#3#4{{\\fcolorbox{#1}{#2}{$\\textcolor{#3}{ #4}$}}} 51 | % border|background|text 52 | \\def\\eqboxa#1{{\\boxed{#1}}} 53 | \\def\\eqboxb#1{{\\eqbox{green}{white}{green}{#1}}} 54 | \\def\\eqboxc#1{{\\eqbox{blue}{white}{blue}{#1}}} 55 | \\def\\eqboxd#1{{\\eqbox{blue}{lightblue}{blue}{#1}}} 56 | \\def\\E#1{\\mathbb{E}\\left[#1\\right]} 57 | \\def\\ta#1{\\left<#1\\right>} 58 | \\def\\egalparerg{{\\mathop{=}\\limits_\\mathrm{erg}}} 59 | \\def\\expo#1{\\exp\\left(#1\\right)} 60 | \\def\\d#1{\\mathrm{d}#1} 61 | \\def\\wb{\\mathbf{w}} 62 | \\def\\sb{\\mathbf{s}} 63 | \\def\\xb{\\mathbf{x}} 64 | \\def\\Rb{\\mathbf{R}} 65 | \\def\\rb{\mathbf{r}} 66 | \\def\\mystar{{*}} 67 | \\def\\ub{\\mathbf{u}} 68 | \\def\\wbopt{\\mathop{\\mathbf{w}}\\limits^\\triangle} 69 | \\def\\deriv#1#2{\\frac{\\mathrm{d}#1}{\\mathrm{d}#2}} 70 | \\def\\Ub{\\mathbf{U}} 71 | \\def\\db{\\mathbf{d}} 72 | \\def\\eb{\\mathbf{e}} 73 | \\def\\vb{\\mathbf{v}} 74 | \\def\\Ib{\\mathbf{I}} 75 | \\def\\Vb{\\mathbf{V}} 76 | \\def\\Lambdab{\\mathbf{\\Lambda}} 77 | \\def\\Ab{\\mathbf{A}} 78 | \\def\\Bb{\\mathbf{B}} 79 | \\def\\Cb{\\mathbf{C}} 80 | \\def\\Db{\\mathbf{D}} 81 | \\def\\Kb{\\mathbf{K}} 82 | \\def\\sinc#1{\\mathrm{sinc\\left(#1\\right)}} 83 | $$ 84 | """ 85 | 86 | display(HTML(LaTeXdefs)) 87 | 88 | ### ---------------------------------- 89 | %matplotlib inline 90 | 91 | print("... Defining figures captions ") 92 | 93 | display(HTML( 94 | """""")) 103 | 104 | #def figcaption(text,label=""): 105 | # display(HTML("
Caption: %s
" % text.replace('\n','
'))) 106 | 107 | def figcaption(text, label=" "): 108 | display(HTML("
Caption: %s
" 109 | % text.replace('\n', '
'))) 110 | text = text.replace('',r'\textbf{').replace('','}') #some replacement of HTML formatting 111 | text = text.replace('',r'\textit{').replace('','}') 112 | text = text.replace('',r'\texttt{').replace('','}') 113 | display(JSON({'caption': text, 'label':label}),include=["application/json"]) 114 | 115 | ### ------------------------------------------------- 116 | # A stub function 117 | def js_addon(): 118 | pass 119 | 120 | print("... Loading customized Javascript for interactive solutions (show/hide)") 121 | from interactive_sols import process_solution, unhide_next_cell, unhide_all_cells 122 | show_solution=process_solution 123 | #%run interactive_sols.ipy 124 | 125 | ## --------------------------------------------------- 126 | print("... Redefining interactive from ipywidgets") 127 | 128 | # Redefine interactive, because in the new version, return of functions 129 | # is automatically displayed. That is the way it is, see https://github.com/ipython/ipywidgets/issues/162 130 | # Thus what we do is to catch the call, redefine the function to hide its return. 131 | # Then it is always possible to call directly the original function and get its return value. 132 | # Also, it is possible to call it with the parameters selected from the interactive function 133 | # by func(**ww.kwargs) where ww is the object returned by intercative or interact. 134 | 135 | def interactive(f,*args,**kwargs): 136 | import ipywidgets 137 | def fn(*args,**kwargs): 138 | f(*args,**kwargs) 139 | w=ipywidgets.interactive(fn,*args,**kwargs) 140 | return w 141 | 142 | example=False 143 | if example: 144 | #func(**ww.kwargs) 145 | def func(x,y,col="red"): 146 | print(x,y) 147 | return x+y 148 | 149 | ww=interactive(func,x=[1,10],y=[3,7],col=("red","blue")) 150 | ww 151 | 152 | ## --------------------------------------------------- 153 | print("... Redefining capture for ipywidgets < 7") 154 | 155 | import ipywidgets 156 | if ipywidgets._version.version_info[0]<7: 157 | from functools import wraps 158 | # ipywidgets.widgets.widget_output.Output.capture = capture 159 | # 160 | def capture(self, clear_output=False, *clear_args, **clear_kwargs): 161 | """ 162 | Decorator to capture the stdout and stderr of a function. 163 | Parameters 164 | ---------- 165 | clear_output: bool 166 | If True, clear the content of the output widget at every 167 | new function call. Default: False 168 | wait: bool 169 | If True, wait to clear the output until new output is 170 | available to replace it. This is only used if clear_output 171 | is also True. 172 | Default: False 173 | usage: 174 | >> from ipywidgets import widgets 175 | >> out = widgets.Output() 176 | >> @out.capture(clear_output=True, wait=True) 177 | ... FUNCTION 178 | >> display(widgets.VBox([slide_k, out])) 179 | """ 180 | def capture_decorator(func): 181 | @wraps(func) 182 | def inner(*args, **kwargs): 183 | if clear_output: 184 | self.clear_output(*clear_args, **clear_kwargs) 185 | with self: 186 | return func(*args, **kwargs) 187 | return inner 188 | return capture_decorator 189 | ipywidgets.widgets.widget_output.Output.capture = capture 190 | -------------------------------------------------------------------------------- /src/noisecancellation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/noisecancellation.jpg -------------------------------------------------------------------------------- /src/parole_bruitee.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/parole_bruitee.npz -------------------------------------------------------------------------------- /src/plot_rea.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | @author: JF Bercher 4 | """ 5 | 6 | 7 | def plot_rea(sig, nb=10, fig=None): 8 | """ 9 | Plot `nb` realizations of the random variable object `rv` 10 | 11 | Parameters 12 | ---------- 13 | rv: object 14 | the random variable array 15 | nb: number 16 | number of realizations to display 17 | Returns 18 | ------- 19 | Nothing 20 | Modules 21 | ------- 22 | import matplotlib.gridspec as gridspec 23 | from itertools import cycle 24 | 25 | Examples 26 | -------- 27 | >>> rv=stats.norm(loc=0,scale=1) 28 | >>> plot_rea() 29 | 30 | """ 31 | import numpy as np 32 | import scipy as sp 33 | import matplotlib.pyplot as plt 34 | import matplotlib.gridspec as gridspec 35 | from itertools import cycle 36 | 37 | plt.figure(fig) 38 | plt.clf() 39 | plt.suptitle( 40 | "Realizations and means of a random signal", fontsize=14, color='blue') 41 | G = gridspec.GridSpec(12, 12) 42 | #fig=figure(figsize=(10,4)) 43 | ax1 = plt.subplot(G[0:9, 0:10]) 44 | ax2 = plt.subplot(G[10:12, 0:10]) 45 | ax3 = plt.subplot(G[0:9, 11:12]) 46 | 47 | (K, N) = np.shape(sig) 48 | sig_sampled = sig[np.random.randint(0, K, nb), :] 49 | deltaA = sig.max() - sig.min() 50 | yrea = deltaA * np.linspace(0, nb, nb) 51 | decalage = np.outer(yrea, np.ones(N)) 52 | sig_sampled_dec = sig_sampled + 0.5 * decalage 53 | 54 | ax1.xaxis.tick_top() 55 | ax1.plot(sig_sampled_dec.T) 56 | ax1.set_yticks(yrea / 2) #, 57 | ax1.set_yticklabels([str(x) for x in list(range(1, nb + 1))]) 58 | ax1.set_xlim([0, N]) 59 | fivepercent = (sig_sampled_dec.max() - sig_sampled_dec.min()) / 20 60 | ax1.set_ylim([ 61 | sig_sampled_dec.min() - fivepercent, sig_sampled_dec.max() + 62 | fivepercent 63 | ]) 64 | ax1.set_ylabel("Realizations", fontsize=14) 65 | 66 | msig0 = np.mean(sig, axis=0) 67 | ax2.plot(msig0) 68 | ax2.set_xlim([0, N]) 69 | ax2.set_xlabel("Time", fontsize=14) 70 | ax2.annotate( 71 | "Ensemble average", 72 | xy=(80, msig0[80]), 73 | xytext=(0.55, 0.25), 74 | textcoords='figure fraction' 75 | # , 76 | # arrowprops=dict(arrowstyle="->", 77 | # color="green", 78 | # connectionstyle="arc3,rad=0.3", 79 | # shrinkA=10, shrinkB=10) 80 | ) 81 | # yticks([]) 82 | 83 | #clist = plt.rcParams['axes.color_cycle'] 84 | #colorcycler = cycle(clist) 85 | #axes.prop_cycle : cycler('color', ['b', 'g', 'r', 'c', 'm', 'y', 'k']) 86 | colorcycler = cycle(plt.rcParams['axes.prop_cycle']) 87 | ax3.yaxis.tick_right() 88 | m_sig_sampled1 = np.mean(sig_sampled, axis=1) 89 | for k in range(len(yrea)): 90 | ax3.plot( 91 | m_sig_sampled1[k], 92 | yrea[k] / 2, 93 | 'o', 94 | color=next(colorcycler)['color']) #sig 95 | ax3.plot(np.mean(sig_sampled, axis=1), yrea / 2, alpha=0.5) #sig 96 | ax3.set_ylim([ 97 | sig_sampled_dec.min() - fivepercent, sig_sampled_dec.max() + 98 | fivepercent 99 | ]) 100 | ax3.set_yticks(yrea / 2) #, 101 | ax3.set_yticklabels([str(x) for x in list(range(1, nb + 1))]) 102 | ax3.set_xticks([m_sig_sampled1.min(), m_sig_sampled1.max()]) 103 | ax3.set_xticklabels([ 104 | "{0:2.2f}".format(m_sig_sampled1.min()), 105 | "{0:2.3f}".format(m_sig_sampled1.max()) 106 | ]) #, 107 | ax3.annotate( 108 | "Time \naverage", 109 | xy=(m_sig_sampled1[0], yrea[0] / 2), #xycoords='figure fraction', 110 | xytext=(0.85, 0.92), 111 | textcoords='figure fraction' 112 | #, 113 | # arrowprops=dict(arrowstyle="->", 114 | # color="blue", 115 | # connectionstyle="arc3,rad=0.3", 116 | # shrinkA=10, shrinkB=10) 117 | ) 118 | #ax3.set_xlim([0,N]) 119 | 120 | 121 | if __name__ == '__main__': 122 | import scipy.stats as stats 123 | import matplotlib.gridspec as gridspec 124 | from itertools import cycle 125 | # Used for arbitrary subplots, with possible aliasing between them and all that 126 | 127 | rv = stats.norm(loc=0, scale=1) 128 | size = (100, 150) 129 | sig = rv.rvs(size=size) 130 | plot_rea(sig, nb=10, fig=1) -------------------------------------------------------------------------------- /src/plot_sighisto.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Tue Feb 18 10:01:53 2014 4 | 5 | @author: JF 6 | """ 7 | import matplotlib.gridspec as gridspec 8 | from pylab import * 9 | # Used for arbitrary subplots, with possible aliasing between them and all that 10 | 11 | 12 | def plot_sighisto(X,M=10,fig=None): 13 | figure(fig); clf() 14 | G = gridspec.GridSpec(12, 12) 15 | ax1 = subplot(G[0:8, 0:12]) 16 | ax2 = subplot(G[9:12, 0:12],sharex=ax1) 17 | #G.update(left=0.05, right=0.48, wspace=0.05) 18 | N=len(X) 19 | D=max(X)-min(X) 20 | ax1.plot(X,range(N)) 21 | ax1.set_ylabel('Time') 22 | ax1.axis([min(X)-D/10, max(X)+D/10, 0, N]) 23 | # make these tick labels invisible 24 | setp( ax1.get_xticklabels(), visible=False) 25 | (n,b,p)=plt.hist(X,M) 26 | ax2.hist(X,M) 27 | ax2.set_xlabel('Amplitude') 28 | ax2.set_ylim([0, 1.1*max(n)]) 29 | #ax2.axis([min(X)-D/10, max(X)+D/10, 0, 1.1*max(h)]) 30 | # Reset the bottom subplot to have xticks 31 | #setp(gca,'xtickMode', 'auto') 32 | 33 | 34 | if __name__ == '__main__': 35 | import scipy.stats as stats 36 | import matplotlib.gridspec as gridspec 37 | # Used for arbitrary subplots, with possible aliasing between them and all that 38 | rv=stats.norm(loc=0,scale=1) 39 | plot_sighisto(rv.rvs(200),fig=2) -------------------------------------------------------------------------------- /src/plt_LPtemplate.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | from numpy import pi 4 | 5 | def plt_LPtemplate(omega, A, Abounds=None): 6 | """omega contains the template frequencies [band-pass, band-stop] 7 | A contains the corresponding attenuations, Abounds, the y limits for the display 8 | """ 9 | [omegac, omegaa]=omega 10 | [Ac, Aa]=A 11 | if Abounds is None: 12 | delta=np.max(A)-np.min(A); Amax=np.max(A)+delta/5; Amin=np.min(A)-delta/5 13 | else: 14 | [Amax, Amin]=(Abounds) 15 | plt.plot([-omegac, -omegac, omegac, omegac],[Amin, Ac, Ac, Amin],'-', color='blue') 16 | plt.fill_between([-omegac, -omegac, omegac, omegac],[Amin, Ac, Ac, Amin], Amin, 17 | color='lightblue', alpha=0.6) 18 | 19 | plt.plot([-pi, -omegaa, -omegaa],[Aa, Aa, Amax],'-', color='blue') 20 | plt.fill_between([-pi, -omegaa, -omegaa],Amax, [Aa, Aa, Amax], color='lightblue', alpha=0.6) 21 | plt.plot([omegaa, omegaa,pi],[Amax, Aa, Aa],'-', color='blue') 22 | plt.fill_between([omegaa, omegaa,pi],Amax, [Amax, Aa, Aa],color='lightblue', alpha=0.6) 23 | plt.ylim([Amin, Amax]) 24 | plt.xlim([-pi, pi]) 25 | 26 | #plt.text(-3.7,0.4,'Fs/2', color='blue',fontsize=14) 27 | if __name__=="__main__": 28 | plt_LPtemplate([1, 1.84],[0, -20],Abounds=[5, -35]) -------------------------------------------------------------------------------- /src/saturne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/saturne.png -------------------------------------------------------------------------------- /src/saturne_vraie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/saturne_vraie.png -------------------------------------------------------------------------------- /src/sb1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/sb1.npz -------------------------------------------------------------------------------- /src/sb2.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/sb2.npz -------------------------------------------------------------------------------- /src/sig1.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/sig1.npz -------------------------------------------------------------------------------- /src/signal.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/signal.npz -------------------------------------------------------------------------------- /src/syssound.py: -------------------------------------------------------------------------------- 1 | def sysfileopen(filepath): 2 | import subprocess, os 3 | if sys.platform.startswith('darwin'): 4 | subprocess.call(('open', filepath)) 5 | elif os.name == 'nt': 6 | os.startfile(filepath) 7 | elif os.name == 'posix': 8 | # subprocess.call(('xdg-open', filepath)) 9 | subprocess.Popen(["xdg-open", filepath]) 10 | 11 | # Import useful read-write for wav files 12 | from scipy.io.wavfile import read as wavread, write as wavwrite 13 | 14 | def sound(var): 15 | from scipy.io.wavfile import write as wavwrite 16 | scaled = np.int16(var/np.max(np.abs(var)) * 32767) 17 | stmp=asarray(scaled,dtype=np.int16) 18 | wavwrite('stmp.wav',8820,stmp) 19 | sysfileopen("stmp.wav") 20 | -------------------------------------------------------------------------------- /src/test.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from zerospolesdisplay import * 3 | 4 | poles=np.array([0]) 5 | zeros=np.array([0.95*np.exp(1j*2*pi*0.4)]) 6 | A=ZerosPolesDisplay(poles,zeros) 7 | 8 | -------------------------------------------------------------------------------- /src/test_sound.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/test_sound.wav -------------------------------------------------------------------------------- /src/toc_and_cln.py: -------------------------------------------------------------------------------- 1 | 2 | """ 3 | Created on Thu Nov 18 15:34:38 2014 4 | @author: JF 5 | """ 6 | 7 | import glob 8 | import os 9 | import sys 10 | import time 11 | from stat import * 12 | 13 | 14 | def texheaders_filtering(input_file): 15 | import re 16 | 17 | st = os.stat(input_file) 18 | atime = st[ST_ATIME] #access time 19 | mtime = st[ST_MTIME] #modification time 20 | 21 | with open(input_file,'rt') as f: 22 | text=f.read() 23 | #print(text) 24 | my_texfile = input_file #file.split('.html')[0] + 'b.html' 25 | if sys.version_info >= (3,0,0): 26 | my_texfile_desc = open(my_texfile, 'wt', newline='') 27 | else: 28 | my_texfile_desc = open(my_texfile_file, 'wt') 29 | 30 | 31 | def remp(intext): 32 | #out=re.findall('\\\\[sub]?section',intext.group(0)) 33 | out=re.findall('(\\\\[sub]?section|\\\\chapter)',intext.group(0)) 34 | 35 | print(out) 36 | """"print(out.group(0)) 37 | return out.group(0) """ 38 | return out[-1] 39 | 40 | #newtext=re.sub('section{Table of Contents}([\s\S]*?)\\[sub]?section{','Remplacement',text,flags=re.M) 41 | newtext=re.sub('\\\\section{Table of Contents}([\s\S]*?)(\\\\[sub]?section|\\\\chapter)',remp,text,flags=re.M) 42 | newtext=re.sub('\\\\begin{verbatim}[\s]*?[\s]*?\\\\end{verbatim}','',newtext,flags=re.M) 43 | newtext=re.sub('\\\\begin{verbatim}[\s]*?[\s]*?\\\\end{verbatim}','',newtext,flags=re.M) 44 | 45 | #bottom page with links to Index/back/next (suppress this) 46 | #'----[\s]*?
[Index](toc.ipynb)[\S ]*?.ipynb\)
' 47 | newtext=re.sub('\\\\begin{center}\\\\rule{3in}{0.4pt}\\\\end{center}[\s]*?\\\\href{toc.ipynb}{Index}[\S\s ]*?.ipynb}{Next}','',newtext,flags=re.M) 48 | 49 | 50 | # figcaption(text,label=) 51 | tofind="figcaption\(([\s\S]*?)\)\n([\s\S]*?)\\\\begin{center}\s*\\\\adjustimage[\s\S]*?}}{([\S]*?)}\s*\\\\end{center}" 52 | 53 | def replacement(text): 54 | cap=re.match("\"([\S\s]*?)\",[\S\s]*?label=\"([\S]*?)\"",text.group(1)) 55 | 56 | if cap==None: 57 | cap=re.match("\"([\S\s]*?)\"",text.group(1)) 58 | caption=cap.group(1) 59 | label="" 60 | rep="\n%s\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\linewidth]{%s}\n\\caption{%s}\n\\end{figure}" % (text.group(2),text.group(3),caption) 61 | else: 62 | caption=cap.group(1) 63 | label=cap.group(2) 64 | rep="\n%s\n\\begin{figure}[H]\n\\centering\n\\includegraphics[width=0.6\\linewidth]{%s}\n\\caption{%s}\n\\label{%s}\n\\end{figure}" % (text.group(2),text.group(3),caption,label) 65 | return rep 66 | code="Init" 67 | 68 | while (code!=None): 69 | code=re.search(tofind,newtext) 70 | newtext=re.sub(tofind,replacement,newtext,flags=re.M) 71 | 72 | 73 | 74 | my_texfile_desc.write(newtext) 75 | 76 | #modify the file timestamp 77 | my_texfile_desc.close() 78 | os.utime(my_texfile,(atime,mtime)) 79 | 80 | 81 | 82 | 83 | 84 | verbose=True 85 | if __name__ == '__main__': 86 | import argparse 87 | 88 | whatitdoes="""This program filters a LaTeX file \n 89 | - in order to remove the first 'table of contents section', 90 | to the next section ; 91 | - it replaces figcaption structures to "\\caption{\\label{}}" LaTeX constructs. 92 | - Finally, it also filters out various 'spurious' outputs""" 93 | myself="(c) JFB 2014" 94 | parser = argparse.ArgumentParser(description=whatitdoes, epilog=myself) 95 | # mandatory argument 96 | parser.add_argument( 97 | help = 'List of files to filter (accepts regular expressions)', 98 | dest = 'argfiles', default = '*.tex', type = str, nargs = '*') 99 | # verbosity flag 100 | parser.add_argument('-v','--verbose', help = 'Prints information', 101 | dest = 'verbose', default = False, #action='store_true' 102 | action='count') 103 | 104 | arguments = parser.parse_args() 105 | verbose=arguments.verbose 106 | if verbose==2: print("script arg: ", arguments.argfiles) 107 | 108 | if isinstance(arguments.argfiles,list): 109 | tex_files=[] 110 | for x in arguments.argfiles: 111 | tex_files = tex_files+glob.glob(x) 112 | else: 113 | tex_files = glob.glob(arguments.argfiles) 114 | if verbose==2: print("glog.glog expansion: ", tex_files, '\n') 115 | if len(tex_files ) == 0: 116 | raise RuntimeError('No TeX files to convert.') 117 | 118 | for file in tex_files: 119 | if verbose: 120 | print("Filtering {}".format(file)) 121 | texheaders_filtering(file) 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /src/voix_outretombe.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/src/voix_outretombe.wav -------------------------------------------------------------------------------- /src/widgets_utils.ipy: -------------------------------------------------------------------------------- 1 | # From http://nbviewer.ipython.org/gist/anonymous/840b5cec9e19f3e39090 2 | hbox = lambda x: (x.remove_class("vbox"), x.add_class("hbox")) 3 | # 4 | frame = lambda x: x.set_css({ 5 | "border": "outset 1px", 6 | "padding": 5, 7 | "border-radius": 5, 8 | "display": "inline-box", 9 | "margin": "5px" 10 | }) 11 | 12 | # Example 13 | if __name__="__main__": 14 | c = widgets.CheckboxWidget(description="", value=True)#, width=100, font_size='14pt', fore_color='red') 15 | t = widgets.HTMLWidget(value="how solution with a very long text how to align on the left? how solution with a very long text how to align on the left? how solution with a very long text how to align on the left?") 16 | t.set_css({'font-size': 16, 'width':'80%', 'margin-top':4}) 17 | cont = widgets.ContainerWidget(children=[c,t]) 18 | 19 | frame(cont) 20 | display(cont) 21 | _=hbox(cont) -------------------------------------------------------------------------------- /src/widgets_utils.py: -------------------------------------------------------------------------------- 1 | from IPython.html import widgets 2 | from IPython.display import clear_output, display, HTML, Image, Javascript 3 | # From http://nbviewer.ipython.org/gist/anonymous/840b5cec9e19f3e39090 4 | hbox = lambda x: (x.remove_class("vbox"), x.add_class("hbox")) 5 | # 6 | frame = lambda x: x.set_css({ 7 | "border": "outset 1px", 8 | "padding": 5, 9 | "border-radius": 5, 10 | "display": "inline-box", 11 | "margin": "5px" 12 | }) 13 | 14 | # Example 15 | if __name__=="__main__": 16 | c = widgets.CheckboxWidget(description="", value=True)#, width=100, font_size='14pt', fore_color='red') 17 | t = widgets.HTMLWidget(value="how solution with a very long text how to align on the left? how solution with a very long text how to align on the left? how solution with a very long text how to align on the left?") 18 | t.set_css({'font-size': 16, 'width':'80%', 'margin-top':4}) 19 | cont = widgets.ContainerWidget(children=[c,t]) 20 | 21 | frame(cont) 22 | display(cont) 23 | _=hbox(cont) -------------------------------------------------------------------------------- /src/windows_disp.ipy: -------------------------------------------------------------------------------- 1 | def bigwidget_cbk(value,val): 2 | ll=dict() 3 | clear_output(wait=True) 4 | fig,ax=plt.subplots(2,1,figsize=(9,5)) 5 | for n in range(nb_lines): 6 | for k,wi in enumerate(windows[6*n:6*(n+1)]): 7 | ll[wi]=lw[n][k].value 8 | 9 | if lw[n][k].value: 10 | #plt.plot(sig.get_window(wi,200),label=wi) 11 | wn=sig.get_window(wi,50) 12 | ax[0].plot(wn,label=wi) 13 | wf=np.fft.fftshift(20*np.log10(abs(np.fft.fft(wn,1000)))) 14 | wf=wf-np.max(wf) #normalization 15 | wf[np.where(wf==-inf)]=-500 16 | f=np.linspace(-0.5,0.5,1000)*50 17 | ax[1].plot(f,wf,label=wi) 18 | ax[1].set_xlim([-5, 5]) 19 | ax[1].set_xticks(np.arange(-5,6)) 20 | #ax[1].set_xticklabels(['$\\frac{%d}{N}$' %x for x in np.arange(-5,6)]) 21 | ax[1].set_xticklabels([str(x) for x in np.arange(-5,6)]) 22 | ax[1].set_xlabel('Frequency (normalized by 1/N)') 23 | ax[1].set_ylabel('dB') 24 | ax[1].set_ylim([-150, 5]) 25 | ax[0].legend() 26 | ax[1].legend() 27 | #plt.legend() 28 | 29 | # plt_win(ll,windows) 30 | return ll 31 | 32 | 33 | def plt_win(ll,windows): 34 | fig,ax=plt.subplots(211) 35 | for k,tst in enumerate(ll): 36 | if tst: 37 | wn=sig.get_window(windows[k],50) 38 | #ax[0].plot(wn,label=windows[k]) 39 | #ax[1].plot(np.linspace(-0.5,0.5,1024),np.fft.fftshift(abs(np.fft.fft(wn,1024))),label=windows[k]) 40 | ax[0].legend() 41 | ax[1].legend() 42 | 43 | nb_lines=len(windows)//6+1 44 | 45 | lw=[None]*nb_lines 46 | wm=[None]*nb_lines 47 | 48 | for m in range(nb_lines): 49 | lw[m]=[widgets.CheckboxWidget(description=w) for w in windows[6*m:6*(m+1)]] 50 | for k,ww in enumerate(lw[m]): ww.on_trait_change(bigwidget_cbk,'value') 51 | wm[m]=widgets.ContainerWidget(children=lw[m]) 52 | 53 | 54 | t = widgets.HTMLWidget(value="Window functions") 55 | t.set_css({'color':'blue', 'font-size': 18, 'width':'80%', 56 | 'margin-top':8,'margin-bottom':8, 'text-align':'center'}) 57 | 58 | xx=widgets.ContainerWidget( 59 | children=[t]+[wm[k] for k in range(nb_lines)]) 60 | display(xx) 61 | for k in range(nb_lines): hbox(wm[k]) 62 | frame(xx) -------------------------------------------------------------------------------- /src/windows_disp_jup.ipy: -------------------------------------------------------------------------------- 1 | out = widgets.Output() 2 | 3 | @out.capture(clear_output=True, wait=True) 4 | def bigwidget_cbk(value): 5 | ll = dict() 6 | #clear_output(wait=True) 7 | fig, ax = plt.subplots(2, 1, figsize=(9, 5)) 8 | plot_exists = False 9 | for n in range(nb_lines): 10 | for k, wi in enumerate(windows[6 * n:6 * (n + 1)]): 11 | ll[wi] = lw[n][k].value 12 | 13 | if lw[n][k].value: 14 | #plt.plot(sig.get_window(wi,200),label=wi) 15 | wn = sig.get_window(wi, 50) 16 | ax[0].plot(wn, label=wi) 17 | wf = np.fft.fftshift(20 * np.log10(abs(np.fft.fft(wn, 1000)))) 18 | wf = wf - np.max(wf) #normalization 19 | wf[np.where(wf == -inf)] = -500 20 | f = np.linspace(-0.5, 0.5, 1000) * 50 21 | ax[1].plot(f, wf, label=wi) 22 | ax[1].set_xlim([-5, 5]) 23 | ax[1].set_xticks(np.arange(-5, 6)) 24 | #ax[1].set_xticklabels(['$\\frac{%d}{N}$' %x for x in np.arange(-5,6)]) 25 | ax[1].set_xticklabels([str(x) for x in np.arange(-5, 6)]) 26 | ax[1].set_xlabel('Frequency (normalized by 1/N)') 27 | ax[1].set_ylabel('dB') 28 | ax[1].set_ylim([-150, 5]) 29 | plot_exists = True 30 | if plot_exists: 31 | ax[0].legend() 32 | ax[1].legend() 33 | 34 | plt.show() 35 | 36 | return ll 37 | 38 | @out.capture(clear_output=True, wait=True) 39 | def plt_win(ll, windows): 40 | fig, ax = plt.subplots(211) 41 | for k, tst in enumerate(ll): 42 | if tst: 43 | wn = sig.get_window(windows[k], 50) 44 | #ax[0].plot(wn,label=windows[k]) 45 | #ax[1].plot(np.linspace(-0.5,0.5,1024),np.fft.fftshift(abs(np.fft.fft(wn,1024))),label=windows[k]) 46 | ax[0].legend() 47 | ax[1].legend() 48 | plt.show() 49 | 50 | 51 | nb_lines = len(windows) // 6 + 1 52 | 53 | lw = [None] * nb_lines 54 | wm = [None] * nb_lines 55 | 56 | for m in range(nb_lines): 57 | lw[m] = [ 58 | widgets.Checkbox(description=w) for w in windows[6 * m:6 * (m + 1)] 59 | ] 60 | for k, ww in enumerate(lw[m]): 61 | ww.observe(bigwidget_cbk, 'value') 62 | wm[m] = widgets.HBox(children=lw[m]) 63 | 64 | t = widgets.HTML( 65 | value="
Window functions
", 66 | color='blue', 67 | font_size=24, 68 | width='100%', 69 | margin=8, 70 | margin_bottom=8, 71 | align='center') 72 | #t.set_css({'color':'blue', 'font-size': 18, 'width':'80%', 73 | # 'margin-top':8,'margin-bottom':8, 'text-align':'center'}) 74 | 75 | tt = widgets.HBox(children=[t, ], width='100%', align='end') 76 | xx = widgets.VBox( 77 | children=[tt] + [wm[k] for k in range(nb_lines)], width='100%') 78 | xx.align = "start" 79 | xx.box_style = "info" 80 | xx.border_radius = 20 81 | xx.padding = 10 82 | 83 | display(widgets.VBox([xx, out])) 84 | 85 | -------------------------------------------------------------------------------- /src/zerospolesdisplay.py: -------------------------------------------------------------------------------- 1 | """ 2 | Zeros/Poles + impulse response + transfer function displays 3 | jfb 2015 - last update november 22, 2018 4 | """ 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | from numpy import pi 8 | 9 | 10 | #line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance 11 | 12 | class ZerosPolesDisplay(): 13 | 14 | def __init__(self,poles=np.array([0.7*np.exp(1j*2*np.pi*0.1)]), 15 | zeros=np.array([1.27*np.exp(1j*2*np.pi*0.3)]), 16 | N=1000, response_real=True, ymax=1.2, Nir=64): 17 | 18 | 19 | self.poles=poles 20 | self.zeros=zeros 21 | 22 | self.ymax=np.max([ymax, 1.2*np.max(np.concatenate((np.abs(poles), np.abs(zeros))))]) 23 | self.poles_th=np.angle(self.poles) 24 | self.poles_r=np.abs(self.poles) 25 | self.zeros_th=np.angle(self.zeros) 26 | self.zeros_r=np.abs(self.zeros) 27 | self.N=N 28 | self.Nir=Nir 29 | 30 | self.poles_line = None 31 | self.zeros_line = None 32 | self.setup_main_screen() 33 | 34 | 35 | 36 | def setup_main_screen(self): 37 | 38 | import matplotlib.gridspec as gridspec 39 | 40 | #Poles & zeros 41 | self.fig = plt.figure(figsize=(9,7)) 42 | gs = gridspec.GridSpec(3,12) 43 | #self.ax = self.fig.add_axes([0.1, 0.1, 0.77, 0.77], polar=True, facecolor='#d5de9c') 44 | #self.ax=self.fig.add_subplot(221,polar=True, facecolor='#d5de9c') 45 | self.ax = plt.subplot(gs[0:,0:6],polar=True,facecolor='#d5de9c') 46 | #self.ax = self.fig.add_subplot(111, polar=True) 47 | self.fig.suptitle('Poles & zeros adjustment',fontsize=18, color='blue', 48 | x=0.1, y=0.98, horizontalalignment='left') 49 | #self.ax.set_title('Poles & zeros adjustment',fontsize=16, color='blue') 50 | self.ax.set_ylim([0, self.ymax]) 51 | self.poles_line, = self.ax.plot(self.poles_th,self.poles_r,'ob',ms=9, picker=5, label="Poles") 52 | self.zeros_line, = self.ax.plot(self.zeros_th,self.zeros_r,'Dr',ms=9, picker=5, label="Zeros") 53 | self.ax.plot(np.linspace(-np.pi,np.pi,500),np.ones(500),'--b',lw=1) 54 | self.ax.legend() 55 | 56 | 57 | #Transfer function 58 | self.axTF0= plt.subplot(gs[0,6:11],facecolor='LightYellow') 59 | #self.axTF[0].set_axis_bgcolor('LightYellow') 60 | self.axTF0.set_title('Transfer function (modulus)') 61 | #self.axTF1=self.fig.add_subplot(224,facecolor='LightYellow') 62 | self.axTF1=plt.subplot(gs[1,6:11],facecolor='LightYellow') 63 | self.axTF1.set_title('Transfer function (phase)') 64 | self.axTF1.set_xlabel('Frequency') 65 | f=np.linspace(0,1,self.N) 66 | self.TF=np.fft.fft(np.poly(self.zeros),self.N)/np.fft.fft(np.poly(self.poles),self.N) 67 | self.TF_m_line, = self.axTF0.plot(f,np.abs(self.TF)) 68 | self.TF_p_line, = self.axTF1.plot(f,180/np.pi*np.angle(self.TF)) 69 | #self.figTF.canvas.draw() 70 | 71 | #Impulse response 72 | #self.figIR = plt.figure() 73 | #self.axIR = self.fig.add_subplot(223,facecolor='Lavender') 74 | self.axIR = plt.subplot(gs[2,6:11],facecolor='Lavender') 75 | self.IR= np.real(self.impz(self.zeros,self.poles,self.Nir)) #np.real(np.fft.ifft(self.TF)) 76 | self.axIR.set_title('Impulse response') 77 | self.axIR.set_xlabel('Time') 78 | self.IR_m_line, = self.axIR.plot(self.IR) 79 | #self.figIR.canvas.draw() 80 | self.fig.canvas.draw() 81 | self.fig.tight_layout() 82 | 83 | def impz(self,zeros,poles,L): 84 | from scipy.signal import lfilter 85 | a=np.poly(poles) 86 | b=np.poly(zeros) 87 | d=np.zeros(L) 88 | d[0]=1 89 | h=lfilter(b,a,d) 90 | return h 91 | 92 | 93 | if __name__=="__main__": 94 | #sym_comp([1+1j, 2, 3-2j]) 95 | #case of complex poles and zeros 96 | poles=np.array([0.8*np.exp(1j*2*pi*0.125), 0.8*np.exp(1j*2*pi*0.15), 0.5]) 97 | zeros=np.array([0.95*np.exp(1j*2*pi*0.175), 1.4*np.exp(1j*2*pi*0.3), 0]) 98 | A=ZerosPolesDisplay(poles,zeros) 99 | 100 | """ 101 | #case of a single real pole 102 | poles=np.array([0.5]) 103 | zeros=np.array([0]) 104 | A=ZerosPolesPlay(poles,zeros,response_real=False) 105 | """ 106 | 107 | #plt.show() 108 | -------------------------------------------------------------------------------- /src/zerospolesplay.py: -------------------------------------------------------------------------------- 1 | """ 2 | Transfer function adjustment using zeros and poles drag and drop! 3 | jfb 2015 - last update january 08, 2015 4 | """ 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | from numpy import pi 8 | 9 | 10 | #line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance 11 | 12 | class ZerosPolesPlay(): 13 | 14 | def __init__(self,poles=np.array([0.7*np.exp(1j*2*np.pi*0.1)]), 15 | zeros=np.array([1.27*np.exp(1j*2*np.pi*0.3)]), 16 | N=1000, response_real=True, ymax=1.2, Nir=64): 17 | 18 | if response_real: 19 | self.poles, self.poles_isreal = self.sym_comp(poles) 20 | self.zeros, self.zeros_isreal = self.sym_comp(zeros) 21 | else: 22 | self.poles=poles 23 | self.poles_isreal= (np.abs(np.imag(poles))<1e-12) 24 | self.zeros=zeros 25 | self.zeros_isreal =(np.abs(np.imag(zeros))<1e-12) 26 | 27 | self.ymax=np.max([ymax, 1.2*np.max(np.concatenate((np.abs(poles), np.abs(zeros))))]) 28 | self.poles_th=np.angle(self.poles) 29 | self.poles_r=np.abs(self.poles) 30 | self.zeros_th=np.angle(self.zeros) 31 | self.zeros_r=np.abs(self.zeros) 32 | self.N=N 33 | self.Nir=Nir 34 | self.response_real=response_real 35 | 36 | self.being_dragged = None 37 | self.nature_dragged = None 38 | self.poles_line = None 39 | self.zeros_line = None 40 | self.setup_main_screen() 41 | self.connect() 42 | self.update() 43 | 44 | 45 | def setup_main_screen(self): 46 | 47 | import matplotlib.gridspec as gridspec 48 | 49 | #Poles & zeros 50 | self.fig = plt.figure() 51 | gs = gridspec.GridSpec(3,12) 52 | #self.ax = self.fig.add_axes([0.1, 0.1, 0.77, 0.77], polar=True, facecolor='#d5de9c') 53 | #self.ax=self.fig.add_subplot(221,polar=True, facecolor='#d5de9c') 54 | self.ax = plt.subplot(gs[0:,0:6],polar=True,facecolor='#d5de9c') 55 | #self.ax = self.fig.add_subplot(111, polar=True) 56 | self.fig.suptitle('Poles & zeros adjustment',fontsize=18, color='blue', 57 | x=0.1, y=0.98, horizontalalignment='left') 58 | #self.ax.set_title('Poles & zeros adjustment',fontsize=16, color='blue') 59 | self.ax.set_ylim([0, self.ymax]) 60 | self.poles_line, = self.ax.plot(self.poles_th,self.poles_r,'ob',ms=9, picker=5, label="Poles") 61 | self.zeros_line, = self.ax.plot(self.zeros_th,self.zeros_r,'Dr',ms=9, picker=5, label="Zeros") 62 | self.ax.plot(np.linspace(-np.pi,np.pi,500),np.ones(500),'--b',lw=1) 63 | self.ax.legend(loc=1) 64 | 65 | 66 | #Transfer function 67 | #self.figTF, self.axTF = plt.subplots(2, sharex=True) 68 | #self.axTF0=self.fig.add_subplot(222,facecolor='LightYellow') 69 | self.axTF0= plt.subplot(gs[0,6:11],facecolor='LightYellow') 70 | #self.axTF[0].set_axis_bgcolor('LightYellow') 71 | self.axTF0.set_title('Transfer function (modulus)') 72 | #self.axTF1=self.fig.add_subplot(224,facecolor='LightYellow') 73 | self.axTF1=plt.subplot(gs[1,6:11],facecolor='LightYellow') 74 | self.axTF1.set_title('Transfer function (phase)') 75 | self.axTF1.set_xlabel('Frequency') 76 | f=np.linspace(0,1,self.N) 77 | self.TF=np.fft.fft(np.poly(self.zeros),self.N)/np.fft.fft(np.poly(self.poles),self.N) 78 | self.TF_m_line, = self.axTF0.plot(f,np.abs(self.TF)) 79 | self.TF_p_line, = self.axTF1.plot(f,180/np.pi*np.angle(self.TF)) 80 | #self.figTF.canvas.draw() 81 | 82 | #Impulse response 83 | #self.figIR = plt.figure() 84 | #self.axIR = self.fig.add_subplot(223,facecolor='Lavender') 85 | self.axIR = plt.subplot(gs[2,6:11],facecolor='Lavender') 86 | self.IR= self.impz(self.zeros,self.poles,self.Nir) #np.real(np.fft.ifft(self.TF)) 87 | self.axIR.set_title('Impulse response') 88 | self.axIR.set_xlabel('Time') 89 | self.IR_m_line, = self.axIR.plot(self.IR) 90 | #self.figIR.canvas.draw() 91 | self.fig.canvas.draw() 92 | self.fig.tight_layout() 93 | 94 | def impz(self,zeros,poles,L): 95 | from scipy.signal import lfilter 96 | a=np.poly(poles) 97 | b=np.poly(zeros) 98 | d=np.zeros(L) 99 | d[0]=1 100 | h=lfilter(b,a,d) 101 | return h 102 | 103 | def sym_comp(self,p): 104 | L=np.size(p) 105 | r=list() 106 | c=list() 107 | for z in p: 108 | if np.abs(np.imag(z))<1e-12: 109 | r.append(z) 110 | else: 111 | c.append(z) 112 | out=np.concatenate((c,r,np.conjugate(c[::-1]))) 113 | isreal=(np.abs(np.imag(out))<1e-12) 114 | return out,isreal 115 | #sym_comp([1+1j, 2, 3-2j]) 116 | 117 | def connect(self): 118 | self.cidpick = self.fig.canvas.mpl_connect( 119 | 'pick_event', self.on_pick) 120 | self.cidrelease = self.fig.canvas.mpl_connect( 121 | 'button_release_event', self.on_release) 122 | self.cidmotion = self.fig.canvas.mpl_connect( 123 | 'motion_notify_event', self.on_motion) 124 | 125 | def update(self): 126 | 127 | #poles and zeros 128 | #self.fig.canvas.draw() 129 | 130 | #Transfer function & Impulse response 131 | if not(self.being_dragged is None): 132 | #print("Was released") 133 | 134 | f=np.linspace(0,1,self.N) 135 | self.TF=np.fft.fft(np.poly(self.zeros),self.N)/np.fft.fft(np.poly(self.poles),self.N) 136 | self.TF_m_line.set_ydata(np.abs(self.TF)) 137 | M=np.max(np.abs(self.TF)) 138 | #update the yscale 139 | current_ylim=self.axTF0.get_ylim()[1] 140 | if M>current_ylim or M<0.5*current_ylim: self.axTF0.set_ylim([0, 1.2*M]) 141 | 142 | #phase 143 | self.TF_p_line.set_ydata(180/np.pi*np.angle(self.TF)) 144 | #self.figTF.canvas.draw() 145 | 146 | # Impulse response 147 | self.IR=self.impz(self.zeros,self.poles,self.Nir) #np.fft.ifft(self.TF) 148 | #print(self.IR) 149 | self.IR_m_line.set_ydata(self.IR) 150 | M=np.max(self.IR) 151 | Mm=np.min(self.IR) 152 | #update the yscale 153 | current_ylim=self.axIR.get_ylim() 154 | update_ylim=False 155 | if M>current_ylim[1] or M<0.5*current_ylim[1]: update_ylim=True 156 | if Mm0.5*np.abs(current_ylim[0]): update_ylim=True 157 | if update_ylim: self.axIR.set_ylim([Mm, 1.2*M]) 158 | 159 | #self.figIR.canvas.draw() 160 | self.fig.canvas.draw() 161 | 162 | 163 | def on_pick(self, event): 164 | """When we click on the figure and hit either the line or the menu items this gets called.""" 165 | if event.artist != self.poles_line and event.artist != self.zeros_line: 166 | return 167 | self.being_dragged = event.ind[0] 168 | self.nature_dragged = event.artist 169 | 170 | 171 | def on_motion(self, event): 172 | """Move the selected points and update the graphs.""" 173 | if event.inaxes != self.ax: return 174 | if self.being_dragged is None: return 175 | p = self.being_dragged #index of points on the line being dragged 176 | xd = event.xdata 177 | yd = event.ydata 178 | #print(yd) 179 | if self.nature_dragged==self.poles_line: 180 | x,y = self.poles_line.get_data() 181 | if not (self.poles_isreal[p]): 182 | x[p],y[p]=xd,yd 183 | else: 184 | if np.pi/2} 106 | \def\egalparerg{{\mathop{=}\limits_\mathrm{erg}}} 107 | \def\egalpardef{\mathop{=}\limits^\triangle} 108 | \def\E#1{\mathbb{E}\left[#1\right]} 109 | \def\flecheTF{\rightleftharpoons } 110 | \def\expo#1{\exp\left(#1\right)} 111 | \def\dr#1{\mathrm{d}#1} 112 | \def\d#1{\mathrm{d}#1} 113 | \def\wb{\mathbf{w}} \def\sb{\mathbf{s}} \def\xb{\mathbf{x}} 114 | \def\Rb{\mathbf{R}} \def\rb{\mathbf{r}} 115 | \def\TFI#1#2#3{{\displaystyle{\int_{-\infty}^{+\infty} #1 ~e^{j2\pi #2 #3} 116 | ~\dr{#2}}}} 117 | \def\TF#1#2#3{{\displaystyle{\int_{-\infty}^{+\infty} #1 ~e^{-j2\pi #3 #2} 118 | ~\dr{#2}}}} 119 | \def\mystar{{*}} 120 | 121 | 122 | \def\R#1{\mathcal{R}\left\{#1\right\}} 123 | \def\I#1{\mathcal{I}\left\{#1\right\}} 124 | \def\tf#1{{\mathrm{FT}\left\{ #1 \right\}}} 125 | \def\sha{w} %{ш} 126 | \def\sinc#1{{\mathrm{sinc}\left( #1 \right)}} 127 | \def\rect{\mathrm{rect}} 128 | \definecolor{lightred}{rgb}{1,0.1,0} 129 | \def\myeqbox#1#2{{\fcolorbox{#1}{light#1}{$\textcolor{#1}{ #2}$}}} 130 | \def\eqbox#1#2#3#4{{\fcolorbox{#1}{#2}{$\textcolor{#3}{ #4}$}}} 131 | % border|background|text 132 | \def\eqboxa#1{{\boxed{#1}}} 133 | \def\eqboxb#1{{\eqbox{green}{white}{green}{#1}}} 134 | \def\eqboxc#1{{\eqbox{blue}{white}{blue}{#1}}} 135 | \def\eqboxd#1{{\eqbox{blue}{lightblue}{blue}{#1}}} 136 | 137 | \def\ub{\mathbf{u}} 138 | \def\wbopt{\mathop{\mathbf{w}}\limits^\triangle} 139 | \def\deriv#1#2{\frac{\mathrm{d}#1}{\mathrm{d}#2}} 140 | \def\Ub{\mathbf{U}} 141 | \def\db{\mathbf{d}} 142 | \def\eb{\mathbf{e}} 143 | \def\yb{\mathbf{y}} 144 | \def\ybp{\mathbf{y}} 145 | \def\est#1{\hat{#1}} 146 | 147 | \def\vb{\mathbf{v}} 148 | \def\Ib{\mathbf{I}} 149 | \def\Vb{\mathbf{V}} 150 | \def\Lambdab{\mathbf{\Lambda}} 151 | \def\Ab{\mathbf{A}} 152 | \def\Bb{\mathbf{B}} 153 | \def\Cb{\mathbf{C}} 154 | \def\Db{\mathbf{D}} 155 | \def\Kb{\mathbf{K}} 156 | 157 | \def\textem#1{\emph{#1}} 158 | %\def\url#1{\href{#1}{}} 159 | 160 | \newtheorem{theorem}{Theorem} 161 | \newtheorem{exercise}{Exercise} 162 | \newtheorem{example}{Example} 163 | \newtheorem{prop}{Property} 164 | \newtheorem{remark}{Remark} 165 | \newtheorem{proposition}{Proposition} 166 | \newtheorem{definition}{Definition} 167 | 168 | 169 | \def\url#1{\texttt{#1}} 170 | 171 | \newenvironment{textboxa} 172 | { \begin{mdframed}[backgroundcolor=yellow]} 173 | { \end{mdframed} } 174 | 175 | 176 | 177 | 178 | 179 | \tableofcontents 180 | \newpage 181 | 182 | %\chapter{Delays and Scales for signals} 183 | \input{DelaysAndScales.tex} 184 | %\chapter{Introduction to filtering} 185 | \input{Intro_Filtering.tex} 186 | %\chapter{Fourier representation} 187 | \input{Intro_Fourier.tex} 188 | \input{Fourier_transform.tex} % 189 | \input{Discrete_Time_Fourier_properties.tex} % 190 | %\chapter{Convolution} 191 | \input{Convolution.tex} 192 | %\chapter{Transfer functions} 193 | \input{TransferFunctions.tex} 194 | %\chapter{Lab: Basic system representation} 195 | \input{Exercises_BasicSystemsRepr.tex} % 196 | \input{BasicSystemsRepr.tex} % 197 | %\chapter{The continuous time case} 198 | \input{Continuous_time_case.tex} % 199 | %\chapter{Periodization and discretization of signals} 200 | \input{Periodization_discretization.tex} 201 | \input{DFT.tex} 202 | %\chapter{Sampling} 203 | \input{Sampling.tex} % 204 | 205 | %\chapter{Lab: image analysis} 206 | \input{LabImages_text.tex} 207 | %\input{LabImages_correction.tex} 208 | 209 | %\chapter{Analysis and Synthesis of Digital filters} 210 | \input{DigitalFilters.tex} 211 | \input{ZerosPoles.tex} 212 | \input{FIR_synthesis.tex} 213 | \input{Bilinear_synthesis.tex} 214 | 215 | %\chapter{Lab: Basic filtering} 216 | \input{BasicFiltering_text.tex} 217 | %\input{BasicFiltering_correction.tex} 218 | 219 | 220 | 221 | \chapter{Random Signals} 222 | \input{Lecture1_RandomSignals} 223 | \input{Lecture2_RandomSignals} 224 | \input{Lecture3_RandomSignals} 225 | 226 | %%Adaptive Filtering 227 | %\chapter{Adaptive filters} 228 | \input{Optimum_filtering_en} 229 | \input{Grad_algo} 230 | \input{Adaptive_versions} 231 | %\input{noisecancellationlab.tex} 232 | 233 | 234 | 235 | \end{document} 236 | -------------------------------------------------------------------------------- /tex/SystemIdentification.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/SystemIdentification.png -------------------------------------------------------------------------------- /tex/bacteria.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/bacteria.png -------------------------------------------------------------------------------- /tex/barbara.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/barbara.png -------------------------------------------------------------------------------- /tex/cellules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/cellules.png -------------------------------------------------------------------------------- /tex/conv_optfilter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/conv_optfilter.jpg -------------------------------------------------------------------------------- /tex/conv_optfilter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/conv_optfilter.png -------------------------------------------------------------------------------- /tex/fig_filter1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/fig_filter1.png -------------------------------------------------------------------------------- /tex/fig_filter2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/fig_filter2.png -------------------------------------------------------------------------------- /tex/fig_template.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/fig_template.jpg -------------------------------------------------------------------------------- /tex/fig_template.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/fig_template.png -------------------------------------------------------------------------------- /tex/jolie_fin_de_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/jolie_fin_de_page.png -------------------------------------------------------------------------------- /tex/lena512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/lena512.png -------------------------------------------------------------------------------- /tex/noisecancellation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/noisecancellation.jpg -------------------------------------------------------------------------------- /tex/saturne.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/saturne.png -------------------------------------------------------------------------------- /tex/saturne_vraie.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jfbercher/LecturesSignalProcessing/d1eb56d2d18b0cd6a7df24e34bcbf3492a42dc52/tex/saturne_vraie.png -------------------------------------------------------------------------------- /update_distrib: -------------------------------------------------------------------------------- 1 | #/usr/bin/env bash 2 | oldcwd=$(pwd) 3 | cd /home/bercherj/JFB/Python/ 4 | #rm -r Lectures_SignalProcessing/*_tmp_files/ 5 | mv Lectures_SignalProcessing.zip Lectures_SignalProcessing_previous.zip 6 | zip -9 Lectures_SignalProcessing.zip Lectures_SignalProcessing/* -x "*tmp_files/" Lectures_SignalProcessing/Lab*.* 7 | zip -9 LabImages.zip Lectures_SignalProcessing/LabImages*.* Lectures_SignalProcessing/*.png -x "*tmp_files/" 8 | zip -9 AdaptiveFiltering.zip Lectures_SignalProcessing/Grad*.* Lectures_SignalProcessing/Optimum_filtering.* Lectures_SignalProcessing/Adaptive_versions.* Lectures_SignalProcessing/*.png Lectures_SignalProcessing/*.css Lectures_SignalProcessing/*.ipy Lectures_SignalProcessing/*.py Lectures_SignalProcessing/*.js Lectures_SignalProcessing/*.jpg Lectures_SignalProcessing/*.npz Lectures_SignalProcessing/*.py -x "*tmp_files/" 9 | 10 | rsync -av --chmod=755 -e "ssh -p 52222" /home/bercherj/JFB/Python/Lectures_SignalProcessing.zip bercherj@ssh.esiee.fr:public_html/Documents/ 11 | rsync -av --chmod=755 -e "ssh -p 52222" /home/bercherj/JFB/Python/LabImages.zip bercherj@ssh.esiee.fr:public_html/Documents/ 12 | rsync -av --chmod=755 -e "ssh -p 52222" /home/bercherj/JFB/Python/AdaptiveFiltering.zip bercherj@ssh.esiee.fr:public_html/Documents/ 13 | 14 | cp toc.html index.html 15 | rsync -av --chmod=755 -e "ssh -p 52222" /home/bercherj/JFB/Python/Lectures_SignalProcessing/*.css bercherj@ssh.esiee.fr:public_html/Lectures_SignalProcessing/ 16 | rsync -av --chmod=755 -e "ssh -p 52222" /home/bercherj/JFB/Python/Lectures_SignalProcessing/*.html bercherj@ssh.esiee.fr:public_html/Lectures_SignalProcessing/ 17 | rsync -av --chmod=755 -e "ssh -p 52222" /home/bercherj/JFB/Python/Lectures_SignalProcessing/*.pdf bercherj@ssh.esiee.fr:public_html/Lectures_SignalProcessing/ 18 | 19 | cd $oldcwd 20 | 21 | 22 | -------------------------------------------------------------------------------- /update_html: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #This is to update html (i) updating links (ii) include header and footer 4 | 5 | title="A Journey in Signal Processing with Jupyter" 6 | listOfFiles=$* 7 | for f in $listOfFiles 8 | do 9 | filename=$(basename -- "$f") 10 | dir=$(dirname "$f") 11 | extension="${filename##*.}" 12 | #filename="${filename%.*}" 13 | 14 | #echo Updating $filename 15 | 16 | if [ "$extension" == "html" ] 17 | then 18 | htmlFile=$dir/$filename 19 | ipynbFile=$dir/${filename%.html}.ipynb 20 | else 21 | ipynbFile=$dir/$filename 22 | htmlFile=$dir/${filename%.ipynb}.html 23 | fi 24 | htmlFilename=$(basename -- "$htmlFile") 25 | ipynbFilename=$(basename -- "$ipynbFile") 26 | 27 | before_after=$(python3 before_after.py $ipynbFile) 28 | 29 | echo [Updating links] 30 | perl -pi -e s/.ipynb/.html/g $htmlFile 31 | 32 | 33 | rep="
34 | 35 |
36 |
37 |
38 |

39 | $ipynbFilename 43 | $title

44 | 46 | 47 | 48 | $before_after 49 | 50 |
51 |
52 |
" 53 | 54 | rep2="
55 |
56 |
57 | 60 |
61 |
62 |
" 63 | origin="
" 64 | origin2="" 65 | 66 | echo [Linking to original notebook] 67 | 68 | perl -pi -e "s#$origin#$rep#g" $htmlFile 69 | perl -pi -e "s#$origin2#$rep2#g" $htmlFile 70 | perl -pi -e s#"TeX-AMS_HTML\""#"TeX-AMS_HTML&delayStartupUntil=onload\""#g $htmlFile 71 | perl -pi -e s#"\[Index\]\(([\S]*)\)"#"\Index\<\/a\>"#g $htmlFile 72 | perl -pi -e s#"\[Back\]\(([\S]*)\)"#"\Back\<\/a\>"#g $htmlFile 73 | perl -pi -e s#"\[Next\]\(([\S]*)\)"#"\Next\<\/a\>"#g $htmlFile 74 | 75 | done 76 | --------------------------------------------------------------------------------