1. c语言进行特定格式文本文件的筛选与判断
/*
原始数据:
9300100 10
9300101 10
9300102 10
9300110 10
9300111 10
9301110 20
9301111 20
9301112 20
处理后数据:
930010 10
930011 10
930111 20
Press any key to continue
*/
#include<stdio.h>
#defineN60
intmain(){
inti,j,n,k,flag,data1[N],data2[N];
FILE*fp=fopen("indata.txt","rt");
if(fp==NULL){
printf("无法打开数据文件。 ");
return1;
}
printf("原始数据: ");
for(n=0;!feof(fp)&&n<N;++n){
fscanf(fp,"%d,%d",&data1[n],&data2[n]);
printf("%d %d ",data1[n],data2[n]);
data1[n]/=10;//去除末位
}
fclose(fp);
for(i=0;i<n-1;++i){
flag=0;
for(j=i+1;j<n;++j){
if(data1[j]==data1[i]&&data2[j]==data2[i]){
for(k=j;k<n-1;++k){
data1[k]=data1[k+1];
data2[k]=data2[k+1];
}
--n;
flag=1;
}
}
if(flag)--i;
}
printf("处理后数据: ");
for(i=0;i<n;++i)
printf("%d %d ",data1[i],data2[i]);
return0;
}
2. c语言命令行在一个文件中查找另一个文件指定的内容
f=fopen("filter.txt","r");
f1=fopen("serieA.txt","r");
while(fgets(line,50,f)!=NULL)
{
while(fgets(line,50,f1)!=NULL)
if(strcmp(nameF,nameS)==0).....
rewind(f1);
}
3. C语言实现fir1函数
#include <stdio.h>
#ifdef WIN32
#include <conio.h>
#endif
#define SAMPLE double /* define the type used for data samples */
void clear(int ntaps, SAMPLE z[])
{
int ii;
for (ii = 0; ii < ntaps; ii++) {
z[ii] = 0;
}
}
SAMPLE fir_basic(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[])
{
int ii;
SAMPLE accum;
/* store input at the beginning of the delay line */
z[0] = input;
/* calc FIR */
accum = 0;
for (ii = 0; ii < ntaps; ii++) {
accum += h[ii] * z[ii];
}
/* shift delay line */
for (ii = ntaps - 2; ii >= 0; ii--) {
z[ii + 1] = z[ii];
}
return accum;
}
SAMPLE fir_circular(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],
int *p_state)
{
int ii, state;
SAMPLE accum;
state = *p_state; /* the filter's state to a local */
/* store input at the beginning of the delay line */
z[state] = input;
if (++state >= ntaps) { /* incr state and check for wrap */
state = 0;
}
/* calc FIR and shift data */
accum = 0;
for (ii = ntaps - 1; ii >= 0; ii--) {
accum += h[ii] * z[state];
if (++state >= ntaps) { /* incr state and check for wrap */
state = 0;
}
}
*p_state = state; /* return new state to caller */
return accum;
}
SAMPLE fir_shuffle(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[])
{
int ii;
SAMPLE accum;
/* store input at the beginning of the delay line */
z[0] = input;
/* calc FIR and shift data */
accum = h[ntaps - 1] * z[ntaps - 1];
for (ii = ntaps - 2; ii >= 0; ii--) {
accum += h[ii] * z[ii];
z[ii + 1] = z[ii];
}
return accum;
}
SAMPLE fir_split(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],
int *p_state)
{
int ii, end_ntaps, state = *p_state;
SAMPLE accum;
SAMPLE const *p_h;
SAMPLE *p_z;
/* setup the filter */
accum = 0;
p_h = h;
/* calculate the end part */
p_z = z + state;
*p_z = input;
end_ntaps = ntaps - state;
for (ii = 0; ii < end_ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* calculate the beginning part */
p_z = z;
for (ii = 0; ii < state; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement the state, wrapping if below zero */
if (--state < 0) {
state += ntaps;
}
*p_state = state; /* return new state to caller */
return accum;
}
SAMPLE fir_double_z(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],
int *p_state)
{
SAMPLE accum;
int ii, state = *p_state;
SAMPLE const *p_h, *p_z;
/* store input at the beginning of the delay line as well as ntaps more */
z[state] = z[state + ntaps] = input;
/* calculate the filter */
p_h = h;
p_z = z + state;
accum = 0;
for (ii = 0; ii < ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement state, wrapping if below zero */
if (--state < 0) {
state += ntaps;
}
*p_state = state; /* return new state to caller */
return accum;
}
SAMPLE fir_double_h(SAMPLE input, int ntaps, const SAMPLE h[], SAMPLE z[],
int *p_state)
{
SAMPLE accum;
int ii, state = *p_state;
SAMPLE const *p_h, *p_z;
/* store input at the beginning of the delay line */
z[state] = input;
/* calculate the filter */
p_h = h + ntaps - state;
p_z = z;
accum = 0;
for (ii = 0; ii < ntaps; ii++) {
accum += *p_h++ * *p_z++;
}
/* decrement state, wrapping if below zero */
if (--state < 0) {
state += ntaps;
}
*p_state = state; /* return new state to caller */
return accum;
}
int main(void)
{
#define NTAPS 6
static const SAMPLE h[NTAPS] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 };
static SAMPLE h2[2 * NTAPS];
static SAMPLE z[2 * NTAPS];
#define IMP_SIZE (3 * NTAPS)
static SAMPLE imp[IMP_SIZE];
SAMPLE output;
int ii, state;
/* make impulse input signal */
clear(IMP_SIZE, imp);
imp[5] = 1.0;
/* create a SAMPLEd h */
for (ii = 0; ii < NTAPS; ii++) {
h2[ii] = h2[ii + NTAPS] = h[ii];
}
/* test FIR algorithms */
printf("Testing fir_basic:\n ");
clear(NTAPS, z);
for (ii = 0; ii < IMP_SIZE; ii++) {
output = fir_basic(imp[ii], NTAPS, h, z);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_shuffle:\n ");
clear(NTAPS, z);
state = 0;
for (ii = 0; ii < IMP_SIZE; ii++) {
output = fir_shuffle(imp[ii], NTAPS, h, z);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_circular:\n ");
clear(NTAPS, z);
state = 0;
for (ii = 0; ii < IMP_SIZE; ii++) {
output = fir_circular(imp[ii], NTAPS, h, z, &state);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_split:\n ");
clear(NTAPS, z);
state = 0;
for (ii = 0; ii < IMP_SIZE; ii++) {
output = fir_split(imp[ii], NTAPS, h, z, &state);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_double_z:\n ");
clear(2 * NTAPS, z);
state = 0;
for (ii = 0; ii < IMP_SIZE; ii++) {
output = fir_double_z(imp[ii], NTAPS, h, z, &state);
printf("%3.1lf ", (double) output);
}
printf("\n\n");
printf("Testing fir_double_h:\n ");
clear(NTAPS, z);
state = 0;
for (ii = 0; ii < IMP_SIZE; ii++) {
output = fir_double_h(imp[ii], NTAPS, h2, z, &state);
printf("%3.1lf ", (double) output);
}
#ifdef WIN32
printf("\n\nHit any key to continue.");
getch();
#endif
return 0;
}
1. fir_basic: 实现基本的FIR滤波器
2. fir_circular: 说明环行buffer是如何实现FIR的。
3. fir_shuffle: 一些TI的处理器上使用的shuffle down技巧
4. fir_split: 把FIR滤波器展开为两块,避免使用环行缓存。
5. fir_double_z: 使用双精度的延迟线,使可以使用一个flat buffer。
6. fir_double_h: 使用双精度的系数,使可以使用一个flat buffer。
4. FIR滤波器的C语言程序
length==256
5. 一段matlab低通滤波器程序,求改编成C语言。
这个我刚好做过一个滤波器,事实上对时域信号做FFT,截取一定点数再做逆FFT相当于理想滤波。设计滤波器代码如下:
f1=100;f2=200;%待滤波正弦信号频率
fs=2000;%采样频率
m=(0.3*f1)/(fs/2);%定义过度带宽
M=round(8/m);%定义窗函数的长度
N=M-1;%定义滤波器的阶数
b=fir1(N,f2/fs);%使用fir1函数设计滤波器
%输入的参数分别是滤波器的阶数和截止频率
figure(1)
[h,f]=freqz(b,1,512);%滤波器的幅频特性图
%[H,W]=freqz(B,A,N)当N是一个整数时函数返回N点的频率向量和幅频响应向量
plot(f*fs/(2*pi),20*log10(abs(h)))%参数分别是频率与幅值
xlabel('频率/赫兹');ylabel('增益/分贝');title('滤波器的增益响应');
figure(2)
subplot(211)
t=0:1/fs:0.5;%定义时间范围和步长
s=sin(2*pi*f1*t)+sin(2*pi*f2*t);%滤波前信号
plot(t,s);%滤波前的信号图像
xlabel('时间/秒');ylabel('幅度');title('信号滤波前时域图');
subplot(212)
Fs=fft(s,512);%将信号变换到频域
AFs=abs(Fs);%信号频域图的幅值
f=(0:255)*fs/512;%频率采样
plot(f,AFs(1:256));%滤波前的信号频域图
xlabel('频率/赫兹');ylabel('幅度');title('信号滤波前频域图');
figure(3)
sf=filter(b,1,s);%使用filter函数对信号进行滤波
%参数分别为滤波器系统函数的分子和分母多项式系数向量和待滤波信号输入
subplot(211)
plot(t,sf)%滤波后的信号图像
xlabel('时间/秒');ylabel('幅度');title('信号滤波后时域图');
axis([0.2 0.5 -2 2]);%限定图像坐标范围
subplot(212)
Fsf=fft(sf,512);%滤波后的信号频域图
AFsf=abs(Fsf);%信号频域图的幅值
f=(0:255)*fs/512;%频率采样
plot(f,AFsf(1:256))%滤波后的信号频域图
xlabel('频率/赫兹');ylabel('幅度');title('信号滤波后频域图');
6. C语言怎么编写:请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。
结果出来了,你看看吧,满意请采纳
#include<stdio.h>
#include<string.h>
voidfinddd(charx[]);
intmain()
{
chara[150];
char*aa;
inta1;
inti;
printf("请输入任意的字符串:");
gets(a);
finddd(a);
return0;
}
voidfinddd(charx[])//不带数据返回
{
inti,shu=0;
charaa[100];
intaaa[200]={0};
for(i=0;i<strlen(x);i++)
{
if(aaa[x[i]]==0)
{
aaa[x[i]]=1;
aa[shu++]=x[i];
}
}
aa[shu++]='