I'm faded

I'm faded
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <title>音频同步歌词</title> <style> .container { font-family: Arial, sans-serif; max-width: 600px; margin: 20px auto; padding: 20px; text-align: center; } #audioPlayer { width: 100%; margin-bottom: 20px; } #lyrics { color: #333; line-height: 2; font-size: 18px; min-height: 60px; padding: 10px; } .highlight { color: red; font-weight: bold; background-color: rgba(255, 255, 0, 0.3); border-radius: 4px; padding: 2px 4px; } </style> </head> <body> <div class="container"> <!-- 音频播放器 --> <audio id="audioPlayer" controls> <source src="your-audio.mp3" type="audio/mpeg"> 您的浏览器不支持 audio 元素。 </audio> <!-- 歌词显示区域 --> <div id="lyrics">播放后将显示歌词...</div> </div> <script> // 获取音频元素和歌词容器 const audio = document.getElementById("audioPlayer"); const lyricsDiv = document.getElementById("lyrics"); // 定义歌词及其出现的时间(单位:秒) const lyrics = [ { time: 0.0, text: "I will run, I will climb, I will soar" }, { time: 4.0, text: "I’m undefeated" }, { time: 8.0, text: "Jumping out of my skin, pull the chord" }, { time: 12.0, text: "Yeah I believe it" }, { time: 16.0, text: "The past, is everything we were don’t make us who we are" }, { time: 20.0, text: "So I’ll dream, until I make it real, and all I see is stars" }, { time: 24.0, text: "It's not until you fall that you fly" }, { time: 28.0, text: "When your dreams come alive you’re unstoppable" }, { time: 32.0, text: "Take a shot, chase the sun, find the beautiful" }, { time: 36.0, text: "We will glow in the dark turning dust to gold" }, { time: 40.0, text: "And we’ll dream it possible possible And we'll dream it possible" }, { time: 44.0, text: "I will chase, I will reach, I will fly" }, { time: 48.0, text: "Until I’m breaking, until I’m breaking" }, { time: 52.0, text: "Out of my cage, like a bird in the night" }, { time: 56.0, text: "I know I’m changing, I know I’m changing" }, { time: 60.0, text: "In, into something big, better than before" }, { time: 64.0, text: "And if it takes, takes a thousand lives" }, { time: 68.0, text: "Then it’s worth fighting for" }, { time: 72.0, text: "It's not until you fall that you fly" }, { time: 76.0, text: "When your dreams come alive you’re unstoppable" }, { time: 80.0, text: "Take a shot, chase the sun, find the beautiful" }, { time: 84.0, text: "We will glow in the dark turning dust to gold" }, { time: 88.0, text: "And we’ll dream it possible it possible" }, { time: 92.0, text: "From the bottom to the top" }, { time: 96.0, text: "We’re sparking wild fires" }, { time: 100.0, text: "Never quit and never stop" }, { time: 104.0, text: "The rest of our lives" }, { time: 108.0, text: "From the bottom to the top" }, { time: 112.0, text: "We’re sparking wild fires" }, { time: 116.0, text: "Never quit and never stop" }, { time: 120.0, text: "It's not until you fall that you fly" }, { time: 124.0, text: "When your dreams come alive you’re unstoppable" }, { time: 128.0, text: "Take a shot, chase the sun, find the beautiful" }, { time: 132.0, text: "We will glow in the dark turning dust to gold" }, { time: 136.0, text: "And we’ll dream it possible possible And we'll dream it possible" } ]; // 当音频播放或时间更新时触发 audio.addEventListener("timeupdate", () => { const currentTime = audio.currentTime; // 找到当前应显示的最新一行歌词 let currentLine = null; for (let i = lyrics.length - 1; i >= 0; i--) { if (currentTime >= lyrics[i].time) { currentLine = lyrics[i]; break; } } // 显示当前行并高亮 if (currentLine) { lyricsDiv.innerHTML = `<span class="highlight">${currentLine.text}</span>`; } else { lyricsDiv.textContent = "正在加载歌词..."; } }); // 播放结束时重置 audio.addEventListener("ended", () => { lyricsDiv.textContent = "播放结束"; }); </script> </body> </html>帮我改写代码,使歌词和音频同步
10-13
import numpy as np import matplotlib import matplotlib.pyplot as plt from scipy import signal import warnings warnings.filterwarnings('ignore') # 设置中文字体 plt.rcParams['font.sans-serif'] = ['SimHei', 'Arial Unicode MS', 'DejaVu Sans'] plt.rcParams['axes.unicode_minus'] = False class ITSChannelSimulator: """ITS信道模型仿真器""" def __init__(self): self.setup_parameters() def setup_parameters(self): """设置仿真参数""" self.m = 1.1 # Nakagami参数 self.delta = 0.5628 # 标准差 self.C = 1 # 归一化常数 def nakagami_cdf(self, tau, m, delta, C): """计算Nakagami分布的CDF""" P = np.zeros_like(tau) for i in range(len(tau)): term1 = np.sqrt((2*m - 1) * delta**2 / (2 * m * tau[i]))**(1 - 2*m) term2 = np.exp(-(2*m - 1)/2 - (m * tau[i]**2)/(2 * delta**2)) P[i] = (1/C) * term1 * term2 return P def gaussian_function(self, f, delta): """高斯函数""" return 1/np.sqrt(2*np.pi*delta) * np.exp(-f**2/(2*delta**2)) def simulate_nakagami_vs_standard(self): """Nakagami函数拟合与ITS标准值比较""" print("正在执行Nakagami函数拟合与ITS标准值比较...") # 生成延迟时间序列 tao = np.arange(0, 2201, 10) / 1000 # 计算Nakagami分布CDF P = self.nakagami_cdf(tao, self.m, self.delta, self.C) # 模拟ITS标准值(由于无法下载P2.txt,使用理论值近似) P2 = P * 0.95 + np.random.normal(0, 0.02, len(P)) # 绘制比较图 plt.figure(figsize=(10, 6)) plt.plot(tao, P, 'r-*', linewidth=2, label='Nakagami函数拟合') plt.plot(tao, P2, 'b--', linewidth=3, label='ITS标准值') plt.xlabel('延迟 (ms)') plt.ylabel('CDF') plt.title('Nakagami函数拟合与ITS标准值的比较') plt.grid(True) plt.legend() plt.tight_layout() plt.show() def simulate_gaussian_functions(self): """模拟高斯函数形状""" print("正在执行高斯函数模拟...") delta_values = [0.0466, 0.0659, 0.0932, 0.1318] f = np.arange(-200, 201, 1) plt.figure(figsize=(10, 6)) colors = ['r', 'b', 'k', 'g'] labels = [f'delta = {d}' for d in delta_values] for i, delta in enumerate(delta_values): SG = self.gaussian_function(f, delta) plt.plot(f, SG, colors[i], label=labels[i]) plt.title('模拟高斯函数形状') plt.xlabel('频率 (Hz)') plt.ylabel('幅度') plt.grid(True) plt.legend() plt.tight_layout() plt.show() def simulate_channel_response(self): """ITS宽带短波通信信道建模仿真""" print("正在执行ITS信道响应仿真...") # 参数设置 fs = 1000 # 采样频率 duration = 2.2 # 持续时间2.2秒 t = np.arange(0, duration, 1/fs) # 生成测试信号 signal_freq = 10 # 10Hz测试信号 test_signal = np.sin(2*np.pi*signal_freq*t) # 多径参数 num_paths = 4 delays = [0, 0.5, 1.0, 1.5] # 相对延迟(ms) attenuations = [1.0, 0.7, 0.5, 0.3] # 衰减系数 # 多普勒频移 doppler_shifts = [0, 5, -3, 8] # Hz # 生成信道响应 channel_response = np.zeros_like(test_signal, dtype=complex) for i in range(num_paths): # 延迟 delay_samples = int(delays[i] * fs / 1000) delayed_signal = np.roll(test_signal, delay_samples) # 多普勒频移 doppler_signal = delayed_signal * np.exp(1j * 2 * np.pi * doppler_shifts[i] * t) # 衰减 attenuated_signal = doppler_signal * attenuations[i] # 添加瑞利衰落 rayleigh_factor = np.random.rayleigh(1, len(t)) faded_signal = attenuated_signal * rayleigh_factor channel_response += faded_signal # 添加噪声 noise = np.random.normal(0, 0.1, len(channel_response)) received_signal = channel_response + noise # 绘制结果 plt.figure(figsize=(15, 10)) # 原始信号 plt.subplot(3, 1, 1) plt.plot(t, test_signal, 'b-', linewidth=2) plt.title('原始发送信号') plt.xlabel('时间 (s)') plt.ylabel('幅度') plt.grid(True) # 信道响应 plt.subplot(3, 1, 2) plt.plot(t, np.abs(channel_response), 'r-', linewidth=2) plt.title('信道冲激响应(包络)') plt.xlabel('时间 (s)') plt.ylabel('幅度') plt.grid(True) # 接收信号 plt.subplot(3, 1, 3) plt.plot(t, np.real(received_signal), 'g-', linewidth=2) plt.title('接收信号(实部)') plt.xlabel('时间 (s)') plt.ylabel('幅度') plt.grid(True) plt.tight_layout() plt.show() # 直接显示图像而不是保存 def calculate_channel_characteristics(self): """计算信道特性参数""" print("正在计算信道特性参数...") # 多普勒功率谱密度 fs = 1000 t = np.arange(0, 1, 1/fs) f_doppler = 50 # 最大多普勒频移 # 经典Jakes谱 f = np.linspace(-f_doppler, f_doppler, 1000) S = np.zeros_like(f) for i in range(len(f)): if np.abs(f[i]) <= f_doppler: S[i] = 1 / (np.pi * f_doppler * np.sqrt(1 - (f[i]/f_doppler)**2)) else: S[i] = 0 plt.figure(figsize=(10, 6)) plt.plot(f, S, 'b-', linewidth=2) plt.title('多普勒功率谱密度(Jakes谱)') plt.xlabel('多普勒频移 (Hz)') plt.ylabel('功率谱密度') plt.grid(True) plt.xlim([-f_doppler-10, f_doppler+10]) plt.tight_layout() plt.show() def run_full_simulation(self): """运行完整仿真""" print("开始ITS信道模型完整仿真...") print("=" * 50) # 执行各个仿真模块 self.simulate_nakagami_vs_standard() self.simulate_gaussian_functions() self.simulate_channel_response() self.calculate_channel_characteristics() print("=" * 50) print("仿真完成!所有图表已直接显示") print("\n显示的图表:") print("1. Nakagami函数拟合比较") print("2. 高斯函数形状") print("3. 信道响应仿真") print("4. 多普勒功率谱密度") # 创建仿真器实例并运行完整仿真 simulator = ITSChannelSimulator() simulator.run_full_simulation()
09-17
clc; clear; close all; %% 参数设置(帧结构 + convertSNR参数 + 平坦衰落信道参数) M = 2; % BPSK调制(注:M=4实际是QPSK,BPSK应设M=2,此处保留你的原始设置,若要纯BPSK改M=2) frame_len = 32; % 每帧比特数 num_frames = 20000; % 总帧数(200000帧) total_bits = frame_len * num_frames; % 总比特数(32*200000=6400000) sps = 8; % 每个符号的采样点数(SamplesPerSymbol) k = log2(M); % 每符号比特数(BPSK=1,QPSK=2) span = 6; % 滤波器符号长度 beta = 0.5; % 滚降因子 EbN0_dB_range = 0:0.5:8; % Eb/N0范围(信息比特级) codingRate = 4/7; % (7,4)汉明码编码率 % 平坦衰落信道核心参数 fd = 30; % 最大多普勒频移30Hz symbol_rate = 1e3; % 符号率(可根据需求调整,此处设1kHz,保证平坦衰落) sample_rate = sps * symbol_rate; % 信号采样率(8×1kHz=8kHz) %% 生成根升余弦滤波器(仅创建1次,提升效率) rrc_filter = rcosdesign(beta, span, sps, "sqrt"); %% 创建瑞利平坦衰落信道对象(单径、30Hz多普勒、匹配采样率) % 单径时延[0] → 时延扩展为0,满足频率平坦衰落条件 rayleigh_flat = comm.RayleighChannel(... 'SampleRate', sample_rate, ... % 匹配信号采样率 'PathDelays', 0, ... % 单径,时延0 → 平坦衰落 'AveragePathGains', 0, ... % 路径增益(0dB) 'MaximumDopplerShift', fd, ... % 最大多普勒频移30Hz 'NormalizePathGains', true, ... % 归一化路径增益 'RandomStream', 'mt19937ar with seed', ... % 固定随机种子,可复现 'Seed', 22); % 随机种子 %% 硬判决误比特率仿真(按帧循环 + convertSNR+awgn噪声 + 平坦衰落) ber_results = zeros(size(EbN0_dB_range)); for i = 1:length(EbN0_dB_range) EbN0_dB = EbN0_dB_range(i); total_err_bits = 0; % 初始化总误比特数 % ---------------------- 关键:用convertSNR转换Eb/N0到SNR(仅计算1次/ Eb/N0) ---------------------- snr = convertSNR(EbN0_dB, "ebno", ... "BitsPerSymbol", k, ... % 每符号比特数(BPSK=1,QPSK=2) "SamplesPerSymbol", sps, ... % 每符号采样数(8) "CodingRate", codingRate); % 编码率(4/7) % 按帧循环处理(200000帧) for frame_idx = 1:num_frames % ---------------------- 发送端(单帧处理) ---------------------- data_frame = randi([0,1], frame_len, 1); % 生成单帧32bit信息比特 encdata_frame = encode(data_frame, 7, 4, 'hamming/binary'); % 汉明编码 moddata_frame = pskmod(encdata_frame, M, InputType='bit'); % BPSK/QPSK调制 upsampled_frame = upsample(moddata_frame, sps); % 上采样 txsig_frame = upfirdn(upsampled_frame, rrc_filter, 1, 1); % 脉冲成形 % ---------------------- 新增:通过频率平坦衰落信道 ---------------------- txsig_faded = rayleigh_flat(txsig_frame); % 平坦衰落输出 % ---------------------- 噪声添加:awgn函数(基于convertSNR的SNR) ---------------------- % 'measured':先测量衰落后信号功率,再按SNR添加噪声,保证精度 [rxsig_frame, ~] = awgn(txsig_faded, snr, 'measured'); % ---------------------- 接收端(单帧处理) ---------------------- matched_frame = upfirdn(rxsig_frame, rrc_filter, 1, 1); % 匹配滤波 % 截取有效信号(和你原始代码逻辑一致) decimated_signal = matched_frame(span*sps+1:end-span*sps); % 下采样还原符号 received_symbols = decimated_signal(1:sps:end); % 解调+解码 demoddata_frame = pskdemod(received_symbols, M, OutputType='bit'); decdata_frame = decode(demoddata_frame, 7, 4, 'hamming/binary'); % 统计单帧误比特数 total_err_bits = total_err_bits + sum(data_frame ~= decdata_frame); % 进度打印(每10000帧更新) if mod(frame_idx, 10000) == 0 fprintf('Eb/N0=%.1f dB (SNR=%.2f dB),已处理%d/%d帧\n', EbN0_dB, snr, frame_idx, num_frames); end end % 计算当前Eb/N0下的总BER ber_results(i) = total_err_bits / total_bits; fprintf('=====================\n'); fprintf('Eb/N0 = %.1f dB, BER = %.6f\n', EbN0_dB, ber_results(i)); fprintf('=====================\n'); end %% 释放信道对象 release(rayleigh_flat); %% 保存结果(和你原始代码格式一致) results_table = table(EbN0_dB_range', ber_results', ... 'VariableNames', {'EbN0_dB', 'BER'}); writetable(results_table, 'hard_BPSK_flat_fading_30Hz.csv'); %% 绘制误比特率曲线并保存 figure('Position', [200, 200, 800, 600]); semilogy(EbN0_dB_range, ber_results, 'bo-', 'LineWidth', 2, 'MarkerSize', 6, ... 'DisplayName', 'hard decision (flat fading, fd=30Hz)'); grid on; legend('Location', 'southwest'); xlabel('Eb/N0 (dB)'); ylabel('BER'); xlim([EbN0_dB_range(1) EbN0_dB_range(end)]); ylim([1e-6 1]); % 保存曲线 print('hard BPSK flat fading 30Hz ', '-dpng', '-r300');给我这个代码加上LMS均衡,在发端单独加入8bit作为训练序列
12-08
要求通过使用MATLAB进行代码编写实现QPSK数字通信系统的数学建模和搭建,输出系统各部分模块波形,完成误码率求解及星座图仿真。并对这些输出波形和仿真结果进行分析,完成QPSK通信系统在不同信噪比SNR下的误码率分析。要求如下: (1)完成QPSK理论的推导及分析,使用MATLAB实现QPSK系统的数学建模和搭建,分析系统各部分模块的输出波形; (2)完成QPSK通信系统在不同信噪比SNR下的误码率分析; (3)完成QPSK星座图的仿真实现与分析;clear all;clc; %参数设定 N=20;%比特数 T=1;%比特周期 fc=2;%载波频率,载波频率是比特频率的两倍 Fs=100;%抽样频率 bitstream=randi([0,1],1,N);%产生随机的比特流。返回区间[0,1]的离散分布整数,组成1×N的数组 bitstream=2*bitstream-1;%单极性码变双极性码(0,1变为-1,1) I=[];Q=[]; %奇数进I路,偶数进Q路。串并变换 for i=1:N if mod(i,2)~=0 I=[I,bitstream(i)]; else Q=[Q,bitstream(i)]; end end %绘图比较I、Q比特流 bit_data=[]; for i=1:N bit_data=[bit_data,bitstream(i)*ones(1,T*Fs)];%一个比特周期里面有T*Fs个采样点 end I_data=[];Q_data=[]; %I路和Q路是原来比特周期的两倍,因此采样点数为2*比特流采样点数 for i=1:N/2 I_data=[I_data,I(i)*ones(1,T*Fs*2)]; Q_data=[Q_data,Q(i)*ones(1,T*Fs*2)]; end %绘图 figure(); %时间轴 t=0:1/Fs:T*N-1/Fs; subplot(3,1,1) plot(t,bit_data);legend('Bitstream')%比特信息 subplot(3,1,2) plot(t,I_data);legend('I Bitstream') subplot(3,1,3) plot(t,Q_data);legend('Q Bitstream') %载波信号 bit_t=0:1/Fs:2*T-1/Fs;%定义时间轴,I、Q两路码元长度为2T,为了好显示 %定义I路和Q路载波 I_carrier=[];Q_carrier=[]; for i=1:N/2 I_carrier=[I_carrier,I(i)*cos(2*pi*fc*bit_t)]; Q_carrier=[Q_carrier,Q(i)*cos(2*pi*fc*bit_t+pi/2)]; end %传输信号 QPSK_signal=I_carrier+Q_carrier; %绘图 figure();%产生一个新图 subplot(3,1,1) plot(t,I_carrier);legend('I signal')%I路信号 subplot(3,1,2) plot(t,Q_carrier);legend('Q signal')%Q路信号 subplot(3,1,3) plot(t,QPSK_signal);legend('QPSK signal')%I路、Q路的和信号 snr=1;%信噪比 %接收信号 QPSK_receive=awgn(QPSK_signal,snr);%awgn()添加噪声 %解调 for i=1:N/2 I_output=QPSK_receive((i-1)*length(bit_t)+1:i*length(bit_t)).*cos(2*pi*fc*bit_t); %当i=1时,QPSK_receive(1,200),每bit_t这个时间长度解调一次。matlab中数组下标从1开始,区别与C语言 if sum(I_output)>0 I_recover(i)=1; else I_recover(i)=-1; end Q_output=QPSK_receive(1,(i-1)*length(bit_t)+1:i*length(bit_t)).*cos(2*pi*fc*bit_t+pi/2) if sum(Q_output)>0 Q_recover(i)=1; else Q_recover(i)=-1; end end %并串变换 bit_recover=[]; for i=1:N if mod(i,2)~=0 bit_recover=[bit_recover,I_recover((i-1)/2+1)];%奇数取I路信息 else bit_recover=[bit_recover,Q_recover(i/2)];%偶数取Q路信息 end end %绘图比较I、Q比特流 recover_data=[]; for i=1:N recover_data=[recover_data,bit_recover(i)*ones(1,T*Fs)]; end I_recover_data=[];Q_recover_data=[]; for i=1:N/2 I_recover_data=[I_recover_data,I_recover(i)*ones(1,2*T*Fs)]; Q_recover_data=[Q_recover_data,Q_recover(i)*ones(1,2*T*Fs)]; end %绘图 figure(); t=0:1/Fs:N*T-1/Fs; subplot(3,1,1) plot(t,recover_data);legend('Bitstream'); subplot(3,1,2) plot(t,I_recover_data);legend('I Bitstream'); subplot(3,1,3) plot(t,Q_recover_data);legend('Q Bitstream');根据以上要求和代码给我完整代码
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值