Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. %% 基础参数输入
  2. sampleLen = 1000; % 波形时间长度(采样点数)
  3. fs = 1000; % 波形的采样频率,Hz
  4. fm = 75; % 信号的主频(中心频率),Hz
  5. fig = 0; % 是否画图,0为否,1为是
  6. ap = 0.7; % 设定子波峰值位置
  7. no = -25; % 加入白噪,单位db,wgn函数的参数
  8. timeDic = 1000*(0:1/fs:1/fs*(sampleLen-1)); % 转化到ms
  9. %% 生成雷克子波
  10. [OriData, noisedData, noise] = RickerWavelet(sampleLen, fs, fm, ap, no, fig);
  11. waveData = OriData;
  12. %% 计算功率谱
  13. N = length(waveData);%数据长度
  14. %i = 0:N-1;
  15. %t = i/fs;
  16. f = (0:N-1)*fs/N;%横坐标频率的表达式为f=(0:M-1)*Fs/M;??
  17. % 1、原始数据计算
  18. %f=100;%设定正弦信号频率?%生成正弦信号?
  19. waveData2 = fft(waveData,N);%进行fft变换?
  20. mag = abs(waveData2);%求幅值?
  21. %f = (0:N-1)*fs/N;%横坐标频率的表达式为f=(0:M-1)*Fs/M;??
  22. Opower = mag.^2;
  23. % 2、含噪声数据计算
  24. %f=100;%设定正弦信号频率?%生成正弦信号?
  25. noisedData2 = fft(noisedData,N);%进行fft变换?
  26. mag = abs(noisedData2);%求幅值?
  27. %f = (0:N-1)*fs/N;%横坐标频率的表达式为f=(0:M-1)*Fs/M;??
  28. NDpower = mag.^2;
  29. % 3、仅噪声数据计算
  30. %f=100;%设定正弦信号频率?%生成正弦信号?
  31. noise2 = fft(noise,N);%进行fft变换?
  32. mag = abs(noise2);%求幅值?
  33. %f = (0:N-1)*fs/N;%横坐标频率的表达式为f=(0:M-1)*Fs/M;??
  34. Npower = mag.^2;
  35.  
  36. %% 绘图
  37. h = figure;
  38. titleStr = ['fs = ' num2str(fs) ',' 'fm=' num2str(fm) ',' 'no=' num2str(no), 'sampleLen = ' num2str(sampleLen) ];
  39. suptitle(titleStr);
  40. %set(h,'name','Haar小波变换','Numbertitle','off')
  41. subplot(3,2,1);
  42. plot(timeDic,waveData);
  43. title('Ricker wavelet');xlabel('Time /ms');ylabel('Amplitude /mV');
  44. hold on;
  45. box on;
  46. set(gcf, 'color', 'w');
  47. set(gca, 'FontName', 'Times New Roman');
  48. xlim([1 N]);
  49. subplot(3,2,2);
  50. plot(f(1:length(f)/2), Opower(1:length(f)/2));
  51. title('Ricker wavelet spectrum');
  52. xlabel('Frequency /Hz');
  53. ylabel('Amplitude');
  54. hold on;
  55. box on;xlim([1 fs/2]);
  56. set(gcf, 'color', 'w');
  57. set(gca, 'FontName', 'Times New Roman');
  58.  
  59. % 含噪声信号
  60. subplot(3,2,3);
  61. plot(timeDic,noisedData);
  62. title('Noise Ricker wavelet');xlabel('Time /ms');ylabel('Amplitude /mV');
  63. hold on;
  64. box on;
  65. set(gcf, 'color', 'w');
  66. set(gca, 'FontName', 'Times New Roman');
  67. xlim([1 N]);
  68. subplot(3,2,4);
  69. plot(f(1:length(f)/2), NDpower(1:length(f)/2));
  70. title('Noise Ricker wavelet');
  71. xlabel('Frequency /Hz');
  72. ylabel('Amplitude');
  73. hold on;
  74. box on;xlim([1 fs/2]);
  75. set(gcf, 'color', 'w');
  76. set(gca, 'FontName', 'Times New Roman');
  77.  
  78. % 噪声
  79. subplot(3,2,5);
  80. plot(timeDic,noise);
  81. title('Noise');xlabel('Time /ms');ylabel('Amplitude /mV');
  82. hold on;
  83. %grid on;
  84. box on;
  85. set(gcf, 'color', 'w');
  86. set(gca, 'FontName', 'Times New Roman');
  87. xlim([1 N]);
  88. subplot(3,2,6);
  89. plot(f(1:length(f)/2), Npower(1:length(f)/2));
  90. title('Noise spectrum');
  91. xlabel('Frequency /Hz');
  92. ylabel('Amplitude');
  93. box on;
  94. xlim([1 fs/2]);
  95. set(gcf, 'color', 'w');
  96. set(gca, 'FontName', 'Times New Roman');
  97. saveas(gcf, [titleStr '.fig']);
  98. save([['Noised-Ricker-[' titleStr ']'] '.mat'], 'noisedData');
  99. save([['Orignal-Ricker-[' titleStr ']'] '.mat'], 'OriData');
  100.  
  101. %% 短时傅立叶变换
  102. %clear all %窗口函数%
  103. % n1=40; window=boxcar(n1); w1=window;
  104. % figure;
  105. % stem(w1); % 非平稳信号产生% fs=1000;
  106. % a=0:1/fs:1;
  107. % f0=0;
  108. % f1=150;
  109. % y1=chirp(a,f0,1,f1);
  110. % x=y1(1:510);
  111. % figure;
  112. % plot(x); % 短时傅里叶变换%
  113. % t=1:length(x);
  114. % n=length(x);
  115. % [tfr,t,f]=tfrstft(x,t,n,w1,0);
  116. % contour(t,f,abs(tfr))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement