#include <stdio.h> #include <chplot.h> #include <numeric.h> #define N 4 /* data x and y array size */ #define N2 2*N-1 int main() { int i,n1[N],n2[N2]; array double c[N2], x[N]={1,2,3,4}, y[N]={3,2,0,1}; class CPlot plot; linspace(n1,0,N-1); linspace(n2,0,N2-1); correlation(c,x,y); printf("x=%6.3f\n",x); printf("y=%6.3f\n",y); printf("c=%6.3f\n",c); plot.Data2D(n1,x); plot.PlotType(PLOT_PLOTTYPE_IMPULSES, 0); plot.AxisRange(PLOT_AXIS_X, 0,7,1); plot.AxisRange(PLOT_AXIS_Y, 0,17,1); plot.Label(PLOT_AXIS_X,"n"); plot.Label(PLOT_AXIS_Y,"x[n]"); plot.Title("x[n] sequence"); plot.Plotting(); plot.DeletePlots(); plot.Data2D(n1,y); plot.PlotType(PLOT_PLOTTYPE_IMPULSES, 0); plot.AxisRange(PLOT_AXIS_X, 0,7,1); plot.AxisRange(PLOT_AXIS_Y, 0,17,1); plot.Label(PLOT_AXIS_X,"n"); plot.Label(PLOT_AXIS_Y,"y[n]"); plot.Title("y[n] sequence"); plot.Plotting(); plot.DeletePlots(); plot.Data2D(n2,c); plot.PlotType(PLOT_PLOTTYPE_IMPULSES, 0); plot.AxisRange(PLOT_AXIS_X, 0,7,1); plot.AxisRange(PLOT_AXIS_Y, 0,17,1); plot.Label(PLOT_AXIS_X,"n"); plot.Label(PLOT_AXIS_Y,"x[n]"); plot.Title("Output sequence"); plot.Plotting(); }
x= 1.000 2.000 3.000 4.000 y= 3.000 2.000 0.000 1.000 c= 4.000 0.000 0.000 0.000 3.000 4.000 0.000