modelisationanalysespectrale/rossignol/nonParametrique/.ipynb_checkpoints/Analyse-Non-Param-MySon-checkpoint.ipynb

248 lines
6.1 KiB
Text
Raw Normal View History

2019-10-02 12:36:08 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Analyse non paramétrique du signal de la flute\n",
"\n",
"Nous allons commencer par afficher le signals\n",
"\n",
"/TODO mettre des labels X/Y avec unités et des titres à toutes les figure"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"using WAV\n",
"\n",
"s, fs = wavread(\"../myson.wav\");\n",
"s = vec(s);\n",
"t = (0 : 1 : size(s)[1]-1)/fs;\n",
"fs = floor(Int, fs);\n",
"\n",
"t_s = 10 #s\n",
"trame_period = 0.005 #s\n",
"\n",
"floor_freq = 10 #Hz\n",
"ceil_freq = 60 #Hz\n",
"\n",
"number_trame = 50 # trames on each side of t_s\n",
"overlap = 0.0001;#s\n",
"\n",
"N_fft = 2^18- 1; #number points fft"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using Plots\n",
"plot(t, s, title=\"Son bizarre\",label=[\"Signal\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Regardons des trames. La taille de trame reste classique : de l'ordre de 20ms.\n",
"\n",
"/TODO attention Gabor\n",
"\n",
"/TODO FFT avec gros nombre"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#using LinearAlgebra\n",
"\n",
"#plot(t_trame, s_trame)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using FFTW\n",
"\n",
"i_s = floor(Int, t_s*fs+1)\n",
"i_e = floor(Int, i_s+trame_period*fs)\n",
"t_trame = t[i_s:i_e]\n",
"s_trame = s[i_s:i_e]\n",
"\n",
"# Fourier Transform of it \n",
"s_pad = zeros(N_fft)\n",
"s_pad[1:size(s_trame,1), 1:size(s_trame,2)]=s_trame\n",
"F = fft(s_pad) |> fftshift\n",
"freqs = fftfreq(N_fft, fs) |> fftshift\n",
"\n",
"# plots \n",
"time_domain = plot(t_trame, s_trame, title = \"Signal\")\n",
"freq_domain = plot(freqs, abs.(F), title = \"Spectrum\", xlim=(-1000, +1000)) \n",
"plot(time_domain, freq_domain, layout = 2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"i_s = floor(Int, t_s*fs-number_trame*trame_period*fs+1)\n",
"i_e = floor(Int, i_s+2*number_trame*trame_period*fs)\n",
"t_trame = t[i_s:i_e]\n",
"s_trame = s[i_s:i_e]\n",
"\n",
"# Fourier Transform of it \n",
"s_pad = zeros(N_fft)\n",
"s_pad[1:size(s_trame,1), 1:size(s_trame,2)]=s_trame\n",
"F = fft(s_pad) |> fftshift\n",
"freqs = fftfreq(N_fft, fs) |> fftshift\n",
"\n",
"# plots \n",
"time_domain = plot(t_trame, s_trame, title = \"Signal\")\n",
"freq_domain = plot(freqs, abs.(F), title = \"Spectrum\", xlim=(-1000, +1000)) \n",
"plot(time_domain, freq_domain, layout = 2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On cherche maintenant la fréquence du fondamental. Comme il s'agit d'un instrument à vent, on choisit notre interval de fréquence."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using WORLD\n",
"\n",
"f0, timeaxis = harvest(s, fs, HarvestOption(floor_freq, ceil_freq, trame_period));#floor and ceil freq, period\n",
"plot(timeaxis, f0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On observe des vibratos, par exemple un gros vibrato vers 5s, un \"fa\". La fréquence du son ne correspond pas exactement à la fréquence du fondamental. On a une modulation de fréquence.\n",
"\n",
"/TODO étudier cette modulation de fréquence\n",
"\n",
"Regardons un zoom sur un vibrato. \n",
"\n",
"/TODO fft du petit bout de signal"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"i_s = floor(Int, t_s*fs-number_trame*trame_period*fs+1)\n",
"i_e = floor(Int, i_s+2*number_trame*trame_period*fs)\n",
"t_trame = t[i_s:i_e]\n",
"s_trame = s[i_s:i_e]\n",
"\n",
"f0, timeaxis = harvest(s_trame, fs, HarvestOption(floor_freq, ceil_freq, trame_period));#floor and ceil freq, period\n",
"plot(timeaxis.+t_trame[1], f0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On va s'intéresser maintenant au spectrogramme.\n",
"\n",
"\\TODO On choisit une fenêtre XXXX car XXX"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"using DSP, PyPlot\n",
"\n",
"println(floor(Int, trame_period*fs), floor(Int, overlap*fs))\n",
"S = spectrogram(s, floor(Int, trame_period*fs), floor(Int, overlap*fs); fs=fs, window=hanning)\n",
"t = time(S)\n",
"f = freq(S)\n",
"imshow(reverse(log10.(power(S)), dims=1), extent=[first(t), last(t), first(f), last(f)], aspect=\"auto\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Zoom sur notre vibrato que l'on voit un peu"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"S = spectrogram(s_trame, floor(Int, trame_period*fs), floor(Int, overlap*fs); fs=fs, window=hanning)\n",
"t = time(S)\n",
"f = freq(S)\n",
"imshow(reverse(log10.(power(S)), dims=1), extent=[first(t).+t_trame[1], last(t).+t_trame[1], first(f), last(f)], aspect=\"auto\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.2.0",
"language": "julia",
"name": "julia-1.2"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}