AddedDTW
This commit is contained in:
parent
2ff209a38b
commit
658e423553
|
@ -57,7 +57,7 @@ CLEAN_OBJECTS = $(wildcard bin/*.o) $(PROGRAM)
|
||||||
all: $(PROGRAM)
|
all: $(PROGRAM)
|
||||||
|
|
||||||
$(PROGRAM): $(OBJECT_FILES)
|
$(PROGRAM): $(OBJECT_FILES)
|
||||||
$(CC) $(CFLAGS) $(OBJECT_FILES) -o $(PROGRAM) $(LDLIBS)
|
$(CC) $(CFLAGS) $(OBJECT_FILES) -o $(PROGRAM) $(LDLIBS) -lm
|
||||||
|
|
||||||
bin/%.o: src/%.c
|
bin/%.o: src/%.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
/*pavan changes*/
|
||||||
|
|
||||||
|
void DTWdistance(struct data_frame *df,gboolean *result);
|
|
@ -0,0 +1,22 @@
|
||||||
|
import csv
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
x=[]
|
||||||
|
y=[]
|
||||||
|
x1=[]
|
||||||
|
y1=[]
|
||||||
|
with open('points.csv', mode ='r') as file:
|
||||||
|
csvFile = csv.reader(file)
|
||||||
|
for lines in csvFile:
|
||||||
|
print(lines)
|
||||||
|
x.append(float(lines[0]))
|
||||||
|
y.append(0)
|
||||||
|
x1.append(float(lines[2]))
|
||||||
|
y1.append(0)
|
||||||
|
|
||||||
|
plt.scatter(x, y)
|
||||||
|
|
||||||
|
plt.scatter(x1, y1)
|
||||||
|
|
||||||
|
plt.show()
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,83 @@
|
||||||
|
|
||||||
|
#include "parser.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
long double *freq1;
|
||||||
|
long double *freq2;
|
||||||
|
int count_track1=0;
|
||||||
|
int count_track2=0;
|
||||||
|
int flag=0;
|
||||||
|
|
||||||
|
void DTWdistance(struct data_frame *df,gboolean *result)
|
||||||
|
{
|
||||||
|
float CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq)*1e-3;
|
||||||
|
//printf("count1: %d\ncount2: %d\n",count_track1,count_track2);
|
||||||
|
//printf("curr_freq: %f\n",CURR_FREQ);
|
||||||
|
if(count_track1==0)
|
||||||
|
{
|
||||||
|
if(flag==0)
|
||||||
|
{
|
||||||
|
flag=1;
|
||||||
|
freq1 = (long double *)malloc(500 * sizeof(long double));
|
||||||
|
}
|
||||||
|
freq1[count_track2]=CURR_FREQ;
|
||||||
|
count_track2++;
|
||||||
|
if(count_track2==500)
|
||||||
|
{
|
||||||
|
count_track2=0;
|
||||||
|
flag=0;
|
||||||
|
count_track1++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(count_track1==1)
|
||||||
|
{
|
||||||
|
if(flag==0)
|
||||||
|
{
|
||||||
|
flag=1;
|
||||||
|
freq2 = (long double *)malloc(500 * sizeof(long double));
|
||||||
|
}
|
||||||
|
freq2[count_track2]=CURR_FREQ;
|
||||||
|
count_track2++;
|
||||||
|
if(count_track2==500)
|
||||||
|
{
|
||||||
|
count_track2=0;
|
||||||
|
flag=0;
|
||||||
|
count_track1++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
float** DTW = (float**)malloc(501 * sizeof(float*));
|
||||||
|
for (int i = 0; i < 501; i++)
|
||||||
|
DTW[i] = (float*)malloc(501 * sizeof(float));
|
||||||
|
|
||||||
|
for(int i=0;i<501;i++)
|
||||||
|
{
|
||||||
|
for(int j=0;j<501;j++)
|
||||||
|
DTW[i][j]=1000;
|
||||||
|
}
|
||||||
|
DTW[0][0]=0;
|
||||||
|
|
||||||
|
for(int i=1;i<501;i++)
|
||||||
|
{
|
||||||
|
for(int j=1;j<501;j++)
|
||||||
|
{
|
||||||
|
float cost=fabs(freq1[i-1]-freq2[j-1]);
|
||||||
|
//printf("cost: %f",cost);
|
||||||
|
DTW[i][j]=cost+fmin(DTW[i][j-1],fmin(DTW[i-1][j],DTW[i-1][j-1]));
|
||||||
|
//printf(" DTW[%d][%d]: %f\n",i,j,DTW[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("DTWdistance: %f\n",DTW[500][500]);
|
||||||
|
if(DTW[500][500]>=35) *result=false;
|
||||||
|
else *result=true;
|
||||||
|
free(freq1);
|
||||||
|
free(freq2);
|
||||||
|
free(DTW);
|
||||||
|
count_track1=0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,16 +2,22 @@
|
||||||
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gtk/gtk.h>
|
c
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
gboolean kmeans(struct data_frame *df,unsigned long long int *count_A,unsigned long long int *count_B,
|
gboolean kmeans(struct data_frame *df,unsigned long long int *count_A,unsigned long long int *count_B,
|
||||||
unsigned long long int *count_C,long double *A,long double *B,long double *C)
|
unsigned long long int *count_C,long double *A,long double *B,long double *C)
|
||||||
{
|
{
|
||||||
float CURR_FREQ = to_intconvertor(df->dpmu[0]->freq);
|
float CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq)*1e-3;
|
||||||
long double diff_A = fabs(*A-CURR_FREQ);
|
long double diff_A = fabs(*A-CURR_FREQ);
|
||||||
long double diff_B = fabs(*B-CURR_FREQ);
|
long double diff_B = fabs(*B-CURR_FREQ);
|
||||||
long double diff_C = fabs(*C-CURR_FREQ);
|
long double diff_C = fabs(*C-CURR_FREQ);
|
||||||
printf("A: %Lf, B: %Lf, C: %Lf\n",*A,*B,*C);
|
//fp = fopen("points.csv","a");
|
||||||
|
//printf("A: %Lf, B: %Lf, C: %Lf\n",*A,*B,*C);
|
||||||
|
//fprintf(fp,"%Lf, %Lf, %Lf\n",*A,*B,*C);
|
||||||
|
//fclose(fp);
|
||||||
if(diff_A <= diff_B && diff_A <= diff_C){
|
if(diff_A <= diff_B && diff_A <= diff_C){
|
||||||
*A = ((*count_A*(*A))+CURR_FREQ)/(++*count_A);
|
*A = ((*count_A*(*A))+CURR_FREQ)/(++*count_A);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "align_sort.h"
|
#include "align_sort.h"
|
||||||
#include "map_vis.h"
|
#include "map_vis.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "osm-gps-map.h"
|
#include "osm-gps-map.h"
|
||||||
#include "Attack_detect.h"
|
#include "Attack_detect.h"
|
||||||
#include "Kmeans.h"
|
#include "Kmeans.h"
|
||||||
|
#include "Dynamic_time_warping.h"
|
||||||
|
|
||||||
|
gboolean value = true;
|
||||||
|
|
||||||
gboolean update_images(gpointer* pars){
|
gboolean update_images(gpointer* pars){
|
||||||
myParameters* parameters = (myParameters*) pars;
|
myParameters* parameters = (myParameters*) pars;
|
||||||
|
@ -15,7 +18,10 @@ gboolean update_images(gpointer* pars){
|
||||||
}
|
}
|
||||||
int freq = to_intconvertor(df->dpmu[0]->freq);
|
int freq = to_intconvertor(df->dpmu[0]->freq);
|
||||||
//gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
|
//gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
|
||||||
gboolean green = kmeans(df,&count_A,&count_B,&count_C,&A,&B,&C);
|
//printf("map_vis A: %Lf, B: %Lf,C: %Lf\n",A,B,C);
|
||||||
|
//gboolean green = kmeans(df,&count_A,&count_B,&count_C,&A,&B,&C);
|
||||||
|
DTWdistance(df,&value);
|
||||||
|
gboolean green=value;
|
||||||
if(parameters->g_last_image != 0){
|
if(parameters->g_last_image != 0){
|
||||||
osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
|
osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ void utility_tools(GtkButton *but, gpointer udata)
|
||||||
NULL);
|
NULL);
|
||||||
osm_gps_map_set_center_and_zoom (util_map, 15.4589, 75.0078, 10);
|
osm_gps_map_set_center_and_zoom (util_map, 15.4589, 75.0078, 10);
|
||||||
|
|
||||||
g_last_image = osm_gps_map_image_add(util_map,15.4589, 75.0078, g_red_image);
|
//g_last_image = osm_gps_map_image_add(util_map,15.4589, 75.0078, g_red_image);
|
||||||
g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image);
|
g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image);
|
||||||
myParameters parameters = {util_map, g_red_image, g_green_image, g_last_image};
|
myParameters parameters = {util_map, g_red_image, g_green_image, g_last_image};
|
||||||
gpointer data = (gpointer) ¶meters;
|
gpointer data = (gpointer) ¶meters;
|
||||||
|
|
Loading…
Reference in New Issue