Bio Assingnment 1 Codes
Bio Assingnment 1 Codes
Bio Assingnment 1 Codes
ASSIGNMENT – 1
- Thatukuru Lakshman
- CB.EN.U4AIE22067
clc;
clear all;
close all;
samplingFrequency = 50;
signalFrequency = 10;
frequencyShiftFactor = 100;
timeVector = 0:1/samplingFrequency:1;
figure;
subplot(2, 1, 1);
subplot(2, 1, 2);
clc;
clear all;
close all;
fs = 500;
N = 1000;
x = 0:N-1;
t = x * (1/fs);
y = 1 * sin(2 * pi * 100 * t) + 4 * sin(2 * pi * 110 * t);
Y = fft(y);
Power_spectrum = Power_spectrum(1:N/2+1);
f = f(1:N/2+1);
PSD = Power_spectrum / N;
figure;
subplot(3,1,1);
plot(t, y);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3,1,2);
plot(f, 10*log10(Power_spectrum));
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
subplot(3,1,3);
plot(f, 10*log10(PSD));
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
OUTPUT
data = load("/Users/lakshmanthatukuru/Desktop/eeg_data.mat");
% Plotting
figure;
% Original signal
subplot(2,1,1);
xlabel('Time (s)');
ylabel('Amplitude');
% Interpolated signal
subplot(2,1,2);
xlabel('Time (s)');
ylabel('Amplitude (Interpolated)');
OUTPUT
10) The file heart_rate_sample contains 2 heart rates – hr_med and hr_pre
during two conditions with corresponding time vectors t_med and t_pre.
Both these signals are unevenly sampled. Convert the hr_pre to evenly
spaced data (resample) using interpolation. You can take the sampling
frequency as 100Hz
hr_pre = data.hr_pre;
t_pre = data.t_pre;
t = t_pre
figure;
subplot(2,1,1);
xlabel('Time (s)');
ylabel('Amplitude');
% Interpolated signal
subplot(2,1,2);
xlabel('Time (s)');
ylabel('Amplitude (Interpolated)');
OUTPUT
11) Create a noisy signal to generate a waveform of 200,400 Hz in
MATLAB with SNR -8 dB, sampling frequency=1000Hz, and N=512
samples. Plot magnitude spectrum.
Repeat with -4dB, -16dB, plot the magnitude spectrums – write your
observation in detecting the signal frequency.
Repeat with N =1000 and N=200 samples, plot the magnitude spectrums -
and write the inference when detecting the signal frequency.
% Time vector
t = (0:N-1) / fs;
figure;
for i = 1:length(snr_values)
snr = snr_values(i);
% Signal power
signal = y + noise;
fft_sign = fft_sign(1:N/2+1);
subplot(2, 1, i);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
end
for j = 1:length(N_values)
N = N_values(j);
t = (0:N-1) / fs;
figure;
for i = 1:length(snr_values)
snr = snr_values(i);
% Signal power
signal_power = mean(y .^ 2);
signal = y + noise;
fft_sign = fft_sign(1:N/2+1);
subplot(length(snr_values), 1, i);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
end
end
OUTPUT
Figure 1:
Figure 2:
Figure 3:
1. SNR Variation:
- Lower SNR values: When the SNR is low, the noise level is high relative to
the signal. This increased noise makes it more challenging to discern the true
signal components, resulting in less clear or visible peaks at specific frequencies
like 200 Hz and 400 Hz. The signal is overwhelmed by noise, which obscures
the important features of the signal.
- Higher SNR values: With a higher SNR, the signal stands out more clearly
above the noise. This makes the signal peaks at 200 Hz and 400 Hz more
distinguishable and easier to detect. The reduced noise interference allows for a
clearer representation of the signal in the frequency domain.
This interpretation highlights the importance of both SNR and sample size in
accurately analyzing signals, particularly in applications like signal processing
and spectral analysis..