什么是在这个程序中的错误呢? [英] what is the mistake in this program?

查看:77
本文介绍了什么是在这个程序中的错误呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code查找两个信号的卷积,但我的输出变为零每次谁能解释错在我的code?
我试图compling,但我无法findout是什么问题我的整个code是正确的
在此先感谢

 #包括LT&;&stdio.h中GT;
#包括LT&;&stdlib.h中GT;
#定义array_len(X)(sizeof的(X)/的sizeof(双))
无效卷积(双*信号,诠释NT,双风*,INT R,双* RM)
{
    INT I,J;
    的printf(%U \\ N的sizeof(风));
    INT L =(NT + R-1);
    对(我= R; I< = 1;我++)
    {
        风由[i] = 0;
    }
        对于(i = NT; I< = 1;我++)
        {
            信号由[i] = 0;
        }
        的printf(信号\\ n);
        对于(i = 0; I< = 1;我++)
        {
            的printf(%LF \\ n,信号[I]);
        }
        对于(i = 0; I< = 1;我++)
        {
            RM [I] = 0;
            为(J = 0; J< = I; J ++)
            {
                RM [I] =(RM [I] +(信号[J] *风[I-J]));
            }
        }
}无效的主要()
{
    双A [] = {1,2,3,4};
    INT I;
    INT LA = array_len(一);
    的printf(\\ NC1 \\ T%LD,LA);
    重B [] = {1,1,1,1};
    INT磅= array_len(B);
    的printf(\\ NC2 \\ T%LD \\ N,磅);
    双R [LA + LB-1];
    INT LR = array_len(R);
    的printf(\\第三次通报\\ T%LD \\ N,LR);    的printf(进入卷积\\ n);
    卷积(一,1a,1b和磅,R);    对于(i = 0;我≤(LR);我++)
    {
        的printf(RM [%d个=%LF \\ n,I,R [I]);
    }
}


解决方案

您试试这个!

 无效卷积(双*信号,诠释NT,双风*,INT R,双* RM)
{
    INT I,J;
    的printf(%U \\ N的sizeof(风)); // 你为什么这么做?这只是返回指针的大小只
    INT L =(NT + R-1);
    双一[L];
    双倍二级[L];
    对于(i = 0; I<升;我++)
    {
        如果(I< NT)
            酮[I] =信号由[i];
        其他
            酮[I] = 0;
        如果(ⅰ&下; r)的
            2个[i] =风[I]
        其他
            有2个[I] = 0;
    }
    的printf(信号\\ n);
    对于(i = 0; I<升;我++)
        的printf(%LF \\ n,一是[I]);
    对于(i = 0; I<升;我++)
    {
        RM [I] = 0;
        为(J = 0; J< = I; J ++)
        {
            RM [I] =(RM [I] +(一个[J] * 2个[I-J]));
        }
    }
}

This is my code for finding the convolution of two signals but my output is becoming zero everytime can anyone explain the mistake in my code? I tried compling it but I'm unable to findout what is the problem my whole code is correct thanks in advance

#include<stdio.h>
#include<stdlib.h>
#define array_len(x) (sizeof(x)/sizeof(double))
void convolution(double *signal, int nt, double *wind, int r, double *rm)
{
    int i,j;
    printf("%u\n", sizeof(wind));
    int l = (nt+r-1);
    for(i=r;i<=l;i++)
    {
        wind[i]=0;
    }
        for(i=nt;i<=l;i++)
        {
            signal[i]=0;
        }
        printf("signal\n");
        for(i=0; i<=l; i++)
        {
            printf("%lf\n",signal[i]);
        }
        for(i=0;i<=l;i++)
        {
            rm[i]=0;
            for(j=0;j<=i;j++)
            {
                rm[i] = (rm[i]+(signal[j]*wind[i-j]) );
            }   
        }
}



void main()
{
    double a[] = {1,2,3,4};
    int i;
    int la = array_len(a);
    printf("\nc1\t%ld",la);
    double b[] = {1,1,1,1} ;
    int lb = array_len(b);
    printf("\nc2\t%ld\n",lb);
    double r[la+lb-1];
    int lr = array_len(r);
    printf("\nc3\t%ld\n",lr);

    printf("entering convolution\n");
    convolution(a,la,b,lb,r);

    for(i=0;i<(lr);i++)
    {
        printf("rm[%d]=%lf\n",i,r[i]);
    }
}

解决方案

You try this!

void convolution(double *signal, int nt, double *wind, int r, double *rm)
{
    int i,j;
    printf("%u\n", sizeof(wind));  // Why you do this? this just returns the size of the pointer only
    int l = (nt+r-1);
    double one[l];
    double two[l];
    for(i=0;i<l;i++)
    {
        if (i < nt)
            one[i] = signal[i];
        else
            one[i] = 0;
        if (i < r)
            two[i] = wind[i];
        else
            two[i] = 0;
    }
    printf("signal\n");
    for(i=0; i<l; i++)
        printf("%lf\n",one[i]);
    for(i=0;i<l;i++)
    {
        rm[i]=0;
        for(j=0;j<=i;j++)
        {
            rm[i] = (rm[i]+(one[j]*two[i-j]) );
        }   
    }
}

这篇关于什么是在这个程序中的错误呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆