Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: SNR script to run using Matlab
Replies: 2   Last Post: Jan 4, 2013 4:27 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 2
Registered: 1/1/13
Re: SNR script to run using Matlab
Posted: Jan 4, 2013 4:27 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


below is my coding:

%<--- LOAD SIGNAL (FILENAME:mydata.mat)
%data = ('mydata.mat')
t= 0: 1/Fs: 20;
S = load('mydata.mat');
signal = S.td;
x= signal
SNR = 0;
% Generate Gaussian Noise with zero mean and unit variance
%function [y] = add_noise (signal, SNR)
x_var=var (x);


%mix signal with noise
mix = x+ noise;

%SNR equation
%SNR dB= 20 log10 (STDsignal/STDnoise)
%STDs = std(signal)
%STDn = std(noise)
%SNR_measured_dB = 20* log(STDs/STDn)

Fc = 100 ; %cut off frequency

w = Fc/(2*Fs); % Normalized frequency
%design a low pass fitler with above mentioned specifications
[b,a]=butter(2,w,'low'); %5th order butterworth LPF
[h,w]=freqz(b,a,1024); %Frequency response of the filter

y=filter(b,a,mix); % pass the input signal through the filter
% y is your output.

%subplot figure (1)
plot(t, signal);
title('Input Signal');

%plot(t, noise);
%title('Generated Noise');

plot(t, mix);
title(['Signal + Noise for SNR = 30 dB']);

plot(t, y);
title('Filtered Signal');

%Plot the Frequency response of the filter (Optional)
g = length(w/pi*2*Fs)
i = length(abs(h))
title('Frequency Response of a 5th Order Butterworth LPF');
xlabel('Frequency (Hz)')

%plotting psd
figure (5)
x = signal;
NFFT = 100;
X = fft(x, NFFT);
plot(-NFFT/2:NFFT/2 - 1, fftshift(abs(X)))
title('PSD Input Signal');

v = noise;
NFFT = 100;
V = fft(v, NFFT);
plot(-NFFT/2:NFFT/2 - 1, fftshift(abs(V)))
title('PSD Generated Noise');

w = mix;
NFFT = 100;
W = fft(w, NFFT);
plot(-NFFT/2:NFFT/2 - 1, fftshift(abs(W)))
title(['PSD Signal + Noise for SNR= 30 dB']);

m = y;
NFFT = 100;
M = fft(m, NFFT);
plot(-NFFT/2:NFFT/2 - 1, fftshift(abs(M)))
title('PSD Filtered Signal');

anyone <ieGJnr4aQXRb!uzEL@z³> wrote in message <50e37605$0$46968$c3e8da3$38634283@news.astraweb.com>...
> On Tue, 01 Jan 2013 20:41:08 +0000, Wan wrote:

> > Hi,
> >
> > I have a problem to run a script for SNR. Here the details.
> >
> > By using the given signal, the signal should be embended with noise with
> > with different Signal-to-noise ration (SNR) of 0dB, 5dB, 10dB, 15dB,
> > 20dB, 25 dB and 30 dB. Details of the programming should include:
> > 1. How SNR of the noisy signal is calculated 2. Comparison of time
> > domain and Power Spectrum Density (PSD) of original signal, noisy signal
> > and filtered signal for each SNR.
> >
> > Anyone know how to write script for this SNR using given signal?

> Yes, I can think of a few ways one could do that. First, you should get
> started on your homework, then come back with an update on what you tried
> to do and what actually happened.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.