当前位置:首页 » 编程语言 » kaiser窗函数c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

kaiser窗函数c语言

发布时间: 2022-08-06 04:21:05

1. 将凯撒密码X的加密、解密过程用c语言编程实现

1、在密码学中,恺撒密码(或称恺撒加密、恺撒变换、变换加密)是一种最简单且最广为人知的加密技术。它是一种替换加密的技术,明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。例如,当偏移量是3的时候,所有的字母A将被替换成D,B变成E,以此类推。这个加密方法是以恺撒的名字命名的,当年恺撒曾用此方法与其将军们进行联系。恺撒密码通常被作为其他更复杂的加密方法中的一个步骤,例如维吉尼尔密码。恺撒密码还在现代的ROT13系统中被应用。但是和所有的利用字母表进行替换的加密技术一样,恺撒密码非常容易被破解,而且在实际应用中也无法保证通信安全。例子恺撒密码的替换方法是通过排列明文和密文字母表,密文字母表示通过将明文字母表向左或向右移动一个固定数目的位置。

2、kaiser加密算法具体程序:

#include<stdio.h>
#include<conio.h>
charencrypt(charch,intn)/*加密函数,把字符向右循环移位n*/
{
while(ch>='A'&&ch<='Z')
{
return('A'+(ch-'A'+n)%26);
}
while(ch>='a'&&ch<='z')
{
return('a'+(ch-'a'+n)%26);
}
returnch;
}
voidmenu()/*菜单,1.加密,2.解密,3.暴力破解,密码只能是数字*/
{
clrscr();
printf(" =========================================================");
printf(" 1.Encryptthefile");
printf(" 2.Decryptthefile");
printf(" 3.Forcedecryptfile");
printf(" 4.Quit ");
printf("========================================================= ");
printf("Pleaseselectaitem:");
return;
}
main()
{
inti,n;
charch0,ch1;
FILE*in,*out;
charinfile[20],outfile[20];
textbackground(BLACK);
textcolor(LIGHTGREEN);
clrscr();
sleep(3);/*等待3秒*/
menu();
ch0=getch();
while(ch0!='4')
{
if(ch0=='1')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要加密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputthekey:");
scanf("%d",&n);/*输入加密密码*/
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入加密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
while(!feof(in))/*加密*/
{
fputc(encrypt(fgetc(in),n),out);
}
printf(" Encryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='2')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要解密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputthekey:");
scanf("%d",&n);/*输入解密密码(可以为加密时候的密码)*/
n=26-n;
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
while(!feof(in))
{
fputc(encrypt(fgetc(in),n),out);
}
printf(" Decryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='3')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要解密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
for(i=1;i<=25;i++)/*暴力破解过程,在察看信息正确后,可以按'Q'或者'q'退出*/
{
rewind(in);
rewind(out);
clrscr();
printf("========================================================== ");
printf("Theoutfileis: ");
printf("========================================================== ");
while(!feof(in))
{
ch1=encrypt(fgetc(in),26-i);
putch(ch1);
fputc(ch1,out);
}
printf(" ======================================================== ");
printf("Thecurrentkeyis:%d ",i);/*显示当前破解所用密码*/
printf("Press'Q'toquitandotherkeytocontinue...... ");
printf("========================================================== ");
ch1=getch();
if(ch1=='q'||ch1=='Q')/*按'Q'或者'q'时退出*/
{
clrscr();
printf(" GoodBye! ");
fclose(in);
fclose(out);
sleep(3);
exit(0);
}
}
printf(" Forcedecryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
menu();
ch0=getch();
}
clrscr();
printf(" GoodBye! ");
sleep(3);
}

2. 请简述窗函数法设计FIR数字滤波器的方法与步骤。

滤波器的理想频率响应函数为Hd(ejω),则其对应的单位脉冲响应为hd(n)=窗函数设计法的基本原理是用有限长单位脉冲响应序列h(n)逼hd(n)。由于hd(n)往往是无限长序列,且是非因果的,所以用窗函数。w(n)将hd(n)截断,并进行加权处理:

h(n)=hd(n)w(n)h(n)就作为实际设计的FIR数字滤波器的单位脉冲响应序列,其频率响应函数H(ejω)为H(ejω)=用窗函数法设计的滤波器性能取决于窗函数w(n)的类型及窗口长度N的取值。设计过程中,要根据对阻带最小衰减和过渡带宽度的要求选择合适的窗函数类型和窗口长度N。

一般都选用Ⅰ型线性相位滤波器即滤波器阶数M为偶数,程序如下:

wp=;ws=;Ap=1;As=100;

dev=[Rp Rs];

[M,wc,beta,ftype]=kaiserord(f,a,dev);

M=mod(M,2)+M;

plot(omega/pi,20*log10(abs(mag)));

运行程序可以得到滤波器的通阻带衰减,画出频率响应,若同阻带衰减不满足要求还可以使用滤波器的优化,一般使用的等波纹FIR进行优化。

(2)kaiser窗函数c语言扩展阅读:

滤波器与机箱之间的一段连线会产生两种不良作用: 一个是机箱内部空间的电磁干扰会直接感应到这段线上,沿着电缆传出机箱,借助电缆辐射,使滤波器失效;另一个是外界干扰在被板上滤波器滤波之前,借助这段线产生辐射,或直接与线路板上的电路发生耦合,造成敏感度问题;

滤波阵列板、滤波连接器等面板滤波器一般都直接安装在屏蔽机箱的金属面板上。由于直接安装在金属面板上,滤波器的输入与输出之间完全隔离,接地良好,电缆上的干扰在机箱端口上被滤除,因此滤波效果相当理想。

3. 用C语言实现任意字符串的加密,其中,字母用凯撒加密方法加密,非字母不变

我尽量用注释阐述了思路,希望可以帮到你!!

#include<stdio.h>
#include<string.h>
#define N 80 //可加密字符串最大长度

char plaintext[N]={0}; //明文,输入时输入字符,参与运算时强制转换成整数
int ciphertext[N]={0}; //密文,保存成整数,输出时强制转换成字符
int k; //后(右)移位数,相当于密钥

void getPlainText() //获得明文字符串
{
printf("请输入明文:");
scanf("%s",plaintext);
printf("\n");
}

void getLength() //获取后(右)移位数(密钥)
{
printf("请输入后移的位数:");
scanf("%d",&k);
k%=26; //因为字母只有26个,所以超过26相当于重复
}

void Caesar_cipher() //凯撒加密,本程序采用的是字母循环后(右)移
{
unsigned int i;

for(i=0;i<strlen(plaintext);i++)
{
//两个bool类型的变量是为了判断字符是否是字母(包括大写和小写)
bool flag1=plaintext[i]>='a'&&plaintext[i]<='z';
bool flag2=plaintext[i]>='A'&&plaintext[i]<='Z';

if(flag1||flag2){ //如果是字母,加密
ciphertext[i]=(int)plaintext[i]+k; //字母在字母表中后(右)移K位
if(ciphertext[i]>(int)'z'){ //保证是循环后(右)移
ciphertext[i]-=26;
}
}
else //非字母字符,不做处理,原样保存
ciphertext[i]=(int)plaintext[i];

}

}

void printCipherText() //输出加密后的密文
{
unsigned int i;
printf("\n加密后的密文是:");
for(i=0;i<strlen(plaintext);i++) //把参与计算后是整数强制转换成对应的字符
printf("%c",(char)ciphertext[i]);
printf("\n");

}

void main()
{
getPlainText(); //明文
getLength(); //后(右)移位数
Caesar_cipher(); //凯撒加密
printCipherText(); //密文

}

4. 用窗函数设计低通滤波器时,出现Cannot find an exact (case-sensitive) match for 'Kaiser'.求解

b = fir1(34,0.48,'high', kaiser(35,.5));
值得注意的是,fir1第一个参数为长度,这里为34,所以kaiser用35

5. 简述采用窗函数法设计FIR数字滤波器的设计步骤及主要公式。

将模拟频率转化为数字频率,设取样时间为T(要满足抽样定理)
Ωp=2π*fp*T Ωs=2π*fs*T
过渡带宽度△Ω=Ωp-Ωs
阻带衰减已经超过74db,要选用Kaiser窗了,Kaiser的参数可变,要根据公式确定滤波器的参数
一般都选用Ⅰ型线性相位滤波器即滤波器阶数M为偶数,程序如下:
wp=;ws=;Ap=1;As=100;
Rp=1-10.^(-0.05*Ap);Rs=10.^(-0.05*As);
f=[fp fs];
a=[0 1];
dev=[Rp Rs];
[M,wc,beta,ftype]=kaiserord(f,a,dev);
M=mod(M,2)+M;
h=fir1(M,wc,ftype,kaiser(M+1,beta));
omega=linspace(0,pi,512);
mag=freqz(h,[1],omega);
plot(omega/pi,20*log10(abs(mag)));
grid;
omega1=linspace(0,wp,512);
h1=freqz(h,[1],omega1);
omega2=linspace(ws,pi,512);
h2=freqz(h,[1],omega2);
fprintf('Ap=%.4f\n',-20*log10(min(abs(h1))));
fprintf('As=%.4f\n',-20*log10(max(abs(h2))));

运行程序可以得到滤波器的通阻带衰减,画出频率响应,若同阻带衰减不满足要求还可以使用滤波器的优化,一般使用的等波纹FIR进行优化

6. 凯撒密码的问题C语言

(2)kaiser加密算法
具体程序:
#include<stdio.h>
#include<conio.h>
char encrypt(char ch,int n)/*加密函数,把字符向右循环移位n*/
{
while(ch>='A'&&ch<='Z')
{
return ('A'+(ch-'A'+n)%26);
}
while(ch>='a'&&ch<='z')
{
return ('a'+(ch-'a'+n)%26);
}
return ch;
}
void menu()/*菜单,1.加密,2.解密,3.暴力破解,密码只能是数字*/
{
clrscr();
printf("\n=========================================================");
printf("\n1.Encrypt the file");
printf("\n2.Decrypt the file");
printf("\n3.Force decrypt file");
printf("\n4.Quit\n");
printf("=========================================================\n");
printf("Please select a item:");
return;
}

main()
{
int i,n;
char ch0,ch1;
FILE *in,*out;
char infile[20],outfile[20];
textbackground(BLACK);
textcolor(LIGHTGREEN);
clrscr();

sleep(3);/*等待3秒*/
menu();
ch0=getch();
while(ch0!='4')
{
if(ch0=='1')
{
clrscr();
printf("\nPlease input the infile:");
scanf("%s",infile);/*输入需要加密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Can not open the infile!\n");
printf("Press any key to exit!\n");
getch();
exit(0);
}
printf("Please input the key:");
scanf("%d",&n);/*输入加密密码*/
printf("Please input the outfile:");
scanf("%s",outfile);/*输入加密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Can not open the outfile!\n");
printf("Press any key to exit!\n");
fclose(in);
getch();
exit(0);
}
while(!feof(in))/*加密*/
{
fputc(encrypt(fgetc(in),n),out);
}
printf("\nEncrypt is over!\n");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='2')
{
clrscr();
printf("\nPlease input the infile:");
scanf("%s",infile);/*输入需要解密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Can not open the infile!\n");
printf("Press any key to exit!\n");
getch();
exit(0);
}
printf("Please input the key:");
scanf("%d",&n);/*输入解密密码(可以为加密时候的密码)*/
n=26-n;
printf("Please input the outfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Can not open the outfile!\n");
printf("Press any key to exit!\n");
fclose(in);
getch();
exit(0);
}
while(!feof(in))
{
fputc(encrypt(fgetc(in),n),out);
}
printf("\nDecrypt is over!\n");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='3')
{
clrscr();
printf("\nPlease input the infile:");
scanf("%s",infile);/*输入需要解密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Can not open the infile!\n");
printf("Press any key to exit!\n");
getch();
exit(0);
}
printf("Please input the outfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Can not open the outfile!\n");
printf("Press any key to exit!\n");
fclose(in);
getch();
exit(0);
}
for(i=1;i<=25;i++)/*暴力破解过程,在察看信息正确后,可以按'Q'或者'q'退出*/
{
rewind(in);
rewind(out);
clrscr();
printf("==========================================================\n");
printf("The outfile is:\n");
printf("==========================================================\n");
while(!feof(in))
{
ch1=encrypt(fgetc(in),26-i);
putch(ch1);
fputc(ch1,out);
}
printf("\n========================================================\n");
printf("The current key is: %d \n",i);/*显示当前破解所用密码*/
printf("Press 'Q' to quit and other key to continue......\n");
printf("==========================================================\n");
ch1=getch();
if(ch1=='q'||ch1=='Q')/*按'Q'或者'q'时退出*/
{
clrscr();
printf("\nGood Bye!\n");
fclose(in);
fclose(out);
sleep(3);
exit(0);
}
}
printf("\nForce decrypt is over!\n");
fclose(in);
fclose(out);
sleep(1);
}
menu();
ch0=getch();
}
clrscr();

printf("\nGood Bye!\n");
sleep(3);
}
.
希望能够帮助你 ^_^ 也希望能够选为最佳答案!

7. 帮帮忙,能不能给我 基于C语言的FIR滤波器设计的程序代码(包括CMD,C,ASM),谢谢了 真的很急!!!

#include"math.h"
void firwin(n,band,fln,fhn,wn,h)
int n,band,wn;
double fln,fhn,h[];
{int i,n2,mid;
double s,pi,wc1,wc2,beta,delay;
double window();
beta=0.0;
if(wn==7)
{printf("input beta parameter of Kaiser window(2<beta<10)\n");
scanf("%1f",&beta);
}
pi=4.0*atan(1.0);
if((n%2)==0)/*如果n是偶数*/
{n2=n/2+1;/*这行什么意思*/
mid=1;
}
else
{n2=n/2;
mid=0;
}
delay=n/2.0;
wc1=2.0*pi*fln;
if(band>=3) wc2=2.0*pi*fhn;/*先判断用户输入的数据,如果band参数大于3*/
switch(band)
{case 1:
{for(i=0;i<=n2;i++)
{s=i-delay;
h[i]=(sin(wc1*s)/(pi*s))*window(wn,n+1,i,beta);
h[n-i]=h[i];
}
if(mid==1) h[n/2]=wc1/pi;
break;
}
case 2:
{for(i=0;i<=n2;i++)
{s=i-delay;
h[i]=(sin(pi*s)-sin(wc1*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];
}
if(mid==1) h[n/2]=1.0-wc1/pi;
break;
}
case 3:
{for(i=0;i<n2;i++)
{s=i-delay;
h[i]=(sin(wc2*s)-sin(wc1*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];
}
if(mid==1)h[n/2]=(wc2-wc1)/pi;
break;
}
case 4:
{for(i=0;i<=n2;i++)
{s=i-delay;
h[i]=(sin(wc1*s)+sin(pi*s)-sin(wc2*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];
}
if(mid==1)h[n/2]=(wc1+pi-wc2)/pi;
break;
}
}
}
static double window(type,n,i,beta)
int i,n,type;
double beta;
{int k;
double pi,w;
double kaiser();
pi=4.0*atan(1.0);
w=1.0;
switch(type)
{case 1:
{w=1.0;
break;
}
case 2:
{k=(n-2)/10;
if(i<=k)
w=0.5*(1.0-cos(i*pi/(k+1)));
break;
}
case 3:
{w=1.0-fabs(1.0-2*i/(n-1.0));
break;
}
case 4:
{w=0.5*(1.0-cos(2*i*pi/(n-1)));
break;
}
case 5:
{w=0.54-0.46*cos(2*i*pi/(n-1));
break;
}
case 6:
{w=0.42-0.5*cos(2*i*pi/(n-1))+0.08*cos(4*i*pi/(n-1));
break;
}
case 7:
{w=kaiser(i,n,beta);
break;
}
}
return(w);
}
static double kaiser(i,n,beta)
int i,n;
double beta;
{
double a,w,a2,b1,b2,beta1;
double bessel0();
b1=bessel0(beta);
a=2.0*i/(double)(n-1)-1.0;
a2=a*a;
beta1=beta*sqrt(1.0-a2);
b2=bessel0(beta1);
w=b2/b1;
return(w);
}
static double bessel0(x)
double x;
{int i;
double d,y,d2,sum;
y=x/2.0;
d=1.0;
sum=1.0;
for(i=1;i<=25;i++)
{d=d*y/i;
d2=d*d;
sum=sum+d2;
if(d2<sum*(1.0e-8)) break;
}
return(sum);
}
这是窗函数法的,当然还有其他的比如切比雪夫,零相位滤波什么的,我也在研究,不是很懂哈

8. 采用窗函数法(Kaiser窗)设计一个FIR数字低通滤波器,说我14行的 'ideal'没有定义。

function hd = ideal_lp(wc,M)
% Ideal LowPass filter computation
% --------------------------------
% [hd] = ideal_lp(wc,M)
%hd= ideal impulse response between 0 to M-1
%wc= cutoff frequency in radians
% M= length of the ideal filter
%
alpha = (M-1)/2; n = 0:1:(M-1);
m=n- alpha; fc = wc/pi; hd = fc*sinc(fc*m);
end

注:此处的wc=(Wst-Wp)/2

9. 用matlab处理语音信号,用到kaiser窗函数 kaiser(N,BTA),其中的N和BTA是什么意思

把datareport 的datasource设置成和datagrid一样的adodc就行 按钮命令 set datareport1.datasource=adodc1
是在工程下面,和部件一样是工程的子命令。\r\n而且datareport不一定非要data environment的可以脱离数据环境单独使用的\r\n具体方法是把一个recordset对象作为数据源 \r\n2新建工程\r\n\r\n选数据工程
1、Data Report使用数据库中的记录生成报表。要使用它:
2、配置一个数据源,例如Microsoft数据环境,以访问数据库。
3、设定DataReport对象的DataSource属性为数据源。
4、设定DataReport对象的DataMember属性为数据成员。
5、右键单击设计器,并单击“检索结构”。
6、向相应的节添加相应的控件。
7、为每一个控件设定DataMember和DataField属性。

10. 利用Kaiser窗函数设计的FIR低通滤波器进行数字滤波

Wp=2.5;Rp=0.25dB
Ws=3;As=50dB;
下面是程序,把t取1:1:499,
wp=2.5;ws=3;As=50;
tr_width=ws-wp;
M=ceil((As-7.95)/(14.36*tr_width/(2*pi))+1)+1;
n=[0:1:M-1];
beta=0.1102*(As-8.7);
wc=(ws+wp)/2;
hd=ideal_lp(wc,M);
w_kai=(kaiser(M,beta))';
h=hd.*w_kai;
t=0:1:499;
x=sin(2*t)+sin(5*t)+sin(20*t);
subplot(2,1,1);plot(t,x);
title('x=sin(2*n)+sin(5*n)+sin(20*n)');
xlabel('时间/s');ylabel('幅度');
y=filter(h,[1],x);
subplot(2,1,2);plot(t,y);
title('y=filter(h,[1],x)');
需要说明的是,你这个题给出的信号和所取的点数不太匹配,我做了频谱分析了,性能不算好,分析原因是因为正弦信号在抽取时,一定要做整数倍周期的抽取,你抽取了500点,而500点不是上述三个正弦信号的任意一个周期的整数倍,这样会产生频率泄露的问题。
为了给你一个直观的看法,我重新设计了你这个题目,你可以看一下效果。我选择了一个信号:
x=sin(0.1*pi*n)+sin(0.3*pi*n);
做了整数周期的抽取。
wp=0.2*pi;ws=0.3*pi;As=50;
tr_width=ws-wp;
M=ceil((As-7.95)/(14.36*tr_width/(2*pi))+1)+1
n=[0:1:M-1];;
beta=0.1102*(As-8.7)
wc=(ws+wp)/2;
hd=ideal_lp(wc,M);
w_kai=(kaiser(M,beta))';
h=hd.*w_kai;
n=0:199;
x=sin(0.1*pi*n)+sin(0.3*pi*n);
y=filter(h,[1],x);
subplot(2,2,1);stem(n,x);
title('x=sin(0.1*pi*n)+sin(0.3*pi*n)');
subplot(2,2,2);plot(n,y);
>>
title('y=filter(h,[1],x)');
x1=fft(x,200);
x11=abs(x1);
title('y=filter(h,[1],x)');
subplot(2,2,3);stem(n,x11);
title('the
frequency
of
x');
y1=fft(y,200);
y11=abs(y1);
subplot(2,2,4);stem(n,y11);
title('the
frequency
of
y');
你在MATLAB中运行可以清晰的看到0.3pi的信号被滤掉。