/programy/C/ix86/signals/correlation |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/programy/C/ix86/signals/correlation.c |
---|
2,89 → 2,50 |
#include <stdlib.h> |
#include <math.h> |
int x[500]; |
int y[500]; |
#define n 500 |
int delay; |
int maxdelay = 500; |
int sample[100]; |
int signal[500]; |
double correlation[1000]; |
int obdelnik(int *pole, int delka_pulsu, int spozdeni) |
int obdelnik(int *pole, int delka_pole, int delka_pulsu, int spozdeni) //generuje testovaci lichobeznikovy puls do zadaneho pole |
{ |
int i; |
int value=1; |
for (i=0; i <= n; i++) { |
if (i < spozdeni && i < n) pole[i]=value; |
for (i=0; i <= delka_pole; i++) { |
if (i < spozdeni && i < delka_pole) pole[i]=value; |
if ((i > spozdeni) && (i < (spozdeni+10))) pole[i] = value++; |
if (i < (spozdeni+delka_pulsu+10) && i > (spozdeni+10) && i < n) pole[i]= value; |
if (i < (spozdeni+delka_pulsu+10) && i > (spozdeni+10) && i < delka_pole) pole[i]= value; |
if (i < (spozdeni+delka_pulsu+20) && i > (spozdeni+delka_pulsu+10) && i < n) pole[i] = value--; |
if (i < (spozdeni+delka_pulsu+20) && i > (spozdeni+delka_pulsu+10) && i < delka_pole) pole[i] = value--; |
if (i > (spozdeni+delka_pulsu+20) && i < n) pole[i]=value; |
if (i > (spozdeni+delka_pulsu+20) && i < delka_pole) pole[i]=value; |
} |
} |
int main (void) |
{ |
int i,j; |
double mx,my,sx,sy,sxy,denom; |
int i,n,m; |
double r; |
fprintf(stdout,"inicializace bufferu s chirpem \n"); |
obdelnik(x,10,40); |
obdelnik(y,10,75); |
obdelnik(sample,100,10,35); // vyrobi vzorek signalu |
obdelnik(signal,500,10,100); // vyrobi signal ve kterem se vzorek hleda |
// vypocita stredni hodnotu signalu |
mx = 0; |
my = 0; |
for (i=0;i<n;i++) { |
mx += x[i]; |
my += y[i]; |
for(n=0; n < 400;n++){ //spocita korelaci pro mozna spozdeni |
r=0; |
for(m=0;m < 100;m++) r += sample[m]*signal[m+n]; |
correlation[n]=r; |
} |
mx /= n; |
my /= n; |
// spoocita jmenovatele |
sx = 0; |
sy = 0; |
for (i=0;i<n;i++) { |
sx += (x[i] - mx) * (x[i] - mx); |
sy += (y[i] - my) * (y[i] - my); |
} |
denom = sqrt(sx*sy); |
//spocita korelacni koeficient |
for (delay=-maxdelay;delay<maxdelay;delay++) { |
sxy = 0; |
for (i=0;i<n;i++) |
for(i=0;i<400;i++) |
{ |
j = i + delay; |
if (j < 0 || j >= n) |
continue; |
else |
sxy += (x[i] - mx) * (y[j] - my); |
/* Or should it be (?) |
if (j < 0 || j >= n) |
sxy += (x[i] - mx) * (-my); |
else |
sxy += (x[i] - mx) * (y[j] - my); |
*/ |
fprintf(stdout,"%3u ",i); // vypise cislo bunky v poli (spozdeni) |
// fprintf(stdout,"%2d ",sample[i]); |
// fprintf(stdout,"%2d ",signal[i]); |
fprintf(stdout,"%3.2f\n",correlation[i]); // vypise hodnotu korelace nejvissi cislo je nejvetsi korelace. |
} |
correlation[delay+maxdelay] = sxy / denom; |
/* r is the correlation coefficient at "delay" */ |
} |
for(i=0;i<=n;i++) |
{ |
fprintf(stdout,"%2d ",x[i]); |
fprintf(stdout,"%2d ",y[i]); |
fprintf(stdout,"%3.2f\n",correlation[i]); |
} |
exit(1); |
} |
/programy/GRC/Sonar/Sonar.py |
---|
4,12 → 4,13 |
# Title: Sonar |
# Author: Kaklik |
# Description: Sonar waform generator |
# Generated: Fri Feb 20 19:31:13 2009 |
# Generated: Sat Feb 21 11:50:42 2009 |
################################################## |
from gnuradio import audio |
from gnuradio import gr |
from gnuradio.wxgui import scopesink2 |
from gnuradio.wxgui import waterfallsink2 |
from grc_gnuradio import wxgui as grc_wxgui |
import wx |
72,6 → 73,19 |
) |
self.wxgui_scopesink2_0.win.set_format_line() |
self.Add(self.wxgui_scopesink2_0.win) |
self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_f( |
self.GetWin(), |
baseband_freq=0, |
y_per_div=10, |
ref_level=50, |
sample_rate=samp_rate, |
fft_size=512, |
fft_rate=15, |
average=True, |
avg_alpha=None, |
title="Waterfall Plot", |
) |
self.Add(self.wxgui_waterfallsink2_0.win) |
################################################## |
# Connections |
79,11 → 93,13 |
self.connect((self.gr_sig_source_x, 0), (self.audio_sink, 0)) |
self.connect((self.gr_sig_source_x, 0), (self.wxgui_scopesink2_0, 0)) |
self.connect((self.audio_source_0, 0), (self.wxgui_scopesink2_0, 1)) |
self.connect((self.audio_source_0, 0), (self.wxgui_waterfallsink2_0, 0)) |
def set_samp_rate(self, samp_rate): |
self.samp_rate = samp_rate |
self.gr_sig_source_x.set_sampling_freq(self.samp_rate) |
self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate*2) |
self.wxgui_waterfallsink2_0.set_sample_rate(self.samp_rate) |
def set_frequency(self, frequency): |
self.frequency = frequency |
/programy/GRC/Sonar/frequency_response.grc |
---|
1,11 → 1,11 |
<?xml version='1.0' encoding='ASCII'?> |
<flow_graph> |
<timestamp>Fri Feb 20 19:47:38 2009</timestamp> |
<timestamp>Sat Feb 21 13:28:42 2009</timestamp> |
<block> |
<key>audio_sink</key> |
<key>options</key> |
<param> |
<key>id</key> |
<value>audio_sink_0</value> |
<value>frequency_response</value> |
</param> |
<param> |
<key>_enabled</key> |
12,24 → 12,36 |
<value>True</value> |
</param> |
<param> |
<key>samp_rate</key> |
<value>48000</value> |
<key>title</key> |
<value>untitled</value> |
</param> |
<param> |
<key>device_name</key> |
<value>hw:1,0</value> |
<key>author</key> |
<value>unknown</value> |
</param> |
<param> |
<key>ok_to_block</key> |
<value>True</value> |
<key>description</key> |
<value>gnuradio flow graph</value> |
</param> |
<param> |
<key>num_inputs</key> |
<key>window_size</key> |
<value>1280, 1024</value> |
</param> |
<param> |
<key>generate_options</key> |
<value>wx_gui</value> |
</param> |
<param> |
<key>category</key> |
<value>Custom</value> |
</param> |
<param> |
<key>realtime_scheduling</key> |
<value>1</value> |
</param> |
<param> |
<key>_coordinate</key> |
<value>(653, 387)</value> |
<value>(10, 10)</value> |
</param> |
<param> |
<key>_rotation</key> |
95,41 → 107,6 |
</param> |
</block> |
<block> |
<key>gr_noise_source_x</key> |
<param> |
<key>id</key> |
<value>gr_noise_source_x_0</value> |
</param> |
<param> |
<key>_enabled</key> |
<value>True</value> |
</param> |
<param> |
<key>type</key> |
<value>float</value> |
</param> |
<param> |
<key>noise_type</key> |
<value>gr.GR_UNIFORM</value> |
</param> |
<param> |
<key>amp</key> |
<value>1</value> |
</param> |
<param> |
<key>seed</key> |
<value>100</value> |
</param> |
<param> |
<key>_coordinate</key> |
<value>(450, 388)</value> |
</param> |
<param> |
<key>_rotation</key> |
<value>0</value> |
</param> |
</block> |
<block> |
<key>wxgui_fftsink2</key> |
<param> |
<key>id</key> |
201,10 → 178,10 |
</param> |
</block> |
<block> |
<key>options</key> |
<key>gr_noise_source_x</key> |
<param> |
<key>id</key> |
<value>frequency_response</value> |
<value>gr_noise_source_x_0</value> |
</param> |
<param> |
<key>_enabled</key> |
211,36 → 188,59 |
<value>True</value> |
</param> |
<param> |
<key>title</key> |
<value>untitled</value> |
<key>type</key> |
<value>float</value> |
</param> |
<param> |
<key>author</key> |
<value>unknown</value> |
<key>noise_type</key> |
<value>gr.GR_UNIFORM</value> |
</param> |
<param> |
<key>description</key> |
<value>gnuradio flow graph</value> |
<key>amp</key> |
<value>1</value> |
</param> |
<param> |
<key>window_size</key> |
<value>1280, 1024</value> |
<key>seed</key> |
<value>100</value> |
</param> |
<param> |
<key>generate_options</key> |
<value>wx_gui</value> |
<key>_coordinate</key> |
<value>(371, 291)</value> |
</param> |
<param> |
<key>category</key> |
<value>Custom</value> |
<key>_rotation</key> |
<value>0</value> |
</param> |
</block> |
<block> |
<key>audio_sink</key> |
<param> |
<key>realtime_scheduling</key> |
<value>1</value> |
<key>id</key> |
<value>audio_sink_0</value> |
</param> |
<param> |
<key>_enabled</key> |
<value>True</value> |
</param> |
<param> |
<key>samp_rate</key> |
<value>48000</value> |
</param> |
<param> |
<key>device_name</key> |
<value>hw:1,0</value> |
</param> |
<param> |
<key>ok_to_block</key> |
<value>True</value> |
</param> |
<param> |
<key>num_inputs</key> |
<value>2</value> |
</param> |
<param> |
<key>_coordinate</key> |
<value>(10, 10)</value> |
<value>(635, 295)</value> |
</param> |
<param> |
<key>_rotation</key> |
259,4 → 259,10 |
<source_key>0</source_key> |
<sink_key>0</sink_key> |
</connection> |
<connection> |
<source_block_id>gr_noise_source_x_0</source_block_id> |
<sink_block_id>audio_sink_0</sink_block_id> |
<source_key>0</source_key> |
<sink_key>1</sink_key> |
</connection> |
</flow_graph> |
/programy/GRC/Sonar/frequency_response.py |
---|
4,7 → 4,7 |
# Title: untitled |
# Author: unknown |
# Description: gnuradio flow graph |
# Generated: Fri Feb 20 19:47:38 2009 |
# Generated: Sat Feb 21 13:28:44 2009 |
################################################## |
from gnuradio import audio |
54,6 → 54,7 |
################################################## |
self.connect((self.gr_noise_source_x_0, 0), (self.audio_sink_0, 0)) |
self.connect((self.audio_source_0, 0), (self.wxgui_fftsink2_0, 0)) |
self.connect((self.gr_noise_source_x_0, 0), (self.audio_sink_0, 1)) |
def set_samp_rate(self, samp_rate): |
self.samp_rate = samp_rate |
/programy/GRC/Sonar/sonar.grc |
---|
1,6 → 1,6 |
<?xml version='1.0' encoding='ASCII'?> |
<flow_graph> |
<timestamp>Fri Feb 20 19:31:11 2009</timestamp> |
<timestamp>Sat Feb 21 12:00:12 2009</timestamp> |
<block> |
<key>options</key> |
<param> |
252,6 → 252,61 |
</param> |
</block> |
<block> |
<key>wxgui_scopesink2</key> |
<param> |
<key>id</key> |
<value>wxgui_scopesink2_0</value> |
</param> |
<param> |
<key>_enabled</key> |
<value>True</value> |
</param> |
<param> |
<key>type</key> |
<value>float</value> |
</param> |
<param> |
<key>title</key> |
<value>Scope Plot</value> |
</param> |
<param> |
<key>samp_rate</key> |
<value>samp_rate*2</value> |
</param> |
<param> |
<key>frame_decim</key> |
<value>15</value> |
</param> |
<param> |
<key>v_scale</key> |
<value>0</value> |
</param> |
<param> |
<key>t_scale</key> |
<value>.0001</value> |
</param> |
<param> |
<key>marker</key> |
<value>set_format_line</value> |
</param> |
<param> |
<key>num_inputs</key> |
<value>2</value> |
</param> |
<param> |
<key>grid_pos</key> |
<value></value> |
</param> |
<param> |
<key>_coordinate</key> |
<value>(770, 294)</value> |
</param> |
<param> |
<key>_rotation</key> |
<value>0</value> |
</param> |
</block> |
<block> |
<key>audio_source</key> |
<param> |
<key>id</key> |
287,10 → 342,10 |
</param> |
</block> |
<block> |
<key>wxgui_scopesink2</key> |
<key>wxgui_waterfallsink2</key> |
<param> |
<key>id</key> |
<value>wxgui_scopesink2_0</value> |
<value>wxgui_waterfallsink2_0</value> |
</param> |
<param> |
<key>_enabled</key> |
302,39 → 357,47 |
</param> |
<param> |
<key>title</key> |
<value>Scope Plot</value> |
<value>Waterfall Plot</value> |
</param> |
<param> |
<key>samp_rate</key> |
<value>samp_rate*2</value> |
<value>samp_rate</value> |
</param> |
<param> |
<key>frame_decim</key> |
<value>15</value> |
<key>baseband_freq</key> |
<value>0</value> |
</param> |
<param> |
<key>v_scale</key> |
<value>0</value> |
<key>y_per_div</key> |
<value>10</value> |
</param> |
<param> |
<key>t_scale</key> |
<value>.0001</value> |
<key>ref_level</key> |
<value>50</value> |
</param> |
<param> |
<key>marker</key> |
<value>set_format_line</value> |
<key>fft_size</key> |
<value>512</value> |
</param> |
<param> |
<key>num_inputs</key> |
<value>2</value> |
<key>fft_rate</key> |
<value>15</value> |
</param> |
<param> |
<key>avg_alpha</key> |
<value>0</value> |
</param> |
<param> |
<key>options</key> |
<value>average</value> |
</param> |
<param> |
<key>grid_pos</key> |
<value></value> |
</param> |
<param> |
<key>_coordinate</key> |
<value>(770, 294)</value> |
<value>(775, 434)</value> |
</param> |
<param> |
<key>_rotation</key> |
359,4 → 422,10 |
<source_key>0</source_key> |
<sink_key>1</sink_key> |
</connection> |
<connection> |
<source_block_id>audio_source_0</source_block_id> |
<sink_block_id>wxgui_waterfallsink2_0</sink_block_id> |
<source_key>0</source_key> |
<sink_key>0</sink_key> |
</connection> |
</flow_graph> |