function classifysignal() % Parameters fs = 1000; % Sampling frequency fc = 100; %…
- User
function classify_signal() % Parameters fs = 1000; % Sampling frequency fc = 100; % Carrier frequency dataLength = fs; % Length of data (1 second of data) numTests = 1000; % Number of signals to test per modulation type
modTypes = {'ASK', 'FSK', 'PSK'}; correctCount = 0; totalCount = 0; % Loop over each modulation type for i = 1:length(modTypes) modType = modTypes{i}; for j = 1:numTests data = randi([0 1], 1, dataLength); signal = generateModulatedSignal(data, fs, fc, modType); [sigma_ap, sigma_af, sigma_dp] = extract_features(signal, fs); detectedModType = classify_based_on_features(sigma_ap, sigma_af, sigma_dp); isCorrect = strcmp(detectedModType, modType); if isCorrect correctCount = correctCount + 1; end totalCount = totalCount + 1; fprintf('Test %d - True: %s, Detected: %s, Correct: %d\n', ... j, modType, detectedModType, isCorrect); end end accuracy = (correctCount / totalCount) * 100; fprintf('Total Accuracy: %.2f%%\n', accuracy);end
function modType = classify_based_on_features(sigma_ap, sigma_af, sigma_dp)
ampThreshASK_PSK = 0.35; freqThreshASK_FSK = 0.45; phaseThreshPSK_FSK = 280; if sigma_af < freqThreshASK_FSK && sigma_dp < phaseThreshPSK_FSK modType = 'ASK'; elseif sigma_af > freqThreshASK_FSK && sigma_dp < phaseThreshPSK_FSK modType = 'FSK'; elseif sigma_dp > phaseThreshPSK_FSK modType = 'PSK'; else modType = 'Unknown'; endend
function signal = generateModulatedSignal(data, fs, fc, modType) dataLength = length(data); t = (0:dataLength-1) / fs;
switch modType case 'ASK' signal = (1 + data) .* cos(2 * pi * fc * t); case 'FSK' f1 = fc; % Frequency for ‘0’ f2 = fc + 50; % Frequency for ‘1’ signal = cos(2 * pi * (f1 + (f2-f1) * data) .* t); case 'PSK' signal = cos(2 * pi * fc * t + pi * data); otherwise error('Unknown modulation type'); endend
% Function to extract statistical features (amplitude, frequency, phase) function [sigma_ap, sigma_af, sigma_dp] = extract_features(x, fs) % Amplitude statistics x_envelope = abs(hilbert(x)); % Get the amplitude envelope sigma_ap = std(x_envelope); % Standard deviation of amplitude
% Phase statistics phase = unwrap(angle(hilbert(x))); % Unwrapped phase sigma_dp = std(phase); % Standard deviation of phase % Frequency statistics freqDiff = diff(unwrap(phase)); % Frequency deviation based on phase difference sigma_af = std(freqDiff); % Standard deviation of frequency deviationend
Give me code that shows me 3d graphs of accuracy vs various values of thresholds so that i can show that why it works for these values
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.