Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- echo off
- clc
- clear all
- close all
- %generate sin_ with Gaussian noise
- SNRdb = 3;
- SNR = 0;
- FS = 8000;
- F = 1;
- To = 0.25;
- t = 0:1/FS:To-1/FS;
- meanHelp = [];
- powerHelp = [];
- figure();
- %----
- sin_ = sin(2*pi*F*t); %clear sinus
- gauss_ = randn(size(sin_));
- Psin = mean(sin_.^2, 2);
- Pnoise = mean(gauss_.^2, 2);
- %normalization
- SNR = 10^(-SNRdb/10);
- gauss_ = gauss_ * sqrt(Psin) / sqrt(Pnoise)/SNR;
- sin_gaus = sin_ + gauss_; %mixed sin with noise
- countBlocks = 10;
- lengthBlock = floor(length(sin_gaus)/countBlocks);
- for i = 1:countBlocks
- j = (i-1)*lengthBlock + 1;
- k = j + lengthBlock - 1;
- vectHelp = sin_gaus(j:k);
- mean_ = mean(vectHelp);
- power = mean(vectHelp.^2);
- meanHelp = [meanHelp, mean_];
- powerHelp = [powerHelp, power];
- end
- meanHelp = ones(lengthBlock,1) * meanHelp;
- meanHelp = meanHelp(:)';
- powerHelp = ones(lengthBlock,1) * powerHelp;
- powerHelp = powerHelp(:)';
- %plot
- subplot(2,1,1);
- plot(t, sin_gaus, t, meanHelp, t, powerHelp);
- xlabel('t[s]');
- ylabel('|A|');
- legend('sinus with noise', 'mean', 'power')
- title('sinus 1Hz with Gaussian noise, SNR 3dB');
- %generate oscillation sinus
- Flow = 10;
- FS = 8000;
- Fhigh = 400;
- To = 0.02;
- t = 0:1/FS:To-1/FS;
- %--------
- k = (Fhigh-Flow)/To;
- F = k*t+Flow; %vector of frequencies
- sin_ = sin(2*pi*F.*t);
- %plot
- subplot(2,1,2);
- plot(t,sin_);
- xlabel('t[s]');
- ylabel('|A|');
- title('oscillation sinus');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement