Question
clear all; clc; global arraySize arrayWithLatestValues samplingRate; arraySize = 500; arrayWithLatestValues = zeros(1,arraySize); samplingRate = 50; % in sps (sampling rate of the ADC) f
clear all; clc; global arraySize arrayWithLatestValues samplingRate;
arraySize = 500; arrayWithLatestValues = zeros(1,arraySize); samplingRate = 50; % in sps (sampling rate of the ADC) f = 2.8; rateOfDetectingFrequency = 1; % Number of times/sec you'll run "fn_detectFrequency" to compute the frequency
threshold = 2.6; hysteresisWindowLength = 1; numberOfCyclesToAverage = 1;
%%% Create source signal: maxTime = 10; % in seconds numberOfSamples = round( maxTime * samplingRate );
simulated_raw_ADC_outputs = 2048 + 1500 * cos(2*pi*f*[0:numberOfSamples-1]*(1/samplingRate)) + 1000*rand(1,numberOfSamples);
index2 = 1; for index1 = 1:numberOfSamples
newValue = (3.3/4095) * simulated_raw_ADC_outputs(index1);
fn_updateArray(newValue); %% WRITE THIS FUNCTION IN A SEPARATE .m FILE
if mod( index1 , round(samplingRate/rateOfDetectingFrequency) ) == 0 currentFrequency = fn_detectFrequency(threshold,hysteresisWindowLength,numberOfCyclesToAverage ); %% WRITE THIS FUNCTION IN A SEPARATE .m FILE detectedFreqArray(:,index2) = [currentFrequency;index1]; index2 = index2 + 1; end end
figure; subplot(2,1,1); plot((3.3/4095) * simulated_raw_ADC_outputs); xlabel('Sample Index'); ylabel('Input Voltage'); axis([1 numberOfSamples 0 3.3]); grid on; title(['Frequency = ' num2str(f) ' , F_s = ' num2str(samplingRate)]);
subplot(2,1,2); plot(detectedFreqArray(2,:),detectedFreqArray(1,:),'ro'); xlabel('Sample Index'); ylabel('Detected Frequency'); axis([1 numberOfSamples 0 ceil(max( detectedFreqArray(1,:) )+1)]); grid on;
In this problem, you will simulate an analog noisy periodic signal, sample the signal and convert it to a digital signal, and write a function to detect the frequency of the original signal You MUST attach all your codes with your report In this problem, you will simulate an analog noisy periodic signal, sample the signal and convert it to a digital signal, and write a function to detect the frequency of the original signal You MUST attach all your codes with your reportStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started