Question

In: Electrical Engineering

Write Matlab code (with detailed comments) to perform spectral analysis of 1KHz sine wave, noise and...

  1. Write Matlab code (with detailed comments) to perform spectral analysis of 1KHz sine wave, noise and noise corrupted sine wave. Consider the sampling frequency Fs=10KHz.                                                                                                                                                  
  2. What should be the ideal frequency response of filter required to remove noise? Justify your answer                                                                                                                           

Solutions

Expert Solution

(a) MATLAB code is given below:

fsin = 1000;%% sine wave frequency
fs = 10000;%% sampling frequency
fbin = fsin/100;%% bin frequency of FFT
npoints = fs/fbin*15;% Total length of sequence
nfft = fs/fbin;% No of points of FFT
A = 1;% amplitude of sinewave
vsin = A*sin(2*pi*fsin/fs*(0:1:npoints-1));% sine wave defined
noise = wgn(1,length(vsin),-40);% noise witj -40dB power defined
nfft_total = 10*nfft;% total length of sequence used for calculating PSD
vsin_final = vsin(end-nfft_total+1:end);
noise_final = noise(end-nfft_total+1:end);
noise_plus_sine = noise+vsin;% noise + signal
noise_plus_sine_final = noise_plus_sine(end-nfft_total+1:end);

%%% Generating 10 different FFT's by dividing sequence into ten segments
%%% and then taking FFT of each segment
fft_vsin(nfft_total/nfft,nfft) = 0;
fft_noise(nfft_total/nfft,nfft) = 0;
fft_noise_plus_sine(nfft_total/nfft,nfft) = 0;
for i = 1:nfft_total/nfft
fft_vsin(i,:) = fft(vsin_final((i-1)*nfft+1:i*nfft));
fft_noise(i,:) = fft(noise_final((i-1)*nfft+1:i*nfft));
fft_noise_plus_sine(i,:) = fft(noise_plus_sine_final((i-1)*nfft+1:i*nfft));
end
freq = fs/nfft*(0:1:nfft-1);

%%%%
psd_vsin_avg(1,nfft) = 0;
psd_noise_avg(1,nfft) = 0;
psd_noise_plus_sine_avg(1,nfft) = 0;
for i = 1:nfft_total/nfft
psd_vsin_avg = psd_vsin_avg + abs(fft_vsin(i,:)).^(2);
psd_noise_avg = psd_noise_avg + abs(fft_noise(i,:)).^(2);
psd_noise_plus_sine_avg = psd_noise_plus_sine_avg + abs(fft_noise_plus_sine(i,:)).^(2);
end
psd_vsin_avg = psd_vsin_avg(1:nfft/2)/(2000*2000);% scaling factor to normalize PSD
psd_noise_avg = psd_noise_avg(1:nfft/2)/(2000*2000);% scaling factor to normalize PSD
psd_noise_plus_sine_avg = psd_noise_plus_sine_avg(1:nfft/2)/(2000*2000);% scaling factor to normalize PSD
frequency = freq(1:nfft/2);

PSD of signal, PSD of noise and PSD of signal + noise is plotted below:

(b) From plot, we can see that signal is single sinusoid but noise spread over whole frequency range. So ideal filter to filter out noise will be a bandpass filter centered at 1kHz and infinite Q such that its bandwidth = 0.


Related Solutions

write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio...
show the MATLAB Code with comments and Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds), takes Fourier transform of the signal (probably FFT).
Use the sine wave and scope in the Simulink library (MATLAB) to generate and observe the...
Use the sine wave and scope in the Simulink library (MATLAB) to generate and observe the following waves: a. ?1 (?) = sin ?? b. ?2 (?) = cos ?? c. ?2 (?) = 0.5 cos ?? d. ?3 (?) = cos (?? − ?) ? = 1 ???/s
The function Sine is defined as: where x is an angle in radians Write a Matlab...
The function Sine is defined as: where x is an angle in radians Write a Matlab script program to compute the sinus value of any angle as the following: - The program should run always until the user enters - 1 to exit from the program. - A sk user to enter: Number of elements (N) that should be included in the sum - C heck that N is a positive integer . [ Hint: use ( round (N) -...
Design a matlab code that: 1-play sound 2- add noise to the sound 3- filter the...
Design a matlab code that: 1-play sound 2- add noise to the sound 3- filter the noised signal using fir or iir filter Note: FIR: Finite impulse response filter IIR: Infinite impulse response filter
write code with proper comments for ever step the code should be in form of pseudocode                            &
write code with proper comments for ever step the code should be in form of pseudocode                                    To Print Triangle of any size, by taking size as input. To Print Triangle of any size, by taking size as input. If size is 4 then triangle is: To calculate Factorial of any number. To calculate the power of any given number. To Print Table of Any Number up till 10: as shown in this figure. for a program which reads 10 integers...
write a matlab code to simulate fiber optics communication system on matlab simulink
write a matlab code to simulate fiber optics communication system on matlab simulink
I'm new in MATLAB and I have to write a code in MATLAB which converts a...
I'm new in MATLAB and I have to write a code in MATLAB which converts a number from one base to another without using base2base, etc
1. Write code in mips that will play battleships. Include comments in code on what each...
1. Write code in mips that will play battleships. Include comments in code on what each part is doing.
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an ARM assembly program to calculate the value of the following function: f(y) = 3y^2 – 2y + 10 when y = 3. My Code below, that needs comments added: FunSolve.s LDR R6,=y LDR R1,[R6] MOV R2,#5 MOV R3,#6 MUL R4,R1,R1 MUL R4,R4,R2 MUL R5,R1,R3 SUB R4,R4,R5 ADD R4,R4,#8 st B st y DCD 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT